Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: markdown JSX expression inconsistencies #3152

Merged
merged 4 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.