5
5
* @typedef {import('mdast').TableCell } TableCell
6
6
* @typedef {import('mdast').InlineCode } InlineCode
7
7
* @typedef {import('markdown-table').MarkdownTableOptions } MarkdownTableOptions
8
+ * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
8
9
* @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
9
10
* @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
10
11
* @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
@@ -39,7 +40,10 @@ export const gfmTableFromMarkdown = {
39
40
}
40
41
}
41
42
42
- /** @type {FromMarkdownHandle } */
43
+ /**
44
+ * @this {CompileContext}
45
+ * @type {FromMarkdownHandle }
46
+ */
43
47
function enterTable ( token ) {
44
48
/** @type {Array<'left'|'right'|'center'|'none'> } */
45
49
// @ts -expect-error: `align` is custom.
@@ -52,36 +56,54 @@ function enterTable(token) {
52
56
} ,
53
57
token
54
58
)
59
+ // @ts -expect-error: to do: map.
55
60
this . setData ( 'inTable' , true )
56
61
}
57
62
58
- /** @type {FromMarkdownHandle } */
63
+ /**
64
+ * @this {CompileContext}
65
+ * @type {FromMarkdownHandle }
66
+ */
59
67
function exitTable ( token ) {
60
68
this . exit ( token )
69
+ // @ts -expect-error: to do: map.
61
70
this . setData ( 'inTable' )
62
71
}
63
72
64
- /** @type {FromMarkdownHandle } */
73
+ /**
74
+ * @this {CompileContext}
75
+ * @type {FromMarkdownHandle }
76
+ */
65
77
function enterRow ( token ) {
66
78
this . enter ( { type : 'tableRow' , children : [ ] } , token )
67
79
}
68
80
69
- /** @type {FromMarkdownHandle } */
81
+ /**
82
+ * @this {CompileContext}
83
+ * @type {FromMarkdownHandle }
84
+ */
70
85
function exit ( token ) {
71
86
this . exit ( token )
72
87
}
73
88
74
- /** @type {FromMarkdownHandle } */
89
+ /**
90
+ * @this {CompileContext}
91
+ * @type {FromMarkdownHandle }
92
+ */
75
93
function enterCell ( token ) {
76
94
this . enter ( { type : 'tableCell' , children : [ ] } , token )
77
95
}
78
96
79
97
// Overwrite the default code text data handler to unescape escaped pipes when
80
98
// they are in tables.
81
- /** @type {FromMarkdownHandle } */
99
+ /**
100
+ * @this {CompileContext}
101
+ * @type {FromMarkdownHandle }
102
+ */
82
103
function exitCodeText ( token ) {
83
104
let value = this . resume ( )
84
105
106
+ // @ts -expect-error: to do: map.
85
107
if ( this . getData ( 'inTable' ) ) {
86
108
value = value . replace ( / \\ ( [ \\ | ] ) / g, replace )
87
109
}
@@ -114,12 +136,15 @@ export function gfmTableToMarkdown(options) {
114
136
115
137
return {
116
138
unsafe : [
139
+ // @ts -expect-error: to do: map.
117
140
{ character : '\r' , inConstruct : 'tableCell' } ,
141
+ // @ts -expect-error: to do: map.
118
142
{ character : '\n' , inConstruct : 'tableCell' } ,
119
143
// A pipe, when followed by a tab or space (padding), or a dash or colon
120
144
// (unpadded delimiter row), could result in a table.
121
145
{ atBreak : true , character : '|' , after : '[\t :-]' } ,
122
146
// A pipe in a cell must be encoded.
147
+ // @ts -expect-error: to do: map.
123
148
{ character : '|' , inConstruct : 'tableCell' } ,
124
149
// A colon must be followed by a dash, in which case it could start a
125
150
// delimiter row.
@@ -171,6 +196,7 @@ export function gfmTableToMarkdown(options) {
171
196
* @param {TableCell } node
172
197
*/
173
198
function handleTableCell ( node , _ , context , safeOptions ) {
199
+ // @ts -expect-error: to do: map.
174
200
const exit = context . enter ( 'tableCell' )
175
201
const subexit = context . enter ( 'phrasing' )
176
202
const value = containerPhrasing ( node , context , {
@@ -206,6 +232,7 @@ export function gfmTableToMarkdown(options) {
206
232
let index = - 1
207
233
/** @type {Array<Array<string>> } */
208
234
const result = [ ]
235
+ // @ts -expect-error: to do: map.
209
236
const subexit = context . enter ( 'table' )
210
237
211
238
while ( ++ index < children . length ) {
@@ -231,6 +258,7 @@ export function gfmTableToMarkdown(options) {
231
258
let index = - 1
232
259
/** @type {Array<string> } */
233
260
const result = [ ]
261
+ // @ts -expect-error: to do: map.
234
262
const subexit = context . enter ( 'tableRow' )
235
263
236
264
while ( ++ index < children . length ) {
@@ -257,6 +285,7 @@ export function gfmTableToMarkdown(options) {
257
285
function inlineCodeWithTable ( node , parent , context ) {
258
286
let value = inlineCode ( node , parent , context )
259
287
288
+ // @ts -expect-error: to do: map.
260
289
if ( context . stack . includes ( 'tableCell' ) ) {
261
290
value = value . replace ( / \| / g, '\\$&' )
262
291
}
0 commit comments