55 * @typedef {import('mdast').TableCell } TableCell
66 * @typedef {import('mdast').InlineCode } InlineCode
77 * @typedef {import('markdown-table').MarkdownTableOptions } MarkdownTableOptions
8+ * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
89 * @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
910 * @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
1011 * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
@@ -39,7 +40,10 @@ export const gfmTableFromMarkdown = {
3940 }
4041}
4142
42- /** @type {FromMarkdownHandle } */
43+ /**
44+ * @this {CompileContext}
45+ * @type {FromMarkdownHandle }
46+ */
4347function enterTable ( token ) {
4448 /** @type {Array<'left'|'right'|'center'|'none'> } */
4549 // @ts -expect-error: `align` is custom.
@@ -52,36 +56,54 @@ function enterTable(token) {
5256 } ,
5357 token
5458 )
59+ // @ts -expect-error: to do: map.
5560 this . setData ( 'inTable' , true )
5661}
5762
58- /** @type {FromMarkdownHandle } */
63+ /**
64+ * @this {CompileContext}
65+ * @type {FromMarkdownHandle }
66+ */
5967function exitTable ( token ) {
6068 this . exit ( token )
69+ // @ts -expect-error: to do: map.
6170 this . setData ( 'inTable' )
6271}
6372
64- /** @type {FromMarkdownHandle } */
73+ /**
74+ * @this {CompileContext}
75+ * @type {FromMarkdownHandle }
76+ */
6577function enterRow ( token ) {
6678 this . enter ( { type : 'tableRow' , children : [ ] } , token )
6779}
6880
69- /** @type {FromMarkdownHandle } */
81+ /**
82+ * @this {CompileContext}
83+ * @type {FromMarkdownHandle }
84+ */
7085function exit ( token ) {
7186 this . exit ( token )
7287}
7388
74- /** @type {FromMarkdownHandle } */
89+ /**
90+ * @this {CompileContext}
91+ * @type {FromMarkdownHandle }
92+ */
7593function enterCell ( token ) {
7694 this . enter ( { type : 'tableCell' , children : [ ] } , token )
7795}
7896
7997// Overwrite the default code text data handler to unescape escaped pipes when
8098// they are in tables.
81- /** @type {FromMarkdownHandle } */
99+ /**
100+ * @this {CompileContext}
101+ * @type {FromMarkdownHandle }
102+ */
82103function exitCodeText ( token ) {
83104 let value = this . resume ( )
84105
106+ // @ts -expect-error: to do: map.
85107 if ( this . getData ( 'inTable' ) ) {
86108 value = value . replace ( / \\ ( [ \\ | ] ) / g, replace )
87109 }
@@ -114,12 +136,15 @@ export function gfmTableToMarkdown(options) {
114136
115137 return {
116138 unsafe : [
139+ // @ts -expect-error: to do: map.
117140 { character : '\r' , inConstruct : 'tableCell' } ,
141+ // @ts -expect-error: to do: map.
118142 { character : '\n' , inConstruct : 'tableCell' } ,
119143 // A pipe, when followed by a tab or space (padding), or a dash or colon
120144 // (unpadded delimiter row), could result in a table.
121145 { atBreak : true , character : '|' , after : '[\t :-]' } ,
122146 // A pipe in a cell must be encoded.
147+ // @ts -expect-error: to do: map.
123148 { character : '|' , inConstruct : 'tableCell' } ,
124149 // A colon must be followed by a dash, in which case it could start a
125150 // delimiter row.
@@ -171,6 +196,7 @@ export function gfmTableToMarkdown(options) {
171196 * @param {TableCell } node
172197 */
173198 function handleTableCell ( node , _ , context , safeOptions ) {
199+ // @ts -expect-error: to do: map.
174200 const exit = context . enter ( 'tableCell' )
175201 const subexit = context . enter ( 'phrasing' )
176202 const value = containerPhrasing ( node , context , {
@@ -206,6 +232,7 @@ export function gfmTableToMarkdown(options) {
206232 let index = - 1
207233 /** @type {Array<Array<string>> } */
208234 const result = [ ]
235+ // @ts -expect-error: to do: map.
209236 const subexit = context . enter ( 'table' )
210237
211238 while ( ++ index < children . length ) {
@@ -231,6 +258,7 @@ export function gfmTableToMarkdown(options) {
231258 let index = - 1
232259 /** @type {Array<string> } */
233260 const result = [ ]
261+ // @ts -expect-error: to do: map.
234262 const subexit = context . enter ( 'tableRow' )
235263
236264 while ( ++ index < children . length ) {
@@ -257,6 +285,7 @@ export function gfmTableToMarkdown(options) {
257285 function inlineCodeWithTable ( node , parent , context ) {
258286 let value = inlineCode ( node , parent , context )
259287
288+ // @ts -expect-error: to do: map.
260289 if ( context . stack . includes ( 'tableCell' ) ) {
261290 value = value . replace ( / \| / g, '\\$&' )
262291 }
0 commit comments