summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2022-07-21 18:01:26 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-21 18:01:26 -0400
commit399d7e269834d11c046b390705a9a53d3738f3cf (patch)
treeff3ca9d527f6d707616772d22fcbcb704e41e661 /packages/markdown/remark/src
parentc2968b05421bffe5e3f033e9c5423191ee6a1cf7 (diff)
downloadastro-399d7e269834d11c046b390705a9a53d3738f3cf.tar.gz
astro-399d7e269834d11c046b390705a9a53d3738f3cf.tar.zst
astro-399d7e269834d11c046b390705a9a53d3738f3cf.zip
Fix: use `set:html` when markdown mode is `md` (#4008)
* refactor: add legacy.jsxInMarkdown flag to config * fix: use `set:html` when `markdown.mode` is 'md' * Revert "refactor: add legacy.jsxInMarkdown flag to config" This reverts commit 5572e8d9b33eb1e9168d221f22348d3b3cb4b29a. * fix: move `remarkUnwrap, remarkEscape` to MDX only * fix: only apply scary HTML passthroughs on MDX * fix: move all JSX-specific rehype plugins under `isMDX` * fix: "allowDangerousHtml" for md (required for Shiki) * fix: apply `set:html` for non-layouts too * test: JSX expressions, components, syntax highlighting * chore: changeset * fix: ignore "setup" and "components" in plain MD mode * refactor: create new fixture to avoid weird caching error * fix: dup package name * chore: update lock * fix: apply rehypeCollectHeaders to md
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r--packages/markdown/remark/src/index.ts18
1 files changed, 10 insertions, 8 deletions
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;