11'use strict'
22
3- /* Dependencies. */
43var xtend = require ( 'xtend' )
54var defaults = require ( './github.json' )
65
7- /* Expose. */
86module . exports = wrapper
97
108var own = { } . hasOwnProperty
119
12- /* Schema. */
1310var NODES = {
1411 root : { children : all } ,
1512 doctype : handleDoctype ,
@@ -26,7 +23,7 @@ var NODES = {
2623 }
2724}
2825
29- /* Sanitize `node`, according to `schema`. */
26+ // Sanitize `node`, according to `schema`.
3027function wrapper ( node , schema ) {
3128 var ctx = { type : 'root' , children : [ ] }
3229 var replace
@@ -54,7 +51,7 @@ function wrapper(node, schema) {
5451 return replace
5552}
5653
57- /* Sanitize `node`. */
54+ // Sanitize `node`.
5855function one ( schema , node , stack ) {
5956 var type = node && node . type
6057 var replacement = { type : node . type }
@@ -84,7 +81,7 @@ function one(schema, node, stack) {
8481 if ( result === false ) {
8582 replace = false
8683
87- /* Set the non-safe value. */
84+ // Set the non-safe value.
8885 replacement [ key ] = node [ key ]
8986 } else if ( result !== null && result !== undefined ) {
9087 replacement [ key ] = result
@@ -108,7 +105,7 @@ function one(schema, node, stack) {
108105 return replacement
109106}
110107
111- /* Sanitize `children`. */
108+ // Sanitize `children`.
112109function all ( schema , children , node , stack ) {
113110 var nodes = children || [ ]
114111 var length = nodes . length || 0
@@ -133,7 +130,7 @@ function all(schema, children, node, stack) {
133130 return results
134131}
135132
136- /* Sanitize `properties`. */
133+ // Sanitize `properties`.
137134function handleProperties ( schema , properties , node , stack ) {
138135 var name = handleTagName ( schema , node . tagName , node , stack )
139136 var attrs = schema . attributes
@@ -170,7 +167,7 @@ function handleProperties(schema, properties, node, stack) {
170167 return result
171168}
172169
173- /* Sanitize a property value which is a list. */
170+ // Sanitize a property value which is a list.
174171function handlePropertyValues ( schema , values , prop ) {
175172 var length = values . length
176173 var result = [ ]
@@ -188,7 +185,7 @@ function handlePropertyValues(schema, values, prop) {
188185 return result
189186}
190187
191- /* Sanitize a property value. */
188+ // Sanitize a property value.
192189function handlePropertyValue ( schema , value , prop ) {
193190 if (
194191 typeof value !== 'boolean' &&
@@ -209,7 +206,7 @@ function handlePropertyValue(schema, value, prop) {
209206 return value
210207}
211208
212- /* Check whether `value` is a safe URL. */
209+ // Check whether `value` is a safe URL.
213210function handleProtocol ( schema , value , prop ) {
214211 var protocols = schema . protocols
215212 var protocol
@@ -266,12 +263,12 @@ function handleProtocol(schema, value, prop) {
266263 return false
267264}
268265
269- /* Always return a valid HTML5 doctype. */
266+ // Always return a valid HTML5 doctype.
270267function handleDoctypeName ( ) {
271268 return 'html'
272269}
273270
274- /* Sanitize `tagName`. */
271+ // Sanitize `tagName`.
275272function handleTagName ( schema , tagName , node , stack ) {
276273 var name = typeof tagName === 'string' ? tagName : null
277274 var ancestors = schema . ancestors
@@ -284,8 +281,8 @@ function handleTagName(schema, tagName, node, stack) {
284281
285282 ancestors = own . call ( ancestors , name ) ? ancestors [ name ] : [ ]
286283
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.
289286 if ( ancestors . length !== 0 ) {
290287 length = ancestors . length + 1
291288 index = - 1
@@ -312,17 +309,17 @@ function handleComment(schema) {
312309 return schema . allowComments ? { value : handleValue } : null
313310}
314311
315- /* Sanitize `value`. */
312+ // Sanitize `value`.
316313function handleValue ( schema , value ) {
317314 return typeof value === 'string' ? value : ''
318315}
319316
320- /* Allow `value`. */
317+ // Allow `value`.
321318function allow ( schema , value ) {
322319 return value
323320}
324321
325- /* Check if `prop` is a data property. */
322+ // Check if `prop` is a data property.
326323function data ( prop ) {
327324 return prop . length > 4 && prop . slice ( 0 , 4 ) . toLowerCase ( ) === 'data'
328325}
0 commit comments