Skip to content

Commit 6405823

Browse files
committed
Update @types/mdast, mdast utilities
1 parent 1031508 commit 6405823

File tree

4 files changed

+169
-143
lines changed

4 files changed

+169
-143
lines changed

lib/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
77
*
88
* @typedef {import('micromark-extension-frontmatter').Options} Options
9-
* @typedef {import('micromark-extension-frontmatter/matters.js').Matter} Matter
10-
* @typedef {import('micromark-extension-frontmatter/matters.js').Info} Info
9+
* @typedef {import('micromark-extension-frontmatter').Matter} Matter
10+
* @typedef {import('micromark-extension-frontmatter').Info} Info
1111
*/
1212

13-
import {matters} from 'micromark-extension-frontmatter/matters.js'
13+
import {toMatters} from 'micromark-extension-frontmatter'
1414

1515
/**
1616
* Create an extension for `mdast-util-from-markdown`.
@@ -21,15 +21,15 @@ import {matters} from 'micromark-extension-frontmatter/matters.js'
2121
* Extension for `mdast-util-from-markdown`.
2222
*/
2323
export function frontmatterFromMarkdown(options) {
24-
const settings = matters(options)
24+
const matters = toMatters(options)
2525
/** @type {FromMarkdownExtension['enter']} */
2626
const enter = {}
2727
/** @type {FromMarkdownExtension['exit']} */
2828
const exit = {}
2929
let index = -1
3030

31-
while (++index < settings.length) {
32-
const matter = settings[index]
31+
while (++index < matters.length) {
32+
const matter = matters[index]
3333
enter[matter.type] = opener(matter)
3434
exit[matter.type] = close
3535
exit[matter.type + 'Value'] = value
@@ -62,7 +62,8 @@ function opener(matter) {
6262
*/
6363
function close(token) {
6464
const data = this.resume()
65-
const node = /** @type {Literal} */ (this.exit(token))
65+
const node = /** @type {Literal} */ (this.stack[this.stack.length - 1])
66+
this.exit(token)
6667
// Remove the initial and final eol.
6768
node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
6869
}
@@ -90,11 +91,11 @@ export function frontmatterToMarkdown(options) {
9091
const unsafe = []
9192
/** @type {ToMarkdownExtension['handlers']} */
9293
const handlers = {}
93-
const settings = matters(options)
94+
const matters = toMatters(options)
9495
let index = -1
9596

96-
while (++index < settings.length) {
97-
const matter = settings[index]
97+
while (++index < matters.length) {
98+
const matter = matters[index]
9899

99100
// @ts-expect-error: this can add custom frontmatter nodes.
100101
// Typing those is the responsibility of the end user.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
"index.js"
3737
],
3838
"dependencies": {
39-
"@types/mdast": "^3.0.0",
40-
"mdast-util-to-markdown": "^1.3.0",
41-
"micromark-extension-frontmatter": "^1.0.0"
39+
"@types/mdast": "^4.0.0",
40+
"mdast-util-from-markdown": "^2.0.0",
41+
"mdast-util-to-markdown": "^2.0.0",
42+
"micromark-extension-frontmatter": "^2.0.0"
4243
},
4344
"devDependencies": {
4445
"@types/node": "^20.0.0",
45-
"c8": "^7.0.0",
46-
"mdast-util-from-markdown": "^1.0.0",
46+
"c8": "^8.0.0",
4747
"prettier": "^2.0.0",
4848
"remark-cli": "^11.0.0",
4949
"remark-preset-wooorm": "^9.0.0",
5050
"type-coverage": "^2.0.0",
5151
"typescript": "^5.0.0",
52-
"unist-util-remove-position": "^4.0.0",
52+
"unist-util-remove-position": "^5.0.0",
5353
"xo": "^0.54.0"
5454
},
5555
"scripts": {

test-types.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ interface Custom extends Literal {
1717

1818
declare module 'mdast' {
1919
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
20-
interface FrontmatterContentMap {
20+
interface RootContentMap {
21+
custom: Custom
22+
json: Json
2123
toml: Toml
24+
}
25+
26+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
27+
interface FrontmatterContentMap {
2228
custom: Custom
2329
json: Json
30+
toml: Toml
2431
}
2532
}

0 commit comments

Comments
 (0)