summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r--packages/markdown/remark/src/index.ts2
-rw-r--r--packages/markdown/remark/src/rehype-escape.ts12
2 files changed, 14 insertions, 0 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index 5c707a4db..8ea5263b8 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -7,6 +7,7 @@ import rehypeExpressions from './rehype-expressions.js';
import rehypeIslands from './rehype-islands.js';
import { remarkJsx, loadRemarkJsx } from './remark-jsx.js';
import rehypeJsx from './rehype-jsx.js';
+import rehypeEscape from './rehype-escape.js';
import remarkPrism from './remark-prism.js';
import remarkUnwrap from './remark-unwrap.js';
import { loadPlugins } from './load-plugins.js';
@@ -76,6 +77,7 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
.use(isMDX ? [rehypeJsx] : [])
.use(isMDX ? [rehypeExpressions] : [])
.use(isMDX ? [] : [rehypeRaw])
+ .use(isMDX ? [rehypeEscape] : [])
.use(rehypeIslands);
let result: string;
diff --git a/packages/markdown/remark/src/rehype-escape.ts b/packages/markdown/remark/src/rehype-escape.ts
new file mode 100644
index 000000000..e0094b463
--- /dev/null
+++ b/packages/markdown/remark/src/rehype-escape.ts
@@ -0,0 +1,12 @@
+import { SKIP, visit } from 'unist-util-visit';
+
+export default function rehypeEscape(): any {
+ return function (node: any): any {
+ return visit(node, 'element', (el) => {
+ if (el.tagName === 'code' || el.tagName === 'pre') {
+ el.properties['data-astro-raw'] = true;
+ }
+ return el;
+ });
+ };
+}