@astrojs/markdown-remark 2.0.0-beta.1 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/CHANGELOG.md +29 -0
  3. package/dist/index.js +4 -24
  4. package/dist/rehype-collect-headings.js +4 -14
  5. package/dist/remark-content-rel-image-error.js +2 -0
  6. package/dist/remark-shiki.js +2 -2
  7. package/dist/types.d.ts +0 -3
  8. package/package.json +6 -15
  9. package/src/index.ts +4 -30
  10. package/src/rehype-collect-headings.ts +3 -19
  11. package/src/remark-content-rel-image-error.ts +2 -0
  12. package/src/remark-shiki.ts +2 -2
  13. package/src/types.ts +0 -3
  14. package/test/autolinking.test.js +10 -75
  15. package/test/entities.test.js +5 -14
  16. package/test/plugins.test.js +2 -0
  17. package/test/test-utils.js +3 -0
  18. package/dist/mdast-util-mdxish.d.ts +0 -2
  19. package/dist/mdast-util-mdxish.js +0 -14
  20. package/dist/mdxjs.d.ts +0 -3
  21. package/dist/mdxjs.js +0 -20
  22. package/dist/rehype-escape.d.ts +0 -2
  23. package/dist/rehype-escape.js +0 -21
  24. package/dist/rehype-expressions.d.ts +0 -1
  25. package/dist/rehype-expressions.js +0 -20
  26. package/dist/rehype-islands.d.ts +0 -1
  27. package/dist/rehype-islands.js +0 -27
  28. package/dist/rehype-jsx.d.ts +0 -2
  29. package/dist/rehype-jsx.js +0 -51
  30. package/dist/remark-escape.d.ts +0 -1
  31. package/dist/remark-escape.js +0 -13
  32. package/dist/remark-mark-and-unravel.d.ts +0 -17
  33. package/dist/remark-mark-and-unravel.js +0 -45
  34. package/dist/remark-mdxish.d.ts +0 -1
  35. package/dist/remark-mdxish.js +0 -53
  36. package/dist/remark-unwrap.d.ts +0 -1
  37. package/dist/remark-unwrap.js +0 -31
  38. package/src/mdast-util-mdxish.ts +0 -12
  39. package/src/mdxjs.ts +0 -27
  40. package/src/rehype-escape.ts +0 -22
  41. package/src/rehype-expressions.ts +0 -18
  42. package/src/rehype-islands.ts +0 -43
  43. package/src/rehype-jsx.ts +0 -65
  44. package/src/remark-escape.ts +0 -15
  45. package/src/remark-mark-and-unravel.ts +0 -72
  46. package/src/remark-mdxish.ts +0 -61
  47. package/src/remark-unwrap.ts +0 -44
  48. package/test/components.test.js +0 -78
  49. package/test/expressions.test.js +0 -125
  50. package/test/strictness.test.js +0 -98
@@ -1,5 +1,5 @@
1
- @astrojs/markdown-remark:build: cache hit, replaying output 9c178a3ea0572c76
1
+ @astrojs/markdown-remark:build: cache hit, replaying output 1c75f68e5ab1d40c
2
2
  @astrojs/markdown-remark:build: 
3
- @astrojs/markdown-remark:build: > @astrojs/markdown-remark@2.0.0-beta.1 build /home/runner/work/astro/astro/packages/markdown/remark
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@2.0.0-beta.2 build /home/runner/work/astro/astro/packages/markdown/remark
4
4
  @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
5
  @astrojs/markdown-remark:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - [#5785](https://github.com/withastro/astro/pull/5785) [`16107b6a1`](https://github.com/withastro/astro/commit/16107b6a10514ef1b563e585ec9add4b14f42b94) Thanks [@delucis](https://github.com/delucis)! - Drop support for legacy Astro-flavored Markdown
8
+
9
+ - [#5825](https://github.com/withastro/astro/pull/5825) [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Baseline the experimental `contentCollections` flag. You're free to remove this from your astro config!
10
+
11
+ ```diff
12
+ import { defineConfig } from 'astro/config';
13
+
14
+ export default defineConfig({
15
+ - experimental: { contentCollections: true }
16
+ })
17
+
18
+ ```
19
+
20
+ - [#5806](https://github.com/withastro/astro/pull/5806) [`7572f7402`](https://github.com/withastro/astro/commit/7572f7402238da37de748be58d678fedaf863b53) Thanks [@matthewp](https://github.com/matthewp)! - Make astro a peerDependency of integrations
21
+
22
+ This marks `astro` as a peerDependency of several packages that are already getting `major` version bumps. This is so we can more properly track the dependency between them and what version of Astro they are being used with.
23
+
24
+ ### Patch Changes
25
+
26
+ - [#5837](https://github.com/withastro/astro/pull/5837) [`12f65a4d5`](https://github.com/withastro/astro/commit/12f65a4d55e3fd2993c2f67b18794dd536280c69) Thanks [@giuseppelt](https://github.com/giuseppelt)! - fix shiki css class replace logic
27
+
28
+ - Updated dependencies [[`01f3f463b`](https://github.com/withastro/astro/commit/01f3f463bf2918b310d130a9fabbf3ee21d14029), [`1f92d64ea`](https://github.com/withastro/astro/commit/1f92d64ea35c03fec43aff64eaf704dc5a9eb30a), [`c2180746b`](https://github.com/withastro/astro/commit/c2180746b4f6d9ef1b6f86924f21f52cc6ab4e63), [`ae8a012a7`](https://github.com/withastro/astro/commit/ae8a012a7b6884a03c50494332ee37b4505c2c3b), [`cf2de5422`](https://github.com/withastro/astro/commit/cf2de5422c26bfdea4c75f76e57b57299ded3e3a), [`ec09bb664`](https://github.com/withastro/astro/commit/ec09bb6642064dbd7d2f3369afb090363ae18de2), [`665a2c222`](https://github.com/withastro/astro/commit/665a2c2225e42881f5a9550599e8f3fc1deea0b4), [`f7aa1ec25`](https://github.com/withastro/astro/commit/f7aa1ec25d1584f7abd421903fbef66b1c050e2a), [`302e0ef8f`](https://github.com/withastro/astro/commit/302e0ef8f5d5232e3348afe680e599f3e537b5c5), [`840412128`](https://github.com/withastro/astro/commit/840412128b00a04515156e92c314a929d6b94f6d), [`1f49cddf9`](https://github.com/withastro/astro/commit/1f49cddf9e9ffc651efc171b2cbde9fbe9e8709d), [`4a1cabfe6`](https://github.com/withastro/astro/commit/4a1cabfe6b9ef8a6fbbcc0727a0dc6fa300cedaa), [`c4b0cb8bf`](https://github.com/withastro/astro/commit/c4b0cb8bf2b41887d9106440bb2e70d421a5f481), [`23dc9ea96`](https://github.com/withastro/astro/commit/23dc9ea96a10343852d965efd41fe6665294f1fb), [`63a6ceb38`](https://github.com/withastro/astro/commit/63a6ceb38d88331451dca64d0034c7c58e3d26f1), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0)]:
29
+ - astro@2.0.0-beta.2
30
+ - @astrojs/prism@2.0.0-beta.0
31
+
3
32
  ## 2.0.0-beta.1
4
33
 
5
34
  ### Minor Changes
package/dist/index.js CHANGED
@@ -1,18 +1,10 @@
1
1
  import { toRemarkInitializeAstroData } from "./frontmatter-injection.js";
2
2
  import { loadPlugins } from "./load-plugins.js";
3
3
  import { rehypeHeadingIds } from "./rehype-collect-headings.js";
4
- import rehypeEscape from "./rehype-escape.js";
5
- import rehypeExpressions from "./rehype-expressions.js";
6
- import rehypeIslands from "./rehype-islands.js";
7
- import rehypeJsx from "./rehype-jsx.js";
8
4
  import toRemarkContentRelImageError from "./remark-content-rel-image-error.js";
9
- import remarkEscape from "./remark-escape.js";
10
- import remarkMarkAndUnravel from "./remark-mark-and-unravel.js";
11
- import remarkMdxish from "./remark-mdxish.js";
12
5
  import remarkPrism from "./remark-prism.js";
13
6
  import scopedStyles from "./remark-scoped-styles.js";
14
7
  import remarkShiki from "./remark-shiki.js";
15
- import remarkUnwrap from "./remark-unwrap.js";
16
8
  import rehypeRaw from "rehype-raw";
17
9
  import rehypeStringify from "rehype-stringify";
18
10
  import remarkGfm from "remark-gfm";
@@ -47,14 +39,12 @@ async function renderMarkdown(content, opts) {
47
39
  remarkRehype = markdownConfigDefaults.remarkRehype,
48
40
  gfm = markdownConfigDefaults.gfm,
49
41
  smartypants = markdownConfigDefaults.smartypants,
50
- isAstroFlavoredMd = false,
51
- isExperimentalContentCollections = false,
52
42
  contentDir,
53
43
  frontmatter: userFrontmatter = {}
54
44
  } = opts;
55
45
  const input = new VFile({ value: content, path: fileURL });
56
46
  const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
57
- let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
47
+ let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use([]);
58
48
  if (gfm) {
59
49
  parser.use(remarkGfm);
60
50
  }
@@ -74,21 +64,13 @@ async function renderMarkdown(content, opts) {
74
64
  } else if (syntaxHighlight === "prism") {
75
65
  parser.use([remarkPrism(scopedClassName)]);
76
66
  }
77
- if (isExperimentalContentCollections) {
78
- parser.use([toRemarkContentRelImageError({ contentDir })]);
79
- }
67
+ parser.use([toRemarkContentRelImageError({ contentDir })]);
80
68
  parser.use([
81
69
  [
82
70
  markdownToHtml,
83
71
  {
84
72
  allowDangerousHtml: true,
85
- passThrough: isAstroFlavoredMd ? [
86
- "raw",
87
- "mdxFlowExpression",
88
- "mdxJsxFlowElement",
89
- "mdxJsxTextElement",
90
- "mdxTextExpression"
91
- ] : [],
73
+ passThrough: [],
92
74
  ...remarkRehype
93
75
  }
94
76
  ]
@@ -96,9 +78,7 @@ async function renderMarkdown(content, opts) {
96
78
  loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
97
79
  parser.use([[plugin, pluginOpts]]);
98
80
  });
99
- parser.use(
100
- isAstroFlavoredMd ? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeHeadingIds] : [rehypeHeadingIds, rehypeRaw]
101
- ).use(rehypeStringify, { allowDangerousHtml: true });
81
+ parser.use([rehypeHeadingIds, rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
102
82
  let vfile;
103
83
  try {
104
84
  vfile = await parser.process(input);
@@ -1,5 +1,4 @@
1
1
  import Slugger from "github-slugger";
2
- import { toHtml } from "hast-util-to-html";
3
2
  import { visit } from "unist-util-visit";
4
3
  const rawNodeTypes = /* @__PURE__ */ new Set(["text", "raw", "mdxTextExpression"]);
5
4
  const codeTagNames = /* @__PURE__ */ new Set(["code", "pre"]);
@@ -19,7 +18,6 @@ function rehypeHeadingIds() {
19
18
  return;
20
19
  const depth = Number.parseInt(level);
21
20
  let text = "";
22
- let isJSX = false;
23
21
  visit(node, (child, __, parent) => {
24
22
  if (child.type === "element" || parent == null) {
25
23
  return;
@@ -34,23 +32,15 @@ function rehypeHeadingIds() {
34
32
  text += child.value;
35
33
  } else {
36
34
  text += child.value.replace(/\{/g, "${");
37
- isJSX = isJSX || child.value.includes("{");
38
35
  }
39
36
  }
40
37
  });
41
38
  node.properties = node.properties || {};
42
39
  if (typeof node.properties.id !== "string") {
43
- if (isJSX) {
44
- const raw = toHtml(node.children, { allowDangerousHtml: true }).replace(/\n(<)/g, "<").replace(/(>)\n/g, ">");
45
- node.properties.id = `$$slug(\`${text}\`)`;
46
- node.type = "raw";
47
- node.value = `<${node.tagName} id={${node.properties.id}}>${raw}</${node.tagName}>`;
48
- } else {
49
- let slug = slugger.slug(text);
50
- if (slug.endsWith("-"))
51
- slug = slug.slice(0, -1);
52
- node.properties.id = slug;
53
- }
40
+ let slug = slugger.slug(text);
41
+ if (slug.endsWith("-"))
42
+ slug = slug.slice(0, -1);
43
+ node.properties.id = slug;
54
44
  }
55
45
  headings.push({ depth, slug: node.properties.id, text });
56
46
  });
@@ -3,6 +3,8 @@ import { pathToFileURL } from "url";
3
3
  function toRemarkContentRelImageError({ contentDir }) {
4
4
  return function remarkContentRelImageError() {
5
5
  return (tree, vfile) => {
6
+ if (typeof (vfile == null ? void 0 : vfile.path) !== "string")
7
+ return;
6
8
  const isContentFile = pathToFileURL(vfile.path).href.startsWith(contentDir.href);
7
9
  if (!isContentFile)
8
10
  return;
@@ -43,8 +43,8 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false },
43
43
  }
44
44
  let html = highlighter.codeToHtml(node.value, { lang });
45
45
  html = html.replace(
46
- '<pre class="shiki"',
47
- `<pre is:raw class="astro-code${scopedClassName ? " " + scopedClassName : ""}"`
46
+ /<pre class="(.*?)shiki(.*?)"/,
47
+ `<pre is:raw class="$1astro-code$2${scopedClassName ? " " + scopedClassName : ""}"`
48
48
  );
49
49
  if (node.lang === "diff") {
50
50
  html = html.replace(
package/dist/types.d.ts CHANGED
@@ -38,9 +38,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
38
38
  $?: {
39
39
  scopedClassName: string | null;
40
40
  };
41
- isAstroFlavoredMd?: boolean;
42
- /** Used to prevent relative image imports from `src/content/` */
43
- isExperimentalContentCollections?: boolean;
44
41
  /** Used to prevent relative image imports from `src/content/` */
45
42
  contentDir: URL;
46
43
  /** Used for frontmatter injection plugins */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -16,20 +16,13 @@
16
16
  ".": "./dist/index.js",
17
17
  "./dist/internal.js": "./dist/internal.js"
18
18
  },
19
+ "peerDependencies": {
20
+ "astro": "^2.0.0-beta.2"
21
+ },
19
22
  "dependencies": {
20
- "@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
21
- "@astrojs/prism": "^1.0.0",
22
- "acorn": "^8.7.1",
23
- "acorn-jsx": "^5.3.2",
23
+ "@astrojs/prism": "^2.0.0-beta.0",
24
24
  "github-slugger": "^1.4.0",
25
- "hast-util-to-html": "^8.0.3",
26
25
  "import-meta-resolve": "^2.1.0",
27
- "mdast-util-from-markdown": "^1.2.0",
28
- "mdast-util-mdx-expression": "^1.2.1",
29
- "mdast-util-mdx-jsx": "^1.2.0",
30
- "micromark-extension-mdx-expression": "^1.0.3",
31
- "micromark-extension-mdx-md": "^1.0.0",
32
- "micromark-util-combine-extensions": "^1.0.0",
33
26
  "rehype-raw": "^6.1.1",
34
27
  "rehype-stringify": "^9.0.3",
35
28
  "remark-gfm": "^3.0.1",
@@ -38,7 +31,6 @@
38
31
  "remark-smartypants": "^2.0.0",
39
32
  "shiki": "^0.11.1",
40
33
  "unified": "^10.1.2",
41
- "unist-util-map": "^3.1.1",
42
34
  "unist-util-visit": "^4.1.0",
43
35
  "vfile": "^5.3.2"
44
36
  },
@@ -49,9 +41,8 @@
49
41
  "@types/mdast": "^3.0.10",
50
42
  "@types/mocha": "^9.1.1",
51
43
  "@types/unist": "^2.0.6",
52
- "astro-scripts": "0.0.9",
44
+ "astro-scripts": "0.0.10-beta.0",
53
45
  "chai": "^4.3.6",
54
- "micromark-util-types": "^1.0.2",
55
46
  "mocha": "^9.2.2"
56
47
  },
57
48
  "scripts": {
package/src/index.ts CHANGED
@@ -8,18 +8,10 @@ import type {
8
8
  import { toRemarkInitializeAstroData } from './frontmatter-injection.js';
9
9
  import { loadPlugins } from './load-plugins.js';
10
10
  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';
15
11
  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';
19
12
  import remarkPrism from './remark-prism.js';
20
13
  import scopedStyles from './remark-scoped-styles.js';
21
14
  import remarkShiki from './remark-shiki.js';
22
- import remarkUnwrap from './remark-unwrap.js';
23
15
 
24
16
  import rehypeRaw from 'rehype-raw';
25
17
  import rehypeStringify from 'rehype-stringify';
@@ -61,8 +53,6 @@ export async function renderMarkdown(
61
53
  remarkRehype = markdownConfigDefaults.remarkRehype,
62
54
  gfm = markdownConfigDefaults.gfm,
63
55
  smartypants = markdownConfigDefaults.smartypants,
64
- isAstroFlavoredMd = false,
65
- isExperimentalContentCollections = false,
66
56
  contentDir,
67
57
  frontmatter: userFrontmatter = {},
68
58
  } = opts;
@@ -72,7 +62,7 @@ export async function renderMarkdown(
72
62
  let parser = unified()
73
63
  .use(markdown)
74
64
  .use(toRemarkInitializeAstroData({ userFrontmatter }))
75
- .use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
65
+ .use([]);
76
66
 
77
67
  if (gfm) {
78
68
  parser.use(remarkGfm);
@@ -100,24 +90,14 @@ export async function renderMarkdown(
100
90
  }
101
91
 
102
92
  // Apply later in case user plugins resolve relative image paths
103
- if (isExperimentalContentCollections) {
104
- parser.use([toRemarkContentRelImageError({ contentDir })]);
105
- }
93
+ parser.use([toRemarkContentRelImageError({ contentDir })]);
106
94
 
107
95
  parser.use([
108
96
  [
109
97
  markdownToHtml as any,
110
98
  {
111
99
  allowDangerousHtml: true,
112
- passThrough: isAstroFlavoredMd
113
- ? [
114
- 'raw',
115
- 'mdxFlowExpression',
116
- 'mdxJsxFlowElement',
117
- 'mdxJsxTextElement',
118
- 'mdxTextExpression',
119
- ]
120
- : [],
100
+ passThrough: [],
121
101
  ...remarkRehype,
122
102
  },
123
103
  ],
@@ -127,13 +107,7 @@ export async function renderMarkdown(
127
107
  parser.use([[plugin, pluginOpts]]);
128
108
  });
129
109
 
130
- parser
131
- .use(
132
- isAstroFlavoredMd
133
- ? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeHeadingIds]
134
- : [rehypeHeadingIds, rehypeRaw]
135
- )
136
- .use(rehypeStringify, { allowDangerousHtml: true });
110
+ parser.use([rehypeHeadingIds, rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
137
111
 
138
112
  let vfile: MarkdownVFile;
139
113
  try {
@@ -1,5 +1,4 @@
1
1
  import Slugger from 'github-slugger';
2
- import { toHtml } from 'hast-util-to-html';
3
2
  import { visit } from 'unist-util-visit';
4
3
 
5
4
  import type { MarkdownHeading, MarkdownVFile, RehypePlugin } from './types.js';
@@ -21,7 +20,6 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
21
20
  const depth = Number.parseInt(level);
22
21
 
23
22
  let text = '';
24
- let isJSX = false;
25
23
  visit(node, (child, __, parent) => {
26
24
  if (child.type === 'element' || parent == null) {
27
25
  return;
@@ -36,31 +34,17 @@ export function rehypeHeadingIds(): ReturnType<RehypePlugin> {
36
34
  text += child.value;
37
35
  } else {
38
36
  text += child.value.replace(/\{/g, '${');
39
- isJSX = isJSX || child.value.includes('{');
40
37
  }
41
38
  }
42
39
  });
43
40
 
44
41
  node.properties = node.properties || {};
45
42
  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);
43
+ let slug = slugger.slug(text);
59
44
 
60
- if (slug.endsWith('-')) slug = slug.slice(0, -1);
45
+ if (slug.endsWith('-')) slug = slug.slice(0, -1);
61
46
 
62
- node.properties.id = slug;
63
- }
47
+ node.properties.id = slug;
64
48
  }
65
49
 
66
50
  headings.push({ depth, slug: node.properties.id, text });
@@ -10,6 +10,8 @@ import type { VFile } from 'vfile';
10
10
  export default function toRemarkContentRelImageError({ contentDir }: { contentDir: URL }) {
11
11
  return function remarkContentRelImageError() {
12
12
  return (tree: any, vfile: VFile) => {
13
+ if (typeof vfile?.path !== 'string') return;
14
+
13
15
  const isContentFile = pathToFileURL(vfile.path).href.startsWith(contentDir.href);
14
16
  if (!isContentFile) return;
15
17
 
@@ -70,8 +70,8 @@ const remarkShiki = async (
70
70
 
71
71
  // Replace "shiki" class naming with "astro" and add "is:raw".
72
72
  html = html.replace(
73
- '<pre class="shiki"',
74
- `<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`
73
+ /<pre class="(.*?)shiki(.*?)"/,
74
+ `<pre is:raw class="$1astro-code$2${scopedClassName ? ' ' + scopedClassName : ''}"`
75
75
  );
76
76
  // Add "user-select: none;" for "+"/"-" diff symbols
77
77
  if (node.lang === 'diff') {
package/src/types.ts CHANGED
@@ -58,9 +58,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
58
58
  $?: {
59
59
  scopedClassName: string | null;
60
60
  };
61
- isAstroFlavoredMd?: boolean;
62
- /** Used to prevent relative image imports from `src/content/` */
63
- isExperimentalContentCollections?: boolean;
64
61
  /** Used to prevent relative image imports from `src/content/` */
65
62
  contentDir: URL;
66
63
  /** Used for frontmatter injection plugins */
@@ -1,10 +1,14 @@
1
1
  import { renderMarkdown } from '../dist/index.js';
2
2
  import chai from 'chai';
3
+ import { mockRenderMarkdownParams } from './test-utils.js';
3
4
 
4
5
  describe('autolinking', () => {
5
6
  describe('plain md', () => {
6
7
  it('autolinks URLs starting with a protocol in plain text', async () => {
7
- const { code } = await renderMarkdown(`See https://example.com for more.`, {});
8
+ const { code } = await renderMarkdown(
9
+ `See https://example.com for more.`,
10
+ mockRenderMarkdownParams
11
+ );
8
12
 
9
13
  chai
10
14
  .expect(code.replace(/\n/g, ''))
@@ -12,7 +16,10 @@ describe('autolinking', () => {
12
16
  });
13
17
 
14
18
  it('autolinks URLs starting with "www." in plain text', async () => {
15
- const { code } = await renderMarkdown(`See www.example.com for more.`, {});
19
+ const { code } = await renderMarkdown(
20
+ `See www.example.com for more.`,
21
+ mockRenderMarkdownParams
22
+ );
16
23
 
17
24
  chai
18
25
  .expect(code.trim())
@@ -22,7 +29,7 @@ describe('autolinking', () => {
22
29
  it('does not autolink URLs in code blocks', async () => {
23
30
  const { code } = await renderMarkdown(
24
31
  'See `https://example.com` or `www.example.com` for more.',
25
- {}
32
+ mockRenderMarkdownParams
26
33
  );
27
34
 
28
35
  chai
@@ -33,76 +40,4 @@ describe('autolinking', () => {
33
40
  );
34
41
  });
35
42
  });
36
-
37
- describe('astro-flavored md', () => {
38
- const renderAstroMd = (text) => renderMarkdown(text, { isAstroFlavoredMd: true });
39
-
40
- it('does not autolink URLs in code blocks', async () => {
41
- const { code } = await renderAstroMd(
42
- 'See `https://example.com` or `www.example.com` for more.',
43
- {}
44
- );
45
-
46
- chai
47
- .expect(code.trim())
48
- .to.equal(
49
- `<p>See <code is:raw>https://example.com</code> or ` +
50
- `<code is:raw>www.example.com</code> for more.</p>`
51
- );
52
- });
53
-
54
- it('does not autolink URLs in fenced code blocks', async () => {
55
- const { code } = await renderAstroMd(
56
- 'Example:\n```\nGo to https://example.com or www.example.com now.\n```'
57
- );
58
-
59
- chai
60
- .expect(code)
61
- .to.contain(`<pre is:raw`)
62
- .to.contain(`Go to https://example.com or www.example.com now.`);
63
- });
64
-
65
- it('does not autolink URLs starting with a protocol when nested inside links', async () => {
66
- const { code } = await renderAstroMd(
67
- `See [http://example.com](http://example.com) or ` +
68
- `<a test href="https://example.com">https://example.com</a>`
69
- );
70
-
71
- chai
72
- .expect(code.replace(/\n/g, ''))
73
- .to.equal(
74
- `<p>See <a href="http://example.com">http://example.com</a> or ` +
75
- `<a test href="https://example.com">https://example.com</a></p>`
76
- );
77
- });
78
-
79
- it('does not autolink URLs starting with "www." when nested inside links', async () => {
80
- const { code } = await renderAstroMd(
81
- `See [www.example.com](https://www.example.com) or ` +
82
- `<a test href="https://www.example.com">www.example.com</a>`
83
- );
84
-
85
- chai
86
- .expect(code.replace(/\n/g, ''))
87
- .to.equal(
88
- `<p>See <a href="https://www.example.com">www.example.com</a> or ` +
89
- `<a test href="https://www.example.com">www.example.com</a></p>`
90
- );
91
- });
92
-
93
- it('does not autolink URLs when nested several layers deep inside links', async () => {
94
- const { code } = await renderAstroMd(
95
- `<a href="https://www.example.com">**Visit _our www.example.com or ` +
96
- `http://localhost pages_ for more!**</a>`
97
- );
98
-
99
- chai
100
- .expect(code.replace(/\n/g, ''))
101
- .to.equal(
102
- `<a href="https://www.example.com"><strong>` +
103
- `Visit <em>our www.example.com or http://localhost pages</em> for more!` +
104
- `</strong></a>`
105
- );
106
- });
107
- });
108
43
  });
@@ -1,23 +1,14 @@
1
1
  import { renderMarkdown } from '../dist/index.js';
2
2
  import { expect } from 'chai';
3
+ import { mockRenderMarkdownParams } from './test-utils.js';
3
4
 
4
5
  describe('entities', () => {
5
6
  it('should not unescape entities in regular Markdown', async () => {
6
- const { code } = await renderMarkdown(`&lt;i&gt;This should NOT be italic&lt;/i&gt;`, {
7
- isAstroFlavoredMd: false,
8
- });
7
+ const { code } = await renderMarkdown(
8
+ `&lt;i&gt;This should NOT be italic&lt;/i&gt;`,
9
+ mockRenderMarkdownParams
10
+ );
9
11
 
10
12
  expect(code).to.equal(`<p>&#x3C;i>This should NOT be italic&#x3C;/i></p>`);
11
13
  });
12
-
13
- it('should not escape entities in code blocks twice in Astro-flavored markdown', async () => {
14
- const { code } = await renderMarkdown(`\`\`\`astro\n<h1>{x && x.name || ''}!</h1>\n\`\`\``, {
15
- isAstroFlavoredMd: true,
16
- syntaxHighlight: false,
17
- });
18
-
19
- expect(code).to.equal(
20
- `<pre is:raw><code class="language-astro">&lt;h1&gt;{x &amp;&amp; x.name || ''}!&lt;/h1&gt;\n</code></pre>`
21
- );
22
- });
23
14
  });
@@ -1,4 +1,5 @@
1
1
  import { renderMarkdown } from '../dist/index.js';
2
+ import { mockRenderMarkdownParams } from './test-utils.js';
2
3
  import chai from 'chai';
3
4
 
4
5
  import { fileURLToPath } from 'node:url';
@@ -8,6 +9,7 @@ describe('plugins', () => {
8
9
  it('should be able to get file path when passing fileURL', async () => {
9
10
  let context;
10
11
  await renderMarkdown(`test`, {
12
+ ...mockRenderMarkdownParams,
11
13
  fileURL: new URL('virtual.md', import.meta.url),
12
14
  remarkPlugins: [
13
15
  function () {
@@ -0,0 +1,3 @@
1
+ export const mockRenderMarkdownParams = {
2
+ contentDir: new URL('file:///src/content/'),
3
+ };
@@ -1,2 +0,0 @@
1
- export declare function mdxFromMarkdown(): any;
2
- export declare function mdxToMarkdown(): any;
@@ -1,14 +0,0 @@
1
- import { mdxExpressionFromMarkdown, mdxExpressionToMarkdown } from "mdast-util-mdx-expression";
2
- import { mdxJsxFromMarkdown, mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
3
- function mdxFromMarkdown() {
4
- return [mdxExpressionFromMarkdown, mdxJsxFromMarkdown];
5
- }
6
- function mdxToMarkdown() {
7
- return {
8
- extensions: [mdxExpressionToMarkdown, mdxJsxToMarkdown]
9
- };
10
- }
11
- export {
12
- mdxFromMarkdown,
13
- mdxToMarkdown
14
- };
package/dist/mdxjs.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Options } from 'micromark-extension-mdx-expression';
2
- import type { Extension } from 'micromark-util-types';
3
- export declare function mdxjs(options: Options): Extension;
package/dist/mdxjs.js DELETED
@@ -1,20 +0,0 @@
1
- import { mdxJsx } from "@astrojs/micromark-extension-mdx-jsx";
2
- import { Parser } from "acorn";
3
- import acornJsx from "acorn-jsx";
4
- import { mdxExpression } from "micromark-extension-mdx-expression";
5
- import { mdxMd } from "micromark-extension-mdx-md";
6
- import { combineExtensions } from "micromark-util-combine-extensions";
7
- function mdxjs(options) {
8
- const settings = Object.assign(
9
- {
10
- acorn: Parser.extend(acornJsx()),
11
- acornOptions: { ecmaVersion: 2020, sourceType: "module" },
12
- addResult: true
13
- },
14
- options
15
- );
16
- return combineExtensions([mdxExpression(settings), mdxJsx(settings), mdxMd]);
17
- }
18
- export {
19
- mdxjs
20
- };
@@ -1,2 +0,0 @@
1
- export declare function escapeEntities(value: string): string;
2
- export default function rehypeEscape(): any;
@@ -1,21 +0,0 @@
1
- import { SKIP, visit } from "unist-util-visit";
2
- function escapeEntities(value) {
3
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
4
- }
5
- function rehypeEscape() {
6
- return function(node) {
7
- return visit(node, "element", (el) => {
8
- if (el.tagName === "code" || el.tagName === "pre") {
9
- el.properties["is:raw"] = true;
10
- visit(el, "raw", (raw) => {
11
- raw.value = escapeEntities(raw.value);
12
- });
13
- return SKIP;
14
- }
15
- });
16
- };
17
- }
18
- export {
19
- rehypeEscape as default,
20
- escapeEntities
21
- };
@@ -1 +0,0 @@
1
- export default function rehypeExpressions(): any;