1
- /**
2
- * @author Titus Wormer
3
- * @copyright 2015 Titus Wormer
4
- * @license MIT
5
- * @module hdast:sanitize
6
- * @fileoverview Sanitize HAST.
7
- */
8
-
9
1
'use strict' ;
10
2
11
3
/* Dependencies. */
@@ -31,14 +23,7 @@ var NODES = {
31
23
}
32
24
} ;
33
25
34
- /**
35
- * Sanitize `node`, according to `schema`.
36
- *
37
- * @param {Node } node - HAST node to sanitize.
38
- * @param {Object } [schema] - Schema to use.
39
- * Defaults to `github`.
40
- * @return {Node } - Sanitized HAST node.
41
- */
26
+ /* Sanitize `node`, according to `schema`. */
42
27
function wrapper ( node , schema ) {
43
28
var ctx = { type : 'root' , children : [ ] } ;
44
29
var replace ;
@@ -66,14 +51,7 @@ function wrapper(node, schema) {
66
51
return replace ;
67
52
}
68
53
69
- /**
70
- * Sanitize `node`.
71
- *
72
- * @param {Object } schema - Configuration.
73
- * @param {Node } node - HAST node to sanitize.
74
- * @param {Array.<string> } stack - Element stack.
75
- * @return {Node?|Array.<Node> } - Clean node(s).
76
- */
54
+ /* Sanitize `node`. */
77
55
function one ( schema , node , stack ) {
78
56
var type = node && node . type ;
79
57
var replacement = { type : node . type } ;
@@ -116,15 +94,7 @@ function one(schema, node, stack) {
116
94
return replacement ;
117
95
}
118
96
119
- /**
120
- * Sanitize `children`.
121
- *
122
- * @param {Object } schema - Configuration.
123
- * @param {Array.<Node> } children - HAST nodes.
124
- * @param {Node } node - Parent.
125
- * @param {Array.<string> } stack - Element stack.
126
- * @return {Array.<Node> } - Clean nodes.
127
- */
97
+ /* Sanitize `children`. */
128
98
function all ( schema , children , node , stack ) {
129
99
var nodes = children || [ ] ;
130
100
var length = nodes . length || 0 ;
@@ -149,15 +119,7 @@ function all(schema, children, node, stack) {
149
119
return results ;
150
120
}
151
121
152
- /**
153
- * Sanitize `properties`.
154
- *
155
- * @param {Object } schema - Configuration.
156
- * @param {Object } properties - Element `properties`.
157
- * @param {Node } node - Context.
158
- * @param {Array.<string> } stack - Element stack.
159
- * @return {Object } - Clean properties.
160
- */
122
+ /* Sanitize `properties`. */
161
123
function handleProperties ( schema , properties , node , stack ) {
162
124
var name = handleTagName ( schema , node . tagName , node , stack ) ;
163
125
var attrs = schema . attributes ;
@@ -194,14 +156,7 @@ function handleProperties(schema, properties, node, stack) {
194
156
return result ;
195
157
}
196
158
197
- /**
198
- * Sanitize a property value which is a list.
199
- *
200
- * @param {Object } schema - Configuration.
201
- * @param {Array.<*> } values - List of values.
202
- * @param {string } prop - Key at which `values` live.
203
- * @return {Array.<number|boolean|string> } - Clean values.
204
- */
159
+ /* Sanitize a property value which is a list. */
205
160
function handlePropertyValues ( schema , values , prop ) {
206
161
var length = values . length ;
207
162
var result = [ ] ;
@@ -219,14 +174,7 @@ function handlePropertyValues(schema, values, prop) {
219
174
return result ;
220
175
}
221
176
222
- /**
223
- * Sanitize a property value.
224
- *
225
- * @param {Object } schema - Configuration.
226
- * @param {* } value - Value.
227
- * @param {string } prop - Key at which `value` live.
228
- * @return {number|boolean|string? } - Clean value.
229
- */
177
+ /* Sanitize a property value. */
230
178
function handlePropertyValue ( schema , value , prop ) {
231
179
if (
232
180
typeof value !== 'boolean' &&
@@ -247,14 +195,7 @@ function handlePropertyValue(schema, value, prop) {
247
195
return value ;
248
196
}
249
197
250
- /**
251
- * Check whether `value` is a safe URL.
252
- *
253
- * @param {Object } schema - Configuration.
254
- * @param {* } value - Value.
255
- * @param {string } prop - Key at which `value` live.
256
- * @return {boolean } - Whether `value` is safe.
257
- */
198
+ /* Check whether `value` is a safe URL. */
258
199
function handleProtocol ( schema , value , prop ) {
259
200
var protocols = schema . protocols ;
260
201
var protocol ;
@@ -311,17 +252,7 @@ function handleProtocol(schema, value, prop) {
311
252
return false ;
312
253
}
313
254
314
- /**
315
- * Sanitize `tagName`.
316
- *
317
- * @param {Object } schema - Configuration.
318
- * @param {* } tagName - Tag-name of element.
319
- * @param {Node } node - HAST node to sanitize.
320
- * @param {Array.<string> } stack - Element stack.
321
- * @return {string|boolean? } - `false`, if `tagName`
322
- * represents an unsage element, a string to use
323
- * as a tag-name otherwise.
324
- */
255
+ /* Sanitize `tagName`. */
325
256
function handleTagName ( schema , tagName , node , stack ) {
326
257
var name = typeof tagName === 'string' ? tagName : null ;
327
258
var ancestors = schema . ancestors ;
0 commit comments