Skip to content

Commit 91a5051

Browse files
committed
Update @types/mdast, mdast utilities
1 parent 70d8a73 commit 91a5051

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

lib/index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*
1313
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
1414
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
15-
* @typedef {import('mdast-util-to-markdown').Context} ToMarkdownContext
16-
* @typedef {import('mdast-util-to-markdown').SafeOptions} SafeOptions
15+
* @typedef {import('mdast-util-to-markdown').State} State
16+
* @typedef {import('mdast-util-to-markdown').Info} Info
1717
*/
1818

1919
/**
@@ -28,12 +28,10 @@
2828
* the delimiters between cells
2929
*/
3030

31-
import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
32-
import {inlineCode} from 'mdast-util-to-markdown/lib/handle/inline-code.js'
3331
import {markdownTable} from 'markdown-table'
32+
import {defaultHandlers} from 'mdast-util-to-markdown'
3433

3534
// To do: next major: use `state` and `state` utilities from `mdast-util-to-markdown`.
36-
// To do: next major: use `defaultHandlers.inlineCode`.
3735
// To do: next major: expose functions.
3836

3937
/**
@@ -73,7 +71,7 @@ function enterTable(token) {
7371
},
7472
token
7573
)
76-
this.setData('inTable', true)
74+
this.data.inTable = true
7775
}
7876

7977
/**
@@ -82,7 +80,7 @@ function enterTable(token) {
8280
*/
8381
function exitTable(token) {
8482
this.exit(token)
85-
this.setData('inTable')
83+
this.data.inTable = undefined
8684
}
8785

8886
/**
@@ -118,7 +116,7 @@ function enterCell(token) {
118116
function exitCodeText(token) {
119117
let value = this.resume()
120118

121-
if (this.getData('inTable')) {
119+
if (this.data.inTable) {
122120
value = value.replace(/\\([\\|])/g, replace)
123121
}
124122

@@ -213,7 +211,7 @@ export function gfmTableToMarkdown(options) {
213211
function handleTableCell(node, _, context, safeOptions) {
214212
const exit = context.enter('tableCell')
215213
const subexit = context.enter('phrasing')
216-
const value = containerPhrasing(node, context, {
214+
const value = context.containerPhrasing(node, {
217215
...safeOptions,
218216
before: around,
219217
after: around
@@ -241,8 +239,8 @@ export function gfmTableToMarkdown(options) {
241239

242240
/**
243241
* @param {Table} node
244-
* @param {ToMarkdownContext} context
245-
* @param {SafeOptions} safeOptions
242+
* @param {State} context
243+
* @param {Info} safeOptions
246244
*/
247245
function handleTableAsData(node, context, safeOptions) {
248246
const children = node.children
@@ -266,8 +264,8 @@ export function gfmTableToMarkdown(options) {
266264

267265
/**
268266
* @param {TableRow} node
269-
* @param {ToMarkdownContext} context
270-
* @param {SafeOptions} safeOptions
267+
* @param {State} context
268+
* @param {Info} safeOptions
271269
*/
272270
function handleTableRowAsData(node, context, safeOptions) {
273271
const children = node.children
@@ -298,7 +296,7 @@ export function gfmTableToMarkdown(options) {
298296
* @param {InlineCode} node
299297
*/
300298
function inlineCodeWithTable(node, parent, context) {
301-
let value = inlineCode(node, parent, context)
299+
let value = defaultHandlers.inlineCode(node, parent, context)
302300

303301
if (context.stack.includes('tableCell')) {
304302
value = value.replace(/\|/g, '\\$&')

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
"index.js"
3939
],
4040
"dependencies": {
41-
"@types/mdast": "^3.0.0",
41+
"@types/mdast": "^4.0.0",
4242
"markdown-table": "^3.0.0",
43-
"mdast-util-from-markdown": "^1.0.0",
44-
"mdast-util-to-markdown": "^1.3.0"
43+
"mdast-util-from-markdown": "^2.0.0",
44+
"mdast-util-to-markdown": "^2.0.0"
4545
},
4646
"devDependencies": {
4747
"@types/node": "^20.0.0",
48-
"c8": "^7.0.0",
49-
"micromark-extension-gfm-table": "^1.0.0",
48+
"c8": "^8.0.0",
49+
"micromark-extension-gfm-table": "^2.0.0",
5050
"prettier": "^2.0.0",
5151
"remark-cli": "^11.0.0",
5252
"remark-preset-wooorm": "^9.0.0",
5353
"string-width": "^6.0.0",
5454
"type-coverage": "^2.0.0",
5555
"typescript": "^5.0.0",
56-
"unist-util-remove-position": "^4.0.0",
56+
"unist-util-remove-position": "^5.0.0",
5757
"xo": "^0.54.0"
5858
},
5959
"scripts": {

test.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('core', () => {
2323
test('gfmTableFromMarkdown', () => {
2424
assert.deepEqual(
2525
fromMarkdown('| a\n| -', {
26-
extensions: [gfmTable],
26+
extensions: [gfmTable()],
2727
mdastExtensions: [gfmTableFromMarkdown]
2828
}),
2929
{
@@ -76,7 +76,7 @@ test('gfmTableFromMarkdown', () => {
7676

7777
assert.deepEqual(
7878
fromMarkdown('| a | b | c | d |\n| - | :- | -: | :-: |', {
79-
extensions: [gfmTable],
79+
extensions: [gfmTable()],
8080
mdastExtensions: [gfmTableFromMarkdown]
8181
}),
8282
{
@@ -178,14 +178,15 @@ test('gfmTableFromMarkdown', () => {
178178
'should support alignment'
179179
)
180180

181+
let tree = fromMarkdown('| `\\|` |\n | --- |', {
182+
extensions: [gfmTable()],
183+
mdastExtensions: [gfmTableFromMarkdown]
184+
})
185+
186+
removePosition(tree, {force: true})
187+
181188
assert.deepEqual(
182-
removePosition(
183-
fromMarkdown('| `\\|` |\n | --- |', {
184-
extensions: [gfmTable],
185-
mdastExtensions: [gfmTableFromMarkdown]
186-
}),
187-
true
188-
),
189+
tree,
189190
{
190191
type: 'root',
191192
children: [
@@ -209,14 +210,15 @@ test('gfmTableFromMarkdown', () => {
209210
'should support an escaped pipe in code in a table cell'
210211
)
211212

213+
tree = fromMarkdown('`\\|`', {
214+
extensions: [gfmTable()],
215+
mdastExtensions: [gfmTableFromMarkdown]
216+
})
217+
218+
removePosition(tree, {force: true})
219+
212220
assert.deepEqual(
213-
removePosition(
214-
fromMarkdown('`\\|`', {
215-
extensions: [gfmTable],
216-
mdastExtensions: [gfmTableFromMarkdown]
217-
}),
218-
true
219-
),
221+
tree,
220222
{
221223
type: 'root',
222224
children: [
@@ -226,14 +228,15 @@ test('gfmTableFromMarkdown', () => {
226228
'should not support an escaped pipe in code *not* in a table cell'
227229
)
228230

231+
tree = fromMarkdown('| `\\\\|`\\\\` b |\n | --- | --- |', {
232+
extensions: [gfmTable()],
233+
mdastExtensions: [gfmTableFromMarkdown]
234+
})
235+
236+
removePosition(tree, {force: true})
237+
229238
assert.deepEqual(
230-
removePosition(
231-
fromMarkdown('| `\\\\|`\\\\` b |\n | --- | --- |', {
232-
extensions: [gfmTable],
233-
mdastExtensions: [gfmTableFromMarkdown]
234-
}),
235-
true
236-
),
239+
tree,
237240
{
238241
type: 'root',
239242
children: [

0 commit comments

Comments
 (0)