Skip to content

Commit

Permalink
Preferve references in the frontmatter data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
remcohaszing committed Jun 21, 2024
1 parent b8ddc31 commit 9e59f0e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
24 changes: 24 additions & 0 deletions fixtures/anchor/expected.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*@jsxRuntime automatic*/
/*@jsxImportSource react*/
export const frontmatter = (() => {
const $0 = {
title: 'Hello frontmatter'
}
return {
original: $0,
reference: $0
}
})()
function _createMdxContent(props) {
return <></>
}
export default function MDXContent(props = {}) {
const { wrapper: MDXLayout } = props.components || {}
return MDXLayout ? (
<MDXLayout {...props}>
<_createMdxContent {...props} />
</MDXLayout>
) : (
_createMdxContent(props)
)
}
5 changes: 5 additions & 0 deletions fixtures/anchor/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
original: &anchor
title: Hello frontmatter
reference: *anchor
---
2 changes: 1 addition & 1 deletion src/remark-mdx-frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const remarkMdxFrontmatter: Plugin<[RemarkMdxFrontmatterOptions?], Root> = ({
{
type: 'VariableDeclarator',
id: { type: 'Identifier', name },
init: valueToEstree(data)
init: valueToEstree(data, { preserveReferences: true })
}
]
}
Expand Down

0 comments on commit 9e59f0e

Please sign in to comment.