11/**
2+ * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
23 * @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
34 * @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
45 * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
@@ -38,7 +39,10 @@ export function mathFromMarkdown() {
3839 }
3940 }
4041
41- /** @type {FromMarkdownHandle } */
42+ /**
43+ * @this {CompileContext}
44+ * @type {FromMarkdownHandle }
45+ */
4246 function enterMathFlow ( token ) {
4347 this . enter (
4448 {
@@ -55,27 +59,39 @@ export function mathFromMarkdown() {
5559 )
5660 }
5761
58- /** @type {FromMarkdownHandle } */
62+ /**
63+ * @this {CompileContext}
64+ * @type {FromMarkdownHandle }
65+ */
5966 function enterMathFlowMeta ( ) {
6067 this . buffer ( )
6168 }
6269
63- /** @type {FromMarkdownHandle } */
70+ /**
71+ * @this {CompileContext}
72+ * @type {FromMarkdownHandle }
73+ */
6474 function exitMathFlowMeta ( ) {
6575 const data = this . resume ( )
6676 const node = /** @type {Math } */ ( this . stack [ this . stack . length - 1 ] )
6777 node . meta = data
6878 }
6979
70- /** @type {FromMarkdownHandle } */
80+ /**
81+ * @this {CompileContext}
82+ * @type {FromMarkdownHandle }
83+ */
7184 function exitMathFlowFence ( ) {
7285 // Exit if this is the closing fence.
7386 if ( this . getData ( 'mathFlowInside' ) ) return
7487 this . buffer ( )
7588 this . setData ( 'mathFlowInside' , true )
7689 }
7790
78- /** @type {FromMarkdownHandle } */
91+ /**
92+ * @this {CompileContext}
93+ * @type {FromMarkdownHandle }
94+ */
7995 function exitMathFlow ( token ) {
8096 const data = this . resume ( ) . replace ( / ^ ( \r ? \n | \r ) | ( \r ? \n | \r ) $ / g, '' )
8197 const node = /** @type {Math } */ ( this . exit ( token ) )
@@ -85,7 +101,10 @@ export function mathFromMarkdown() {
85101 this . setData ( 'mathFlowInside' )
86102 }
87103
88- /** @type {FromMarkdownHandle } */
104+ /**
105+ * @this {CompileContext}
106+ * @type {FromMarkdownHandle }
107+ */
89108 function enterMathText ( token ) {
90109 this . enter (
91110 {
@@ -102,7 +121,10 @@ export function mathFromMarkdown() {
102121 this . buffer ( )
103122 }
104123
105- /** @type {FromMarkdownHandle } */
124+ /**
125+ * @this {CompileContext}
126+ * @type {FromMarkdownHandle }
127+ */
106128 function exitMathText ( token ) {
107129 const data = this . resume ( )
108130 const node = /** @type {Math } */ ( this . exit ( token ) )
@@ -111,7 +133,10 @@ export function mathFromMarkdown() {
111133 node . data . hChildren [ 0 ] . value = data
112134 }
113135
114- /** @type {FromMarkdownHandle } */
136+ /**
137+ * @this {CompileContext}
138+ * @type {FromMarkdownHandle }
139+ */
115140 function exitMathData ( token ) {
116141 this . config . enter . data . call ( this , token )
117142 this . config . exit . data . call ( this , token )
@@ -133,8 +158,11 @@ export function mathToMarkdown(options = {}) {
133158
134159 return {
135160 unsafe : [
161+ // @ts -expect-error: To do: use context map.
136162 { character : '\r' , inConstruct : [ 'mathFlowMeta' ] } ,
163+ // @ts -expect-error: To do: use context map.
137164 { character : '\r' , inConstruct : [ 'mathFlowMeta' ] } ,
165+ // @ts -expect-error: To do: use context map.
138166 single
139167 ? { character : '$' , inConstruct : [ 'mathFlowMeta' , 'phrasing' ] }
140168 : {
@@ -154,11 +182,13 @@ export function mathToMarkdown(options = {}) {
154182 function math ( node , _ , context , safeOptions ) {
155183 const raw = node . value || ''
156184 const sequence = '$' . repeat ( Math . max ( longestStreak ( raw , '$' ) + 1 , 2 ) )
185+ // @ts -expect-error: To do: use context map.
157186 const exit = context . enter ( 'mathFlow' )
158187 const tracker = track ( safeOptions )
159188 let value = tracker . move ( sequence )
160189
161190 if ( node . meta ) {
191+ // @ts -expect-error: To do: use context map.
162192 const subexit = context . enter ( 'mathFlowMeta' )
163193 value += tracker . move (
164194 safe ( context , node . meta , {
0 commit comments