-
My objective is to be able to parse to AST and later convert the AST back via stringify to a similar MDX file. Input MDX files contain frontmatter, markdown and MDX code. I just want to extact markdown text strings in the AST and some of the frontmatter fields and have the parser recognise but leave the MDX code unchanged. I've got this all working with Frontmatter and Markdown parsers This works fine ... const processor = remark().use(frontmatter, ['yaml']).use(stringify);
const ast = processor.parse(markdownIn);
const markdownOut = processor.stringify(ast); But once I add the MDX parser it blows up with the exception shown below. import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
import remarkMdx from "remark-mdx";
import { it, describe, expect } from "vitest";
describe("MDX parse and stringify", () => {
it("should parse MDX with no code", () => {
const mdxIn = `
---
title: My MDX Post
date: 2023-10-16
---
# This is an MDX post
With some content and a JSX component: <MyComponent />
`;
const processor = unified()
.use(remarkParse)
.use(remarkMdx)
.use(remarkStringify);
// Parse markdown to AST
const ast = processor.parse(mdxIn); // << THROWS
console.log("ast>>", JSON.stringify(ast, null, 2));
const mdxOut = processor.stringify(ast);
console.log("mdxOut>>", mdxOut);
expect(mdxOut).toEqual(mdxIn);
});
}); Throws this exception ...
/**
* @this {CompileContext}
* @type {FromMarkdownHandle}
*/
function enterMdxJsxTag(token) {
/** @type {Tag} */
const tag = {
name: undefined,
attributes: [],
close: false,
selfClosing: false,
start: token.start,
end: token.end
}
if (!this.getData('mdxJsxTagStack')) this.setData('mdxJsxTagStack', []) <<< THROWS exception here
this.setData('mdxJsxTag', tag)
this.buffer()
} |
Beta Was this translation helpful? Give feedback.
Answered by
wooorm
Oct 18, 2023
Replies: 1 comment 3 replies
-
#2373. Done in a couple days! |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tohagan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#2373. Done in a couple days!