@@ -11,12 +11,12 @@ var is = require('hast-util-is-element')
11
11
12
12
module . exports = toNLCST
13
13
14
- /* Elements representing source. */
14
+ // Elements representing source.
15
15
var SOURCE = [ 'code' ]
16
16
var IGNORE = [ 'script' , 'style' , 'svg' , 'math' , 'del' ]
17
17
var EXPLICIT = [ 'p' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ]
18
18
19
- /* Constants. */
19
+ // Constants.
20
20
var FLOW_ACCEPTING = [
21
21
'body' ,
22
22
'article' ,
@@ -43,14 +43,14 @@ var FLOW_ACCEPTING = [
43
43
'dialog'
44
44
]
45
45
46
- /* Transform `tree` to `nlcst`. */
46
+ // Transform `tree` to `nlcst`.
47
47
function toNLCST ( tree , file , Parser ) {
48
48
var parser
49
49
var location
50
50
var results
51
51
var doc
52
52
53
- /* Warn for invalid parameters. */
53
+ // Warn for invalid parameters.
54
54
if ( ! tree || ! tree . type ) {
55
55
throw new Error ( 'hast-util-to-nlcst expected node' )
56
56
}
@@ -59,7 +59,7 @@ function toNLCST(tree, file, Parser) {
59
59
throw new Error ( 'hast-util-to-nlcst expected file' )
60
60
}
61
61
62
- /* Construct parser. */
62
+ // Construct parser.
63
63
if ( ! Parser ) {
64
64
throw new Error ( 'hast-util-to-nlcst expected parser' )
65
65
}
@@ -72,9 +72,8 @@ function toNLCST(tree, file, Parser) {
72
72
doc = String ( file )
73
73
parser = 'parse' in Parser ? Parser : new Parser ( )
74
74
75
- /* Transform HAST into NLCST tokens, and pass these
76
- * into `parser.parse` to insert sentences, paragraphs
77
- * where needed. */
75
+ // Transform HAST into NLCST tokens, and pass these into `parser.parse` to
76
+ // insert sentences, paragraphs where needed.
78
77
results = [ ]
79
78
80
79
find ( tree )
@@ -94,15 +93,15 @@ function toNLCST(tree, file, Parser) {
94
93
if ( node . type === 'root' ) {
95
94
findAll ( children )
96
95
} else if ( is ( node ) && ! ignored ( node ) ) {
97
- /* Explicit paragraph. */
98
96
if ( is ( node , EXPLICIT ) ) {
97
+ // Explicit paragraph.
99
98
add ( node )
100
- /* Slightly simplified version of:
101
- * https://html.spec.whatwg.org/#paragraphs */
102
99
} else if ( is ( node , FLOW_ACCEPTING ) ) {
100
+ // Slightly simplified version of:
101
+ // https://html.spec.whatwg.org/#paragraphs
103
102
implicit ( flattenAll ( children ) )
104
- /* Dig deeper. */
105
103
} else {
104
+ // Dig deeper.
106
105
findAll ( children )
107
106
}
108
107
}
@@ -179,7 +178,7 @@ function toNLCST(tree, file, Parser) {
179
178
}
180
179
}
181
180
182
- /* Convert `node` (HAST ) to NLCST. */
181
+ // Convert `node` (hast ) to nlcst.
183
182
function one ( node ) {
184
183
var type = node . type
185
184
var tagName = type === 'element' ? node . tagName : null
@@ -211,7 +210,7 @@ function toNLCST(tree, file, Parser) {
211
210
return patch ( replacement , location , location . toOffset ( position . start ( node ) ) )
212
211
}
213
212
214
- /* Convert all `children` (HAST) to NLCST. */
213
+ // Convert all `children` (HAST) to NLCST.
215
214
function all ( children ) {
216
215
var length = children && children . length
217
216
var index = - 1
@@ -229,13 +228,11 @@ function toNLCST(tree, file, Parser) {
229
228
return result
230
229
}
231
230
232
- /* Patch a position on each node in `nodes`.
233
- * `offset` is the offset in `file` this run of content
234
- * starts at.
235
- *
236
- * Note that NLCST nodes are concrete, meaning that their
237
- * starting and ending positions can be inferred from their
238
- * content. */
231
+ // Patch a position on each node in `nodes`. `offset` is the offset in
232
+ // `file` this run of content starts at.
233
+ //
234
+ // Note that NLCST nodes are concrete, meaning that their starting and ending
235
+ // positions can be inferred from their content.
239
236
function patch ( nodes , location , offset ) {
240
237
var length = nodes . length
241
238
var index = - 1
0 commit comments