Skip to content

Commit 9e59f0e

Browse files
committedJun 21, 2024
Preferve references in the frontmatter data
This means that objects generated from YAML anchors now point to the same reference. The same goes for custom frontmatter parsers. Custom parsers may now also return objects that contain recursive references.
1 parent b8ddc31 commit 9e59f0e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
 

‎fixtures/anchor/expected.jsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*@jsxRuntime automatic*/
2+
/*@jsxImportSource react*/
3+
export const frontmatter = (() => {
4+
const $0 = {
5+
title: 'Hello frontmatter'
6+
}
7+
return {
8+
original: $0,
9+
reference: $0
10+
}
11+
})()
12+
function _createMdxContent(props) {
13+
return <></>
14+
}
15+
export default function MDXContent(props = {}) {
16+
const { wrapper: MDXLayout } = props.components || {}
17+
return MDXLayout ? (
18+
<MDXLayout {...props}>
19+
<_createMdxContent {...props} />
20+
</MDXLayout>
21+
) : (
22+
_createMdxContent(props)
23+
)
24+
}

‎fixtures/anchor/input.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
original: &anchor
3+
title: Hello frontmatter
4+
reference: *anchor
5+
---

‎src/remark-mdx-frontmatter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const remarkMdxFrontmatter: Plugin<[RemarkMdxFrontmatterOptions?], Root> = ({
7575
{
7676
type: 'VariableDeclarator',
7777
id: { type: 'Identifier', name },
78-
init: valueToEstree(data)
78+
init: valueToEstree(data, { preserveReferences: true })
7979
}
8080
]
8181
}

0 commit comments

Comments
 (0)