1- if ( typeof define !== 'function' ) { var define = require ( 'amdefine' ) ( module ) }
1+ if ( typeof define !== 'function' ) { var define = require ( 'amdefine' ) ( module ) ; }
22
33define ( [ './core' , './markdown_helpers' ] , function ( Markdown , MarkdownHelpers ) {
44
@@ -88,11 +88,15 @@ define(['./core', './markdown_helpers'], function(Markdown, MarkdownHelpers) {
8888
8989
9090 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+ }
96100 }
97101
98102 function render_tree ( jsonml ) {
@@ -116,8 +120,12 @@ define(['./core', './markdown_helpers'], function(Markdown, MarkdownHelpers) {
116120 delete attributes . src ;
117121 }
118122
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+ }
121129
122130 // be careful about adding whitespace here for inline elements
123131 if ( tag === "img" || tag === "br" || tag === "hr" )
0 commit comments