2121import { parseEntities } from 'parse-entities'
2222import { stringifyEntitiesLight } from 'stringify-entities'
2323import { visitParents } from 'unist-util-visit-parents'
24- import { containerFlow } from 'mdast-util-to-markdown/lib/util/container-flow.js'
25- import { containerPhrasing } from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
26- import { checkQuote } from 'mdast-util-to-markdown/lib/util/check-quote.js'
27- import { track } from 'mdast-util-to-markdown/lib/util/track.js'
2824
29- // To do: next major: replace `containerFlow`, `containerPhrasing`, `track`
30- // with `state` methods.
3125// To do: next major: expose functions.
3226
3327const own = { } . hasOwnProperty
@@ -178,7 +172,7 @@ function exitContainerLabel(token) {
178172 * @type {FromMarkdownHandle }
179173 */
180174function enterAttributes ( ) {
181- this . setData ( ' directiveAttributes' , [ ] )
175+ this . data . directiveAttributes = [ ]
182176 this . buffer ( ) // Capture EOLs
183177}
184178
@@ -188,7 +182,7 @@ function enterAttributes() {
188182 */
189183function exitAttributeIdValue ( token ) {
190184 const list = /** @type {Array<[string, string]> } */ (
191- this . getData ( ' directiveAttributes' )
185+ this . data . directiveAttributes
192186 )
193187 list . push ( [
194188 'id' ,
@@ -204,7 +198,7 @@ function exitAttributeIdValue(token) {
204198 */
205199function exitAttributeClassValue ( token ) {
206200 const list = /** @type {Array<[string, string]> } */ (
207- this . getData ( ' directiveAttributes' )
201+ this . data . directiveAttributes
208202 )
209203 list . push ( [
210204 'class' ,
@@ -220,7 +214,7 @@ function exitAttributeClassValue(token) {
220214 */
221215function exitAttributeValue ( token ) {
222216 const list = /** @type {Array<[string, string]> } */ (
223- this . getData ( ' directiveAttributes' )
217+ this . data . directiveAttributes
224218 )
225219 list [ list . length - 1 ] [ 1 ] = parseEntities ( this . sliceSerialize ( token ) , {
226220 attribute : true
@@ -233,7 +227,7 @@ function exitAttributeValue(token) {
233227 */
234228function exitAttributeName ( token ) {
235229 const list = /** @type {Array<[string, string]> } */ (
236- this . getData ( ' directiveAttributes' )
230+ this . data . directiveAttributes
237231 )
238232
239233 // Attribute names in CommonMark are significantly limited, so character
@@ -247,7 +241,7 @@ function exitAttributeName(token) {
247241 */
248242function exitAttributes ( ) {
249243 const list = /** @type {Array<[string, string]> } */ (
250- this . getData ( ' directiveAttributes' )
244+ this . data . directiveAttributes
251245 )
252246 /** @type {Record<string, string> } */
253247 const cleaned = { }
@@ -263,7 +257,7 @@ function exitAttributes() {
263257 }
264258 }
265259
266- this . setData ( ' directiveAttributes' )
260+ this . data . directiveAttributes = undefined
267261 this . resume ( ) // Drop EOLs
268262 const node = /** @type {Directive } */ ( this . stack [ this . stack . length - 1 ] )
269263 node . attributes = cleaned
@@ -282,7 +276,7 @@ function exit(token) {
282276 * @param {Directive } node
283277 */
284278function handleDirective ( node , _ , state , safeOptions ) {
285- const tracker = track ( safeOptions )
279+ const tracker = state . createTracker ( safeOptions )
286280 const sequence = fence ( node )
287281 const exit = state . enter ( node . type )
288282 let value = tracker . move ( sequence + ( node . name || '' ) )
@@ -303,7 +297,11 @@ function handleDirective(node, _, state, safeOptions) {
303297 const subexit = state . enter ( labelType )
304298 value += tracker . move ( '[' )
305299 value += tracker . move (
306- containerPhrasing ( label , state , {
300+ // @ts -expect-error: `containerPhrasing` is typed correctly, but TS
301+ // generates *hardcoded* types, which means that our dynamically added
302+ // directives are not present.
303+ // At some point, TS should fix that, and `from-markdown` should be fine.
304+ state . containerPhrasing ( label , {
307305 ...tracker . current ( ) ,
308306 before : value ,
309307 after : ']'
@@ -326,7 +324,7 @@ function handleDirective(node, _, state, safeOptions) {
326324
327325 if ( shallow && shallow . children && shallow . children . length > 0 ) {
328326 value += tracker . move ( '\n' )
329- value += tracker . move ( containerFlow ( shallow , state , tracker . current ( ) ) )
327+ value += tracker . move ( state . containerFlow ( shallow , tracker . current ( ) ) )
330328 }
331329
332330 value += tracker . move ( '\n' + sequence )
@@ -347,7 +345,7 @@ function peekDirective() {
347345 * @returns {string }
348346 */
349347function attributes ( node , state ) {
350- const quote = checkQuote ( state )
348+ const quote = state . options . quote || '"'
351349 const subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
352350 const attrs = node . attributes || { }
353351 /** @type {Array<string> } */
@@ -427,7 +425,7 @@ function attributes(node, state) {
427425
428426/**
429427 * @param {BlockContent | DefinitionContent } node
430- * @returns {node is Paragraph & {data: {directiveLabel: boolean }} }
428+ * @returns {node is Paragraph & {data: {directiveLabel: true }} }
431429 */
432430function inlineDirectiveLabel ( node ) {
433431 return Boolean (
0 commit comments