Skip to content

Commit 16107b6

Browse files
authored
Remove Astro-flavored Markdown from @astrojs/markdown-remark (#5785)
1 parent 54076a4 commit 16107b6

22 files changed

+12
-842
lines changed

.changeset/poor-chicken-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/markdown-remark': major
3+
---
4+
5+
Drop support for legacy Astro-flavored Markdown

packages/astro/src/vite-plugin-markdown/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
7171
const renderResult = await renderMarkdown(raw.content, {
7272
...settings.config.markdown,
7373
fileURL: new URL(`file://${fileId}`),
74-
isAstroFlavoredMd: false,
7574
isExperimentalContentCollections: settings.config.experimental.contentCollections,
7675
contentDir: getContentPaths(settings.config).contentDir,
7776
frontmatter: raw.data,

packages/markdown/remark/package.json

-10
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,11 @@
2525
"test": "mocha --exit --timeout 20000"
2626
},
2727
"dependencies": {
28-
"@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
2928
"@astrojs/prism": "^1.0.0",
3029
"acorn": "^8.7.1",
31-
"acorn-jsx": "^5.3.2",
3230
"github-slugger": "^1.4.0",
3331
"hast-util-to-html": "^8.0.3",
3432
"import-meta-resolve": "^2.1.0",
35-
"mdast-util-from-markdown": "^1.2.0",
36-
"mdast-util-mdx-expression": "^1.2.1",
37-
"mdast-util-mdx-jsx": "^1.2.0",
38-
"micromark-extension-mdx-expression": "^1.0.3",
39-
"micromark-extension-mdx-md": "^1.0.0",
40-
"micromark-util-combine-extensions": "^1.0.0",
4133
"rehype-raw": "^6.1.1",
4234
"rehype-stringify": "^9.0.3",
4335
"remark-gfm": "^3.0.1",
@@ -46,7 +38,6 @@
4638
"remark-smartypants": "^2.0.0",
4739
"shiki": "^0.11.1",
4840
"unified": "^10.1.2",
49-
"unist-util-map": "^3.1.1",
5041
"unist-util-visit": "^4.1.0",
5142
"vfile": "^5.3.2"
5243
},
@@ -59,7 +50,6 @@
5950
"@types/unist": "^2.0.6",
6051
"astro-scripts": "workspace:*",
6152
"chai": "^4.3.6",
62-
"micromark-util-types": "^1.0.2",
6353
"mocha": "^9.2.2"
6454
}
6555
}

packages/markdown/remark/src/index.ts

+3-26
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ import type {
88
import { toRemarkInitializeAstroData } from './frontmatter-injection.js';
99
import { loadPlugins } from './load-plugins.js';
1010
import { rehypeHeadingIds } from './rehype-collect-headings.js';
11-
import rehypeEscape from './rehype-escape.js';
12-
import rehypeExpressions from './rehype-expressions.js';
13-
import rehypeIslands from './rehype-islands.js';
14-
import rehypeJsx from './rehype-jsx.js';
1511
import toRemarkContentRelImageError from './remark-content-rel-image-error.js';
16-
import remarkEscape from './remark-escape.js';
17-
import remarkMarkAndUnravel from './remark-mark-and-unravel.js';
18-
import remarkMdxish from './remark-mdxish.js';
1912
import remarkPrism from './remark-prism.js';
2013
import scopedStyles from './remark-scoped-styles.js';
2114
import remarkShiki from './remark-shiki.js';
22-
import remarkUnwrap from './remark-unwrap.js';
2315

2416
import rehypeRaw from 'rehype-raw';
2517
import rehypeStringify from 'rehype-stringify';
@@ -61,7 +53,6 @@ export async function renderMarkdown(
6153
remarkRehype = markdownConfigDefaults.remarkRehype,
6254
gfm = markdownConfigDefaults.gfm,
6355
smartypants = markdownConfigDefaults.smartypants,
64-
isAstroFlavoredMd = false,
6556
isExperimentalContentCollections = false,
6657
contentDir,
6758
frontmatter: userFrontmatter = {},
@@ -72,7 +63,7 @@ export async function renderMarkdown(
7263
let parser = unified()
7364
.use(markdown)
7465
.use(toRemarkInitializeAstroData({ userFrontmatter }))
75-
.use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
66+
.use([]);
7667

7768
if (gfm) {
7869
parser.use(remarkGfm);
@@ -109,15 +100,7 @@ export async function renderMarkdown(
109100
markdownToHtml as any,
110101
{
111102
allowDangerousHtml: true,
112-
passThrough: isAstroFlavoredMd
113-
? [
114-
'raw',
115-
'mdxFlowExpression',
116-
'mdxJsxFlowElement',
117-
'mdxJsxTextElement',
118-
'mdxTextExpression',
119-
]
120-
: [],
103+
passThrough: [],
121104
...remarkRehype,
122105
},
123106
],
@@ -127,13 +110,7 @@ export async function renderMarkdown(
127110
parser.use([[plugin, pluginOpts]]);
128111
});
129112

130-
parser
131-
.use(
132-
isAstroFlavoredMd
133-
? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeHeadingIds]
134-
: [rehypeHeadingIds, rehypeRaw]
135-
)
136-
.use(rehypeStringify, { allowDangerousHtml: true });
113+
parser.use([rehypeHeadingIds, rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
137114

138115
let vfile: MarkdownVFile;
139116
try {

packages/markdown/remark/src/mdast-util-mdxish.ts

-12
This file was deleted.

packages/markdown/remark/src/mdxjs.ts

-27
This file was deleted.

packages/markdown/remark/src/rehype-collect-headings.ts

+3-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
2121
const depth = Number.parseInt(level);
2222

2323
let text = '';
24-
let isJSX = false;
2524
visit(node, (child, __, parent) => {
2625
if (child.type === 'element' || parent == null) {
2726
return;
@@ -36,31 +35,17 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
3635
text += child.value;
3736
} else {
3837
text += child.value.replace(/\{/g, '${');
39-
isJSX = isJSX || child.value.includes('{');
4038
}
4139
}
4240
});
4341

4442
node.properties = node.properties || {};
4543
if (typeof node.properties.id !== 'string') {
46-
if (isJSX) {
47-
// HACK: serialized JSX from internal plugins, ignore these for slug
48-
const raw = toHtml(node.children, { allowDangerousHtml: true })
49-
.replace(/\n(<)/g, '<')
50-
.replace(/(>)\n/g, '>');
51-
// HACK: for ids that have JSX content, use $$slug helper to generate slug at runtime
52-
node.properties.id = `$$slug(\`${text}\`)`;
53-
(node as any).type = 'raw';
54-
(
55-
node as any
56-
).value = `<${node.tagName} id={${node.properties.id}}>${raw}</${node.tagName}>`;
57-
} else {
58-
let slug = slugger.slug(text);
44+
let slug = slugger.slug(text);
5945

60-
if (slug.endsWith('-')) slug = slug.slice(0, -1);
46+
if (slug.endsWith('-')) slug = slug.slice(0, -1);
6147

62-
node.properties.id = slug;
63-
}
48+
node.properties.id = slug;
6449
}
6550

6651
headings.push({ depth, slug: node.properties.id, text });

packages/markdown/remark/src/rehype-escape.ts

-22
This file was deleted.

packages/markdown/remark/src/rehype-expressions.ts

-18
This file was deleted.

packages/markdown/remark/src/rehype-islands.ts

-43
This file was deleted.

packages/markdown/remark/src/rehype-jsx.ts

-65
This file was deleted.

packages/markdown/remark/src/remark-escape.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)