1
- if ( typeof define !== 'function' ) { var define = require ( 'amdefine' ) ( module ) }
1
+ if ( typeof define !== 'function' ) { var define = require ( 'amdefine' ) ( module ) ; }
2
2
3
3
define ( [ './core' , './markdown_helpers' ] , function ( Markdown , MarkdownHelpers ) {
4
4
@@ -88,11 +88,15 @@ define(['./core', './markdown_helpers'], function(Markdown, MarkdownHelpers) {
88
88
89
89
90
90
function escapeHTML ( text ) {
91
- return text . replace ( / & / g, "&" )
92
- . replace ( / < / g, "<" )
93
- . replace ( / > / g, ">" )
94
- . replace ( / " / g, """ )
95
- . replace ( / ' / g, "'" ) ;
91
+ if ( text && text . length > 0 ) {
92
+ return text . replace ( / & / g, "&" )
93
+ . replace ( / < / g, "<" )
94
+ . replace ( / > / g, ">" )
95
+ . replace ( / " / g, """ )
96
+ . replace ( / ' / g, "'" ) ;
97
+ } else {
98
+ return "" ;
99
+ }
96
100
}
97
101
98
102
function render_tree ( jsonml ) {
@@ -116,8 +120,12 @@ define(['./core', './markdown_helpers'], function(Markdown, MarkdownHelpers) {
116
120
delete attributes . src ;
117
121
}
118
122
119
- for ( var a in attributes )
120
- tag_attrs += " " + a + '="' + escapeHTML ( attributes [ a ] ) + '"' ;
123
+ for ( var a in attributes ) {
124
+ var escaped = escapeHTML ( attributes [ a ] ) ;
125
+ if ( escaped && escaped . length ) {
126
+ tag_attrs += " " + a + '="' + escaped + '"' ;
127
+ }
128
+ }
121
129
122
130
// be careful about adding whitespace here for inline elements
123
131
if ( tag === "img" || tag === "br" || tag === "hr" )
0 commit comments