@@ -27,25 +27,39 @@ var START_TAG_REGEXP = /^<\s*([\w:-]+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:
27
27
URI_REGEXP = / ^ ( ( f t p | h t t p s ? ) : \/ \/ | m a i l t o : | # ) / ,
28
28
NON_ALPHANUMERIC_REGEXP = / ( [ ^ \# - ~ | | ! ] ) / g; // Match everything outside of normal chars and " (quote character)
29
29
30
- // Empty Elements - HTML 4.01
31
- var emptyElements = makeMap ( "area,br,col,hr,img" ) ;
32
-
33
- // Block Elements - HTML 4.01
34
- var blockElements = makeMap ( "address,blockquote,center,dd,del,dir,div,dl,dt," +
35
- "hr,ins,li,map,menu,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul" ) ;
36
-
37
- // Inline Elements - HTML 4.01
38
- var inlineElements = makeMap ( "a,abbr,acronym,b,bdo,big,br,cite,code,del,dfn,em,font,i,img," +
39
- "ins,kbd,label,map,q,s,samp,small,span,strike,strong,sub,sup,tt,u,var" ) ;
40
- // Elements that you can, intentionally, leave open
41
- // (and which close themselves)
42
- var closeSelfElements = makeMap ( "colgroup,dd,dt,li,p,td,tfoot,th,thead,tr" ) ;
30
+
31
+ // Good source of info about elements and attributes
32
+ // http://dev.w3.org/html5/spec/Overview.html#semantics
33
+ // http://simon.html5.org/html-elements
34
+
35
+ // Safe Void Elements - HTML5
36
+ // http://dev.w3.org/html5/spec/Overview.html#void-elements
37
+ var voidElements = makeMap ( "area,br,col,hr,img,wbr" ) ;
38
+
39
+ // Elements that you can, intentionally, leave open (and which close themselves)
40
+ // http://dev.w3.org/html5/spec/Overview.html#optional-tags
41
+ var optionalEndTagBlockElements = makeMap ( "colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr" ) ,
42
+ optionalEndTagInlineElements = makeMap ( "rp,rt" ) ,
43
+ optionalEndTagElements = extend ( { } , optionalEndTagInlineElements , optionalEndTagBlockElements ) ;
44
+
45
+ // Safe Block Elements - HTML5
46
+ var blockElements = extend ( { } , optionalEndTagBlockElements , makeMap ( "address,article,aside," +
47
+ "blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5,h6," +
48
+ "header,hgroup,hr,ins,map,menu,nav,ol,pre,script,section,table,ul" ) ) ;
49
+
50
+ // Inline Elements - HTML5
51
+ var inlineElements = extend ( { } , optionalEndTagInlineElements , makeMap ( "a,abbr,acronym,b,bdi,bdo," +
52
+ "big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s,samp,small," +
53
+ "span,strike,strong,sub,sup,time,tt,u,var" ) ) ;
54
+
55
+
43
56
// Special Elements (can contain anything)
44
57
var specialElements = makeMap ( "script,style" ) ;
45
- var validElements = extend ( { } , emptyElements , blockElements , inlineElements , closeSelfElements ) ;
58
+
59
+ var validElements = extend ( { } , voidElements , blockElements , inlineElements , optionalEndTagElements ) ;
46
60
47
61
//Attributes that have href and hence need to be sanitized
48
- var uriAttrs = makeMap ( "background,href,longdesc,src,usemap" ) ;
62
+ var uriAttrs = makeMap ( "background,cite, href,longdesc,src,usemap" ) ;
49
63
var validAttrs = extend ( { } , uriAttrs , makeMap (
50
64
'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
51
65
'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' +
@@ -146,11 +160,11 @@ function htmlParser( html, handler ) {
146
160
}
147
161
}
148
162
149
- if ( closeSelfElements [ tagName ] && stack . last ( ) == tagName ) {
163
+ if ( optionalEndTagElements [ tagName ] && stack . last ( ) == tagName ) {
150
164
parseEndTag ( "" , tagName ) ;
151
165
}
152
166
153
- unary = emptyElements [ tagName ] || ! ! unary ;
167
+ unary = voidElements [ tagName ] || ! ! unary ;
154
168
155
169
if ( ! unary )
156
170
stack . push ( tagName ) ;
0 commit comments