@@ -93,7 +93,7 @@ function render(opts, cb) {
9393 filename = path . basename ( filename , '.md' ) ;
9494
9595 parseText ( lexed ) ;
96- lexed = parseLists ( lexed ) ;
96+ lexed = preprocessElements ( lexed ) ;
9797
9898 // Generate the table of contents.
9999 // This mutates the lexed contents in-place.
@@ -231,25 +231,28 @@ function parseText(lexed) {
231231 } ) ;
232232}
233233
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 ) {
237236 var state = null ;
238- const savedState = [ ] ;
239- var depth = 0 ;
240237 const output = [ ] ;
241238 let headingIndex = - 1 ;
242239 let heading = null ;
243240
244241 output . links = input . links ;
245242 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+ }
246250 if ( tok . type === 'blockquote_start' ) {
247- savedState . push ( state ) ;
248251 state = 'MAYBE_STABILITY_BQ' ;
249252 return ;
250253 }
251254 if ( tok . type === 'blockquote_end' && state === 'MAYBE_STABILITY_BQ' ) {
252- state = savedState . pop ( ) ;
255+ state = null ;
253256 return ;
254257 }
255258 if ( ( tok . type === 'paragraph' && state === 'MAYBE_STABILITY_BQ' ) ||
@@ -271,50 +274,7 @@ function parseLists(input) {
271274 return ;
272275 } else if ( state === 'MAYBE_STABILITY_BQ' ) {
273276 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 ;
318278 }
319279 }
320280 output . push ( tok ) ;
0 commit comments