');
+ });
+
+ describe('syntax highlighting', async () => {
+ it('handles Shiki', async () => {
+ const html = await fixture.readFile('/code-in-md/index.html');
+ const $ = cheerio.load(html);
+
+ expect($('pre.astro-code').length).to.not.equal(0);
+ });
+
+ it('handles Prism', async () => {
+ fixture = await loadFixture({
+ root: './fixtures/astro-markdown-md-mode/',
+ markdown: {
+ syntaxHighlight: 'prism',
+ mode: 'md',
+ },
+ });
+ await fixture.build();
+
+ const html = await fixture.readFile('/code-in-md/index.html');
+ const $ = cheerio.load(html);
+
+ expect($('pre.language-html').length).to.not.equal(0);
+ });
+ });
+});
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/astro.config.mjs b/packages/astro/test/fixtures/astro-markdown-md-mode/astro.config.mjs
new file mode 100644
index 000000000..3fab631f3
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/astro.config.mjs
@@ -0,0 +1,11 @@
+import { defineConfig } from 'astro/config';
+import svelte from "@astrojs/svelte";
+
+// https://astro.build/config
+export default defineConfig({
+ markdown: {
+ mode: 'md',
+ },
+ integrations: [svelte()],
+ site: 'https://astro.build/',
+});
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/package.json b/packages/astro/test/fixtures/astro-markdown-md-mode/package.json
new file mode 100644
index 000000000..48a6c6816
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/astro-markdown-md-mode",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/svelte": "workspace:*",
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/src/components/Counter.svelte b/packages/astro/test/fixtures/astro-markdown-md-mode/src/components/Counter.svelte
new file mode 100644
index 000000000..4e91b2659
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/src/components/Counter.svelte
@@ -0,0 +1,5 @@
+
+
+
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/code-in-md.md b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/code-in-md.md
new file mode 100644
index 000000000..72206a868
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/code-in-md.md
@@ -0,0 +1,7 @@
+# Fenced code blocks
+
+```html
+
+ This should also work without any problems.
+
+```
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/components.md b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/components.md
new file mode 100644
index 000000000..cd27bc09f
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/components.md
@@ -0,0 +1,5 @@
+---
+setup: import Counter from '../components/Counter.svelte'
+---
+
+
diff --git a/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/jsx-expressions.md b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/jsx-expressions.md
new file mode 100644
index 000000000..b87efbb2d
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-markdown-md-mode/src/pages/jsx-expressions.md
@@ -0,0 +1,13 @@
+---
+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 => - {item}
)}
+
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index 567a4414d..6c72ba981 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -46,8 +46,7 @@ export async function renderMarkdown(
let parser = unified()
.use(markdown)
- .use(isMDX ? [remarkMdxish, remarkMarkAndUnravel] : [])
- .use([remarkUnwrap, remarkEscape]);
+ .use(isMDX ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : [])
if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
@@ -76,13 +75,13 @@ export async function renderMarkdown(
markdownToHtml as any,
{
allowDangerousHtml: true,
- passThrough: [
+ passThrough: isMDX ? [
'raw',
'mdxFlowExpression',
'mdxJsxFlowElement',
'mdxJsxTextElement',
'mdxTextExpression',
- ],
+ ] : [],
},
],
]);
@@ -92,10 +91,13 @@ export async function renderMarkdown(
});
parser
- .use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw])
- .use(rehypeEscape)
- .use(rehypeIslands)
- .use([rehypeCollectHeaders])
+ .use(isMDX ? [
+ rehypeJsx,
+ rehypeExpressions,
+ rehypeEscape,
+ rehypeIslands,
+ rehypeCollectHeaders,
+ ] : [rehypeCollectHeaders, rehypeRaw])
.use(rehypeStringify, { allowDangerousHtml: true });
let result: string;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0f48f3ed9..633ee1b9d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1280,6 +1280,14 @@ importers:
dependencies:
astro: link:../../..
+ packages/astro/test/fixtures/astro-markdown-md-mode:
+ specifiers:
+ '@astrojs/svelte': workspace:*
+ astro: workspace:*
+ dependencies:
+ '@astrojs/svelte': link:../../../../integrations/svelte
+ astro: link:../../..
+
packages/astro/test/fixtures/astro-markdown-plugins:
specifiers:
'@astrojs/preact': workspace:*