Skip to content

Commit d4c6b85

Browse files
committed
Update @types/mdast, mdast utilities
1 parent b6a190d commit d4c6b85

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

Diff for: index.d.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ declare module 'mdast-util-to-markdown' {
7777
// Add nodes to tree.
7878
declare module 'mdast' {
7979
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
80-
interface StaticPhrasingContentMap {
80+
interface BlockContentMap {
81+
math: Math
82+
}
83+
84+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
85+
interface PhrasingContentMap {
8186
inlineMath: InlineMath
8287
}
8388

8489
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
85-
interface BlockContentMap {
90+
interface RootContentMap {
91+
inlineMath: InlineMath
8692
math: Math
8793
}
8894
}

Diff for: lib/index.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919

2020
import {longestStreak} from 'longest-streak'
21-
import {safe} from 'mdast-util-to-markdown/lib/util/safe.js'
22-
import {track} from 'mdast-util-to-markdown/lib/util/track.js'
23-
import {patternCompile} from 'mdast-util-to-markdown/lib/util/pattern-compile.js'
2421

2522
/**
2623
* Create an extension for `mdast-util-from-markdown`.
@@ -89,9 +86,9 @@ export function mathFromMarkdown() {
8986
*/
9087
function exitMathFlowFence() {
9188
// Exit if this is the closing fence.
92-
if (this.getData('mathFlowInside')) return
89+
if (this.data.mathFlowInside) return
9390
this.buffer()
94-
this.setData('mathFlowInside', true)
91+
this.data.mathFlowInside = true
9592
}
9693

9794
/**
@@ -100,11 +97,12 @@ export function mathFromMarkdown() {
10097
*/
10198
function exitMathFlow(token) {
10299
const data = this.resume().replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
103-
const node = /** @type {Math} */ (this.exit(token))
100+
const node = /** @type {Math} */ (this.stack[this.stack.length - 1])
101+
this.exit(token)
104102
node.value = data
105103
// @ts-expect-error: we defined it.
106104
node.data.hChildren[0].value = data
107-
this.setData('mathFlowInside')
105+
this.data.mathFlowInside = undefined
108106
}
109107

110108
/**
@@ -133,7 +131,8 @@ export function mathFromMarkdown() {
133131
*/
134132
function exitMathText(token) {
135133
const data = this.resume()
136-
const node = /** @type {Math} */ (this.exit(token))
134+
const node = /** @type {Math} */ (this.stack[this.stack.length - 1])
135+
this.exit(token)
137136
node.value = data
138137
// @ts-expect-error: we defined it.
139138
node.data.hChildren[0].value = data
@@ -190,15 +189,15 @@ export function mathToMarkdown(options) {
190189
// <https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/handle/code.js>
191190
function math(node, _, context, safeOptions) {
192191
const raw = node.value || ''
193-
const tracker = track(safeOptions)
192+
const tracker = context.createTracker(safeOptions)
194193
const sequence = '$'.repeat(Math.max(longestStreak(raw, '$') + 1, 2))
195194
const exit = context.enter('mathFlow')
196195
let value = tracker.move(sequence)
197196

198197
if (node.meta) {
199198
const subexit = context.enter('mathFlowMeta')
200199
value += tracker.move(
201-
safe(context, node.meta, {
200+
context.safe(node.meta, {
202201
before: value,
203202
after: '\n',
204203
encode: ['$'],
@@ -270,15 +269,16 @@ export function mathToMarkdown(options) {
270269
// them out.
271270
while (++index < context.unsafe.length) {
272271
const pattern = context.unsafe[index]
273-
const expression = patternCompile(pattern)
274-
/** @type {RegExpExecArray | null} */
275-
let match
276272

277273
// Only look for `atBreak`s.
278274
// Btw: note that `atBreak` patterns will always start the regex at LF or
279275
// CR.
280276
if (!pattern.atBreak) continue
281277

278+
const expression = context.compilePattern(pattern)
279+
/** @type {RegExpExecArray | null} */
280+
let match
281+
282282
while ((match = expression.exec(value))) {
283283
let position = match.index
284284

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
"index.js"
3838
],
3939
"dependencies": {
40-
"@types/mdast": "^3.0.0",
40+
"@types/mdast": "^4.0.0",
4141
"longest-streak": "^3.0.0",
42-
"mdast-util-to-markdown": "^1.3.0"
42+
"mdast-util-from-markdown": "^2.0.0",
43+
"mdast-util-to-markdown": "^2.1.0"
4344
},
4445
"devDependencies": {
4546
"@types/node": "^20.0.0",
4647
"c8": "^8.0.0",
47-
"mdast-util-from-markdown": "^1.0.0",
48-
"micromark-extension-math": "^2.0.0",
48+
"micromark-extension-math": "^3.0.0",
4949
"prettier": "^3.0.0",
5050
"remark-cli": "^11.0.0",
5151
"remark-preset-wooorm": "^9.0.0",

0 commit comments

Comments
 (0)