@@ -12,6 +12,8 @@ var own = {}.hasOwnProperty
12
12
/* Schema. */
13
13
var NODES = {
14
14
root : { children : all } ,
15
+ doctype : handleDoctype ,
16
+ comment : handleComment ,
15
17
element : {
16
18
tagName : handleTagName ,
17
19
properties : handleProperties ,
@@ -57,25 +59,36 @@ function one(schema, node, stack) {
57
59
var type = node && node . type
58
60
var replacement = { type : node . type }
59
61
var replace = true
62
+ var definition
60
63
var allowed
61
64
var result
62
65
var key
63
66
64
67
if ( ! own . call ( NODES , type ) ) {
65
68
replace = false
66
69
} else {
67
- allowed = xtend ( NODES [ type ] , NODES [ '*' ] )
70
+ definition = NODES [ type ]
68
71
69
- for ( key in allowed ) {
70
- result = allowed [ key ] ( schema , node [ key ] , node , stack )
72
+ if ( typeof definition === 'function' ) {
73
+ definition = definition ( schema , node )
74
+ }
75
+
76
+ if ( ! definition ) {
77
+ replace = false
78
+ } else {
79
+ allowed = xtend ( definition , NODES [ '*' ] )
71
80
72
- if ( result === false ) {
73
- replace = false
81
+ for ( key in allowed ) {
82
+ result = allowed [ key ] ( schema , node [ key ] , node , stack )
74
83
75
- /* Set the non-safe value. */
76
- replacement [ key ] = node [ key ]
77
- } else if ( result !== null && result !== undefined ) {
78
- replacement [ key ] = result
84
+ if ( result === false ) {
85
+ replace = false
86
+
87
+ /* Set the non-safe value. */
88
+ replacement [ key ] = node [ key ]
89
+ } else if ( result !== null && result !== undefined ) {
90
+ replacement [ key ] = result
91
+ }
79
92
}
80
93
}
81
94
}
@@ -253,6 +266,11 @@ function handleProtocol(schema, value, prop) {
253
266
return false
254
267
}
255
268
269
+ /* Always return a valid HTML5 doctype. */
270
+ function handleDoctypeName ( ) {
271
+ return 'html'
272
+ }
273
+
256
274
/* Sanitize `tagName`. */
257
275
function handleTagName ( schema , tagName , node , stack ) {
258
276
var name = typeof tagName === 'string' ? tagName : null
@@ -286,6 +304,14 @@ function handleTagName(schema, tagName, node, stack) {
286
304
return name
287
305
}
288
306
307
+ function handleDoctype ( schema ) {
308
+ return schema . allowDoctypes ? { name : handleDoctypeName } : null
309
+ }
310
+
311
+ function handleComment ( schema ) {
312
+ return schema . allowComments ? { value : handleValue } : null
313
+ }
314
+
289
315
/* Sanitize `value`. */
290
316
function handleValue ( schema , value ) {
291
317
return typeof value === 'string' ? value : ''
0 commit comments