Skip to content

Commit

Permalink
Fix: markdown JSX expression inconsistencies (#3152)
Browse files Browse the repository at this point in the history
* fix: remove micromark-extension-mdx-expression to unbreak JSX expressions

* chore: changeset

* deps: update lockfile

* tests: jsx expressions in markdown
  • Loading branch information
bholmesdev authored Apr 19, 2022
1 parent b3a4238 commit 9ba1f4f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/purple-timers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/markdown-remark': patch
---

Fix JSX expression inconsistencies within markdown files
11 changes: 11 additions & 0 deletions packages/astro/test/astro-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ describe('Astro Markdown', () => {
expect($('#test').length).to.be.ok;
});

it('Can parse JSX expressions in markdown pages', async () => {
const html = await fixture.readFile('/jsx-expressions/index.html');
const $ = cheerio.load(html);

expect($('h2').html()).to.equal('Blog Post with JSX expressions')
expect($('p').first().html()).to.equal('JSX at the start of the line!')
for (let listItem of ['test-1', 'test-2', 'test-3']) {
expect($(`#${listItem}`).html()).to.equal(`\n${listItem}\n`)
}
})

it('Can load more complex jsxy stuff', async () => {
const html = await fixture.readFile('/complex/index.html');
const $ = cheerio.load(html);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Blog Post with JSX expressions
paragraph: JSX at the start of the line!
list: ['test-1', 'test-2', 'test-3']
---

## {frontmatter.title}

{frontmatter.paragraph}

{frontmatter.list.map(item => <p id={item}>{item}</p>)}
1 change: 0 additions & 1 deletion packages/markdown/remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"mdast-util-mdx-expression": "^1.2.0",
"mdast-util-mdx-jsx": "^1.2.0",
"mdast-util-to-string": "^3.1.0",
"micromark-extension-mdx-expression": "^1.0.3",
"micromark-extension-mdx-jsx": "^1.0.3",
"prismjs": "^1.27.0",
"rehype-raw": "^6.1.1",
Expand Down
6 changes: 0 additions & 6 deletions packages/markdown/remark/src/remark-expressions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Vite bug: dynamically import() modules needed for CJS. Cache in memory to keep side effects
let mdxExpression: any;
let mdxExpressionFromMarkdown: any;
let mdxExpressionToMarkdown: any;

export function remarkExpressions(this: any, options: any) {
let settings = options || {};
let data = this.data();

add('micromarkExtensions', mdxExpression({}));
add('fromMarkdownExtensions', mdxExpressionFromMarkdown);
add('toMarkdownExtensions', mdxExpressionToMarkdown);

Expand All @@ -19,10 +17,6 @@ export function remarkExpressions(this: any, options: any) {
}

export async function loadRemarkExpressions() {
if (!mdxExpression) {
const micromarkMdxExpression = await import('micromark-extension-mdx-expression');
mdxExpression = micromarkMdxExpression.mdxExpression;
}
if (!mdxExpressionFromMarkdown || !mdxExpressionToMarkdown) {
const mdastUtilMdxExpression = await import('mdast-util-mdx-expression');
mdxExpressionFromMarkdown = mdastUtilMdxExpression.mdxExpressionFromMarkdown;
Expand Down
14 changes: 0 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ba1f4f

Please sign in to comment.