11/**
22 * @typedef {import('mdast').BlockContent } BlockContent
3- * @typedef {import('mdast').Root } Root
43 * @typedef {import('mdast').Paragraph } Paragraph
5- * @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
6- * @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
4+ *
75 * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
6+ * @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
7+ * @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
88 * @typedef {import('mdast-util-from-markdown').Token } Token
9+ *
910 * @typedef {import('mdast-util-to-markdown').ConstructName } ConstructName
10- * @typedef {import('mdast-util-to-markdown/lib/types.js').Handle } ToMarkdownHandle
11+ * @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
12+ * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
1113 * @typedef {import('mdast-util-to-markdown').State } State
12- * @typedef {import('mdast-util-to-markdown/lib/types.js').Options } ToMarkdownExtension
13- * @typedef {import('../complex-types.js').ContainerDirective } ContainerDirective
14- * @typedef {import('../complex-types.js').LeafDirective } LeafDirective
15- * @typedef {import('../complex-types.js').TextDirective } TextDirective
16- * @typedef {ContainerDirective|LeafDirective|TextDirective } Directive
14+ *
15+ * @typedef {import('../index.js').LeafDirective } LeafDirective
16+ * @typedef {import('../index.js').TextDirective } TextDirective
17+ * @typedef {import('../index.js').Directive } Directive
1718 */
1819
1920import { parseEntities } from 'parse-entities'
@@ -24,6 +25,9 @@ import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phras
2425import { checkQuote } from 'mdast-util-to-markdown/lib/util/check-quote.js'
2526import { track } from 'mdast-util-to-markdown/lib/util/track.js'
2627
28+ // To do: next major: replace `containerFlow`, `containerPhrasing`, `track`
29+ // with `state` methods.
30+
2731const own = { } . hasOwnProperty
2832
2933const shortcut = / ^ [ ^ \t \n \r " # ' . < = > ` } ] + $ /
@@ -173,7 +177,7 @@ function enterAttributes() {
173177 * @type {FromMarkdownHandle }
174178 */
175179function exitAttributeIdValue ( token ) {
176- const list = /** @type {Array. <[string, string]> } */ (
180+ const list = /** @type {Array<[string, string]> } */ (
177181 this . getData ( 'directiveAttributes' )
178182 )
179183 list . push ( [
@@ -189,7 +193,7 @@ function exitAttributeIdValue(token) {
189193 * @type {FromMarkdownHandle }
190194 */
191195function exitAttributeClassValue ( token ) {
192- const list = /** @type {Array. <[string, string]> } */ (
196+ const list = /** @type {Array<[string, string]> } */ (
193197 this . getData ( 'directiveAttributes' )
194198 )
195199 list . push ( [
@@ -205,7 +209,7 @@ function exitAttributeClassValue(token) {
205209 * @type {FromMarkdownHandle }
206210 */
207211function exitAttributeValue ( token ) {
208- const list = /** @type {Array. <[string, string]> } */ (
212+ const list = /** @type {Array<[string, string]> } */ (
209213 this . getData ( 'directiveAttributes' )
210214 )
211215 list [ list . length - 1 ] [ 1 ] = parseEntities ( this . sliceSerialize ( token ) , {
@@ -218,7 +222,7 @@ function exitAttributeValue(token) {
218222 * @type {FromMarkdownHandle }
219223 */
220224function exitAttributeName ( token ) {
221- const list = /** @type {Array. <[string, string]> } */ (
225+ const list = /** @type {Array<[string, string]> } */ (
222226 this . getData ( 'directiveAttributes' )
223227 )
224228
@@ -232,10 +236,10 @@ function exitAttributeName(token) {
232236 * @type {FromMarkdownHandle }
233237 */
234238function exitAttributes ( ) {
235- const list = /** @type {Array. <[string, string]> } */ (
239+ const list = /** @type {Array<[string, string]> } */ (
236240 this . getData ( 'directiveAttributes' )
237241 )
238- /** @type {Record. <string, string> } */
242+ /** @type {Record<string, string> } */
239243 const cleaned = { }
240244 let index = - 1
241245
@@ -336,13 +340,13 @@ function attributes(node, state) {
336340 const quote = checkQuote ( state )
337341 const subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
338342 const attrs = node . attributes || { }
339- /** @type {Array. <string> } */
343+ /** @type {Array<string> } */
340344 const values = [ ]
341- /** @type {string| undefined } */
345+ /** @type {string | undefined } */
342346 let classesFull
343- /** @type {string| undefined } */
347+ /** @type {string | undefined } */
344348 let classes
345- /** @type {string| undefined } */
349+ /** @type {string | undefined } */
346350 let id
347351 /** @type {string } */
348352 let key
@@ -359,9 +363,9 @@ function attributes(node, state) {
359363 id = shortcut . test ( value ) ? '#' + value : quoted ( 'id' , value )
360364 } else if ( key === 'class' ) {
361365 const list = value . split ( / [ \t \n \r ] + / g)
362- /** @type {Array. <string> } */
366+ /** @type {Array<string> } */
363367 const classesFullList = [ ]
364- /** @type {Array. <string> } */
368+ /** @type {Array<string> } */
365369 const classesList = [ ]
366370 let index = - 1
367371
@@ -429,7 +433,20 @@ function fence(node) {
429433 let size = 0
430434
431435 if ( node . type === 'containerDirective' ) {
432- visitParents ( node , 'containerDirective' , onvisit )
436+ visitParents ( node , function ( node , parents ) {
437+ if ( node . type === 'containerDirective' ) {
438+ let index = parents . length
439+ let nesting = 0
440+
441+ while ( index -- ) {
442+ if ( parents [ index ] . type === 'containerDirective' ) {
443+ nesting ++
444+ }
445+ }
446+
447+ if ( nesting > size ) size = nesting
448+ }
449+ } )
433450 size += 3
434451 } else if ( node . type === 'leafDirective' ) {
435452 size = 2
@@ -438,18 +455,4 @@ function fence(node) {
438455 }
439456
440457 return ':' . repeat ( size )
441-
442- /** @type {import('unist-util-visit-parents').BuildVisitor<Root, Directive> } */
443- function onvisit ( _ , parents ) {
444- let index = parents . length
445- let nesting = 0
446-
447- while ( index -- ) {
448- if ( parents [ index ] . type === 'containerDirective' ) {
449- nesting ++
450- }
451- }
452-
453- if ( nesting > size ) size = nesting
454- }
455458}
0 commit comments