3
3
module . exports = fromMarkdown
4
4
5
5
// These three are compiled away in the `dist/`
6
- var codes = require ( 'micromark/lib /character/codes' )
7
- var constants = require ( 'micromark/lib /constant/constants' )
8
- var types = require ( 'micromark/lib /constant/types' )
6
+ var codes = require ( 'micromark/dist /character/codes' )
7
+ var constants = require ( 'micromark/dist /constant/constants' )
8
+ var types = require ( 'micromark/dist /constant/types' )
9
9
10
10
var toString = require ( 'mdast-util-to-string' )
11
11
var assign = require ( 'micromark/dist/constant/assign' )
@@ -147,12 +147,10 @@ function compiler(options) {
147
147
function compile ( events ) {
148
148
var stack = [ { type : 'root' , children : [ ] } ]
149
149
var tokenStack = [ ]
150
- var index = - 1
151
150
var listStack = [ ]
152
- var length
151
+ var index = - 1
153
152
var handler
154
153
var listStart
155
- var event
156
154
157
155
var context = {
158
156
stack : stack ,
@@ -167,15 +165,13 @@ function compiler(options) {
167
165
}
168
166
169
167
while ( ++ index < events . length ) {
170
- event = events [ index ]
171
-
172
168
// We preprocess lists to add `listItem` tokens, and to infer whether
173
169
// items the list itself are spread out.
174
170
if (
175
- event [ 1 ] . type === types . listOrdered ||
176
- event [ 1 ] . type === types . listUnordered
171
+ events [ index ] [ 1 ] . type === types . listOrdered ||
172
+ events [ index ] [ 1 ] . type === types . listUnordered
177
173
) {
178
- if ( event [ 0 ] === 'enter' ) {
174
+ if ( events [ index ] [ 0 ] === 'enter' ) {
179
175
listStack . push ( index )
180
176
} else {
181
177
listStart = listStack . pop ( index )
@@ -185,9 +181,8 @@ function compiler(options) {
185
181
}
186
182
187
183
index = - 1
188
- length = events . length
189
184
190
- while ( ++ index < length ) {
185
+ while ( ++ index < events . length ) {
191
186
handler = config [ events [ index ] [ 0 ] ]
192
187
193
188
if ( own . call ( handler , events [ index ] [ 1 ] . type ) ) {
@@ -198,7 +193,7 @@ function compiler(options) {
198
193
}
199
194
}
200
195
201
- if ( tokenStack . length > 0 ) {
196
+ if ( tokenStack . length ) {
202
197
throw new Error (
203
198
'Cannot close document, a token (`' +
204
199
tokenStack [ tokenStack . length - 1 ] . type +
@@ -214,10 +209,10 @@ function compiler(options) {
214
209
// Figure out `root` position.
215
210
stack [ 0 ] . position = {
216
211
start : point (
217
- length ? events [ 0 ] [ 1 ] . start : { line : 1 , column : 1 , offset : 0 }
212
+ events . length ? events [ 0 ] [ 1 ] . start : { line : 1 , column : 1 , offset : 0 }
218
213
) ,
219
214
end : point (
220
- length
215
+ events . length
221
216
? events [ events . length - 2 ] [ 1 ] . end
222
217
: { line : 1 , column : 1 , offset : 0 }
223
218
)
@@ -430,8 +425,7 @@ function compiler(options) {
430
425
}
431
426
432
427
function resume ( ) {
433
- var value = toString ( this . stack . pop ( ) )
434
- return value
428
+ return toString ( this . stack . pop ( ) )
435
429
}
436
430
437
431
//
@@ -555,11 +549,10 @@ function compiler(options) {
555
549
return
556
550
}
557
551
558
- if ( getData ( 'setextHeadingSlurpLineEnding' ) ) {
559
- return
560
- }
561
-
562
- if ( config . canContainEols . indexOf ( context . type ) !== - 1 ) {
552
+ if (
553
+ ! getData ( 'setextHeadingSlurpLineEnding' ) &&
554
+ config . canContainEols . indexOf ( context . type ) > - 1
555
+ ) {
563
556
onenterdata . call ( this , token )
564
557
onexitdata . call ( this , token )
565
558
}
@@ -677,6 +670,7 @@ function compiler(options) {
677
670
var data = this . sliceSerialize ( token )
678
671
var type = getData ( 'characterReferenceType' )
679
672
var value
673
+ var tail
680
674
681
675
if ( type ) {
682
676
value = safeFromInt (
@@ -690,7 +684,7 @@ function compiler(options) {
690
684
value = decode ( data )
691
685
}
692
686
693
- var tail = this . stack . pop ( )
687
+ tail = this . stack . pop ( )
694
688
tail . value += value
695
689
tail . position . end = point ( token . end )
696
690
}
@@ -793,10 +787,9 @@ function compiler(options) {
793
787
}
794
788
795
789
function configure ( config , extensions ) {
796
- var length = extensions . length
797
790
var index = - 1
798
791
799
- while ( ++ index < length ) {
792
+ while ( ++ index < extensions . length ) {
800
793
extension ( config , extensions [ index ] )
801
794
}
802
795
@@ -806,16 +799,14 @@ function configure(config, extensions) {
806
799
function extension ( config , extension ) {
807
800
var key
808
801
var left
809
- var right
810
802
811
803
for ( key in extension ) {
812
804
left = own . call ( config , key ) ? config [ key ] : ( config [ key ] = { } )
813
- right = extension [ key ]
814
805
815
806
if ( key === 'canContainEols' ) {
816
- config [ key ] = [ ] . concat ( left , right )
807
+ config [ key ] = [ ] . concat ( left , extension [ key ] )
817
808
} else {
818
- Object . assign ( left , right )
809
+ Object . assign ( left , extension [ key ] )
819
810
}
820
811
}
821
812
}
0 commit comments