@@ -93,7 +93,7 @@ function render(opts, cb) {
93
93
filename = path . basename ( filename , '.md' ) ;
94
94
95
95
parseText ( lexed ) ;
96
- lexed = parseLists ( lexed ) ;
96
+ lexed = preprocessElements ( lexed ) ;
97
97
98
98
// Generate the table of contents.
99
99
// This mutates the lexed contents in-place.
@@ -231,25 +231,28 @@ function parseText(lexed) {
231
231
} ) ;
232
232
}
233
233
234
- // Just update the list item text in-place.
235
- // Lists that come right after a heading are what we're after.
236
- function parseLists ( input ) {
234
+ // Preprocess stability blockquotes and YAML blocks.
235
+ function preprocessElements ( input ) {
237
236
var state = null ;
238
- const savedState = [ ] ;
239
- var depth = 0 ;
240
237
const output = [ ] ;
241
238
let headingIndex = - 1 ;
242
239
let heading = null ;
243
240
244
241
output . links = input . links ;
245
242
input . forEach ( function ( tok , index ) {
243
+ if ( tok . type === 'heading' ) {
244
+ headingIndex = index ;
245
+ heading = tok ;
246
+ }
247
+ if ( tok . type === 'html' && common . isYAMLBlock ( tok . text ) ) {
248
+ tok . text = parseYAML ( tok . text ) ;
249
+ }
246
250
if ( tok . type === 'blockquote_start' ) {
247
- savedState . push ( state ) ;
248
251
state = 'MAYBE_STABILITY_BQ' ;
249
252
return ;
250
253
}
251
254
if ( tok . type === 'blockquote_end' && state === 'MAYBE_STABILITY_BQ' ) {
252
- state = savedState . pop ( ) ;
255
+ state = null ;
253
256
return ;
254
257
}
255
258
if ( ( tok . type === 'paragraph' && state === 'MAYBE_STABILITY_BQ' ) ||
@@ -271,50 +274,7 @@ function parseLists(input) {
271
274
return ;
272
275
} else if ( state === 'MAYBE_STABILITY_BQ' ) {
273
276
output . push ( { type : 'blockquote_start' } ) ;
274
- state = savedState . pop ( ) ;
275
- }
276
- }
277
- if ( state === null ||
278
- ( state === 'AFTERHEADING' && tok . type === 'heading' ) ) {
279
- if ( tok . type === 'heading' ) {
280
- headingIndex = index ;
281
- heading = tok ;
282
- state = 'AFTERHEADING' ;
283
- }
284
- output . push ( tok ) ;
285
- return ;
286
- }
287
- if ( state === 'AFTERHEADING' ) {
288
- if ( tok . type === 'list_start' ) {
289
- state = 'LIST' ;
290
- if ( depth === 0 ) {
291
- output . push ( { type : 'html' , text : '<div class="signature">' } ) ;
292
- }
293
- depth ++ ;
294
- output . push ( tok ) ;
295
- return ;
296
- }
297
- if ( tok . type === 'html' && common . isYAMLBlock ( tok . text ) ) {
298
- tok . text = parseYAML ( tok . text ) ;
299
- }
300
- state = null ;
301
- output . push ( tok ) ;
302
- return ;
303
- }
304
- if ( state === 'LIST' ) {
305
- if ( tok . type === 'list_start' ) {
306
- depth ++ ;
307
- output . push ( tok ) ;
308
- return ;
309
- }
310
- if ( tok . type === 'list_end' ) {
311
- depth -- ;
312
- output . push ( tok ) ;
313
- if ( depth === 0 ) {
314
- state = null ;
315
- output . push ( { type : 'html' , text : '</div>' } ) ;
316
- }
317
- return ;
277
+ state = null ;
318
278
}
319
279
}
320
280
output . push ( tok ) ;
0 commit comments