1
1
'use strict'
2
2
3
- /* Dependencies. */
4
3
var xtend = require ( 'xtend' )
5
4
var defaults = require ( './github.json' )
6
5
7
- /* Expose. */
8
6
module . exports = wrapper
9
7
10
8
var own = { } . hasOwnProperty
11
9
12
- /* Schema. */
13
10
var NODES = {
14
11
root : { children : all } ,
15
12
doctype : handleDoctype ,
@@ -26,7 +23,7 @@ var NODES = {
26
23
}
27
24
}
28
25
29
- /* Sanitize `node`, according to `schema`. */
26
+ // Sanitize `node`, according to `schema`.
30
27
function wrapper ( node , schema ) {
31
28
var ctx = { type : 'root' , children : [ ] }
32
29
var replace
@@ -54,7 +51,7 @@ function wrapper(node, schema) {
54
51
return replace
55
52
}
56
53
57
- /* Sanitize `node`. */
54
+ // Sanitize `node`.
58
55
function one ( schema , node , stack ) {
59
56
var type = node && node . type
60
57
var replacement = { type : node . type }
@@ -84,7 +81,7 @@ function one(schema, node, stack) {
84
81
if ( result === false ) {
85
82
replace = false
86
83
87
- /* Set the non-safe value. */
84
+ // Set the non-safe value.
88
85
replacement [ key ] = node [ key ]
89
86
} else if ( result !== null && result !== undefined ) {
90
87
replacement [ key ] = result
@@ -108,7 +105,7 @@ function one(schema, node, stack) {
108
105
return replacement
109
106
}
110
107
111
- /* Sanitize `children`. */
108
+ // Sanitize `children`.
112
109
function all ( schema , children , node , stack ) {
113
110
var nodes = children || [ ]
114
111
var length = nodes . length || 0
@@ -133,7 +130,7 @@ function all(schema, children, node, stack) {
133
130
return results
134
131
}
135
132
136
- /* Sanitize `properties`. */
133
+ // Sanitize `properties`.
137
134
function handleProperties ( schema , properties , node , stack ) {
138
135
var name = handleTagName ( schema , node . tagName , node , stack )
139
136
var attrs = schema . attributes
@@ -170,7 +167,7 @@ function handleProperties(schema, properties, node, stack) {
170
167
return result
171
168
}
172
169
173
- /* Sanitize a property value which is a list. */
170
+ // Sanitize a property value which is a list.
174
171
function handlePropertyValues ( schema , values , prop ) {
175
172
var length = values . length
176
173
var result = [ ]
@@ -188,7 +185,7 @@ function handlePropertyValues(schema, values, prop) {
188
185
return result
189
186
}
190
187
191
- /* Sanitize a property value. */
188
+ // Sanitize a property value.
192
189
function handlePropertyValue ( schema , value , prop ) {
193
190
if (
194
191
typeof value !== 'boolean' &&
@@ -209,7 +206,7 @@ function handlePropertyValue(schema, value, prop) {
209
206
return value
210
207
}
211
208
212
- /* Check whether `value` is a safe URL. */
209
+ // Check whether `value` is a safe URL.
213
210
function handleProtocol ( schema , value , prop ) {
214
211
var protocols = schema . protocols
215
212
var protocol
@@ -266,12 +263,12 @@ function handleProtocol(schema, value, prop) {
266
263
return false
267
264
}
268
265
269
- /* Always return a valid HTML5 doctype. */
266
+ // Always return a valid HTML5 doctype.
270
267
function handleDoctypeName ( ) {
271
268
return 'html'
272
269
}
273
270
274
- /* Sanitize `tagName`. */
271
+ // Sanitize `tagName`.
275
272
function handleTagName ( schema , tagName , node , stack ) {
276
273
var name = typeof tagName === 'string' ? tagName : null
277
274
var ancestors = schema . ancestors
@@ -284,8 +281,8 @@ function handleTagName(schema, tagName, node, stack) {
284
281
285
282
ancestors = own . call ( ancestors , name ) ? ancestors [ name ] : [ ]
286
283
287
- /* Some nodes can break out of their context if they
288
- * don’t have a certain ancestor. */
284
+ // Some nodes can break out of their context if they don’t have a certain
285
+ // ancestor.
289
286
if ( ancestors . length !== 0 ) {
290
287
length = ancestors . length + 1
291
288
index = - 1
@@ -312,17 +309,17 @@ function handleComment(schema) {
312
309
return schema . allowComments ? { value : handleValue } : null
313
310
}
314
311
315
- /* Sanitize `value`. */
312
+ // Sanitize `value`.
316
313
function handleValue ( schema , value ) {
317
314
return typeof value === 'string' ? value : ''
318
315
}
319
316
320
- /* Allow `value`. */
317
+ // Allow `value`.
321
318
function allow ( schema , value ) {
322
319
return value
323
320
}
324
321
325
- /* Check if `prop` is a data property. */
322
+ // Check if `prop` is a data property.
326
323
function data ( prop ) {
327
324
return prop . length > 4 && prop . slice ( 0 , 4 ) . toLowerCase ( ) === 'data'
328
325
}
0 commit comments