6
6
* @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
7
7
*
8
8
* @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
11
11
*/
12
12
13
- import { matters } from 'micromark-extension-frontmatter/matters.js '
13
+ import { toMatters } from 'micromark-extension-frontmatter'
14
14
15
15
/**
16
16
* Create an extension for `mdast-util-from-markdown`.
@@ -21,15 +21,15 @@ import {matters} from 'micromark-extension-frontmatter/matters.js'
21
21
* Extension for `mdast-util-from-markdown`.
22
22
*/
23
23
export function frontmatterFromMarkdown ( options ) {
24
- const settings = matters ( options )
24
+ const matters = toMatters ( options )
25
25
/** @type {FromMarkdownExtension['enter'] } */
26
26
const enter = { }
27
27
/** @type {FromMarkdownExtension['exit'] } */
28
28
const exit = { }
29
29
let index = - 1
30
30
31
- while ( ++ index < settings . length ) {
32
- const matter = settings [ index ]
31
+ while ( ++ index < matters . length ) {
32
+ const matter = matters [ index ]
33
33
enter [ matter . type ] = opener ( matter )
34
34
exit [ matter . type ] = close
35
35
exit [ matter . type + 'Value' ] = value
@@ -62,7 +62,8 @@ function opener(matter) {
62
62
*/
63
63
function close ( token ) {
64
64
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 )
66
67
// Remove the initial and final eol.
67
68
node . value = data . replace ( / ^ ( \r ? \n | \r ) | ( \r ? \n | \r ) $ / g, '' )
68
69
}
@@ -90,11 +91,11 @@ export function frontmatterToMarkdown(options) {
90
91
const unsafe = [ ]
91
92
/** @type {ToMarkdownExtension['handlers'] } */
92
93
const handlers = { }
93
- const settings = matters ( options )
94
+ const matters = toMatters ( options )
94
95
let index = - 1
95
96
96
- while ( ++ index < settings . length ) {
97
- const matter = settings [ index ]
97
+ while ( ++ index < matters . length ) {
98
+ const matter = matters [ index ]
98
99
99
100
// @ts -expect-error: this can add custom frontmatter nodes.
100
101
// Typing those is the responsibility of the end user.
0 commit comments