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

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 +151 -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 6cabe659bf0ade09
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 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,7 +1,151 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
8
+
9
+ This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an `imageSrc` slug in your document frontmatter:
10
+
11
+ ```ts
12
+ export function remarkInjectSocialImagePlugin() {
13
+ return function (tree, file) {
14
+ const { frontmatter } = file.data.astro;
15
+ frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname;
16
+ };
17
+ }
18
+ ```
19
+
20
+ When using Content Collections, you can access this modified frontmatter using the `remarkPluginFrontmatter` property returned when rendering an entry.
21
+
22
+ **Migration instructions**
23
+
24
+ Plugin authors should now **check for user frontmatter when applying defaults.**
25
+
26
+ For example, say a remark plugin wants to apply a default `title` if none is present. Add a conditional to check if the property is present, and update if none exists:
27
+
28
+ ```diff
29
+ export function remarkInjectTitlePlugin() {
30
+ return function (tree, file) {
31
+ const { frontmatter } = file.data.astro;
32
+ + if (!frontmatter.title) {
33
+ frontmatter.title = 'Default title';
34
+ + }
35
+ }
36
+ }
37
+ ```
38
+
39
+ This differs from previous behavior, where a Markdown file's frontmatter would _always_ override frontmatter injected via remark or reype.
40
+
41
+ - [#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
42
+
43
+ - [#5684](https://github.com/withastro/astro/pull/5684) [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d) & [#5769](https://github.com/withastro/astro/pull/5769) [`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Refine Markdown and MDX configuration options for ease-of-use.
44
+
45
+ - **Markdown**
46
+
47
+ - **Replace the `extendDefaultPlugins` option** with a `gfm` boolean and a `smartypants` boolean. These are enabled by default, and can be disabled to remove GitHub-Flavored Markdown and SmartyPants.
48
+
49
+ - Ensure GitHub-Flavored Markdown and SmartyPants are applied whether or not custom `remarkPlugins` or `rehypePlugins` are configured. If you want to apply custom plugins _and_ remove Astro's default plugins, manually set `gfm: false` and `smartypants: false` in your config.
50
+
51
+ - **Migrate `extendDefaultPlugins` to `gfm` and `smartypants`**
52
+
53
+ You may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the `extendDefaultPlugins` option. This has now been split into 2 flags to disable each plugin individually:
54
+
55
+ - `markdown.gfm` to disable GitHub-Flavored Markdown
56
+ - `markdown.smartypants` to disable SmartyPants
57
+
58
+ ```diff
59
+ // astro.config.mjs
60
+ import { defineConfig } from 'astro/config';
61
+
62
+ export default defineConfig({
63
+ markdown: {
64
+ - extendDefaultPlugins: false,
65
+ + smartypants: false,
66
+ + gfm: false,
67
+ }
68
+ });
69
+ ```
70
+
71
+ Additionally, applying remark and rehype plugins **no longer disables** `gfm` and `smartypants`. You will need to opt-out manually by setting `gfm` and `smartypants` to `false`.
72
+
73
+ - **MDX**
74
+
75
+ - Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
76
+
77
+ - Simplify `extendPlugins` to an `extendMarkdownConfig` option. MDX options will default to their equivalent in your Markdown config. By setting `extendMarkdownConfig` to false, you can "eject" to set your own syntax highlighting, plugins, and more.
78
+
79
+ - **Migrate MDX's `extendPlugins` to `extendMarkdownConfig`**
80
+
81
+ You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 3 flags:
82
+
83
+ - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
84
+ - `gfm` (`true` by default) and `smartypants` (`true` by default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces the `extendPlugins: 'defaults'` option.
85
+
86
+ - [#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!
87
+
88
+ ```diff
89
+ import { defineConfig } from 'astro/config';
90
+
91
+ export default defineConfig({
92
+ - experimental: { contentCollections: true }
93
+ })
94
+
95
+ ```
96
+
97
+ - [#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
98
+
99
+ 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.
100
+
101
+
102
+ **Patch Changes**
103
+
104
+ - [#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
105
+
106
+ - Updated dependencies [[`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b), [`16dc36a87`](https://github.com/withastro/astro/commit/16dc36a870df47a4151a8ed2d91d0bd1bb812458), [`01f3f463b`](https://github.com/withastro/astro/commit/01f3f463bf2918b310d130a9fabbf3ee21d14029), [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144), [`05caf445d`](https://github.com/withastro/astro/commit/05caf445d4d2728f1010aeb2179a9e756c2fd17d), [`49ab4f231`](https://github.com/withastro/astro/commit/49ab4f231c23b34891c3ee86f4b92bf8d6d267a3), [`a342a486c`](https://github.com/withastro/astro/commit/a342a486c2831461e24e6c2f1ca8a9d3e15477b6), [`8fb28648f`](https://github.com/withastro/astro/commit/8fb28648f66629741cb976bfe34ccd9d8f55661e), [`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), [`ce5c5dbd4`](https://github.com/withastro/astro/commit/ce5c5dbd46afbe738b03600758bf5c35113de522), [`ec09bb664`](https://github.com/withastro/astro/commit/ec09bb6642064dbd7d2f3369afb090363ae18de2), [`665a2c222`](https://github.com/withastro/astro/commit/665a2c2225e42881f5a9550599e8f3fc1deea0b4), [`259a539d7`](https://github.com/withastro/astro/commit/259a539d7d70c783330c797794b15716921629cf), [`f7aa1ec25`](https://github.com/withastro/astro/commit/f7aa1ec25d1584f7abd421903fbef66b1c050e2a), [`4987d6f44`](https://github.com/withastro/astro/commit/4987d6f44cfd0d81d88f21f5c380503403dc1e6a), [`304823811`](https://github.com/withastro/astro/commit/304823811eddd8e72aa1d8e2d39b40ab5cda3565), [`302e0ef8f`](https://github.com/withastro/astro/commit/302e0ef8f5d5232e3348afe680e599f3e537b5c5), [`55cea0a9d`](https://github.com/withastro/astro/commit/55cea0a9d8c8df91a46590fc04a9ac28089b3432), [`dd56c1941`](https://github.com/withastro/astro/commit/dd56c19411b126439b8bc42d681b6fa8c06e8c61), [`9963c6e4d`](https://github.com/withastro/astro/commit/9963c6e4d50c392c3d1ac4492237020f15ccb1de), [`be901dc98`](https://github.com/withastro/astro/commit/be901dc98c4a7f6b5536540aa8f7ba5108e939a0), [`f6cf92b48`](https://github.com/withastro/astro/commit/f6cf92b48317a19a3840ad781b77d6d3cae143bb), [`e818cc046`](https://github.com/withastro/astro/commit/e818cc0466a942919ea3c41585e231c8c80cb3d0), [`8c100a6fe`](https://github.com/withastro/astro/commit/8c100a6fe6cc652c3799d1622e12c2c969f30510), [`116d8835c`](https://github.com/withastro/astro/commit/116d8835ca9e78f8b5e477ee5a3d737b69f80706), [`840412128`](https://github.com/withastro/astro/commit/840412128b00a04515156e92c314a929d6b94f6d), [`1f49cddf9`](https://github.com/withastro/astro/commit/1f49cddf9e9ffc651efc171b2cbde9fbe9e8709d), [`7325df412`](https://github.com/withastro/astro/commit/7325df412107fc0e65cd45c1b568fb686708f723), [`16c7d0bfd`](https://github.com/withastro/astro/commit/16c7d0bfd49d2b9bfae45385f506bcd642f9444a), [`a9c292026`](https://github.com/withastro/astro/commit/a9c2920264e36cc5dc05f4adc1912187979edb0d), [`2a5786419`](https://github.com/withastro/astro/commit/2a5786419599b8674473c699300172b9aacbae2e), [`4a1cabfe6`](https://github.com/withastro/astro/commit/4a1cabfe6b9ef8a6fbbcc0727a0dc6fa300cedaa), [`a8d3e7924`](https://github.com/withastro/astro/commit/a8d3e79246605d252dcddad159e358e2d79bd624), [`fa8c131f8`](https://github.com/withastro/astro/commit/fa8c131f88ef67d14c62f1c00c97ed74d43a80ac), [`64b8082e7`](https://github.com/withastro/astro/commit/64b8082e776b832f1433ed288e6f7888adb626d0), [`c4b0cb8bf`](https://github.com/withastro/astro/commit/c4b0cb8bf2b41887d9106440bb2e70d421a5f481), [`23dc9ea96`](https://github.com/withastro/astro/commit/23dc9ea96a10343852d965efd41fe6665294f1fb), [`63a6ceb38`](https://github.com/withastro/astro/commit/63a6ceb38d88331451dca64d0034c7c58e3d26f1), [`a3a7fc929`](https://github.com/withastro/astro/commit/a3a7fc9298e6d88abb4b7bee1e58f05fa9558cf1), [`52209ca2a`](https://github.com/withastro/astro/commit/52209ca2ad72a30854947dcb3a90ab4db0ac0a6f), [`5fd9208d4`](https://github.com/withastro/astro/commit/5fd9208d447f5ab8909a2188b6c2491a0debd49d), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b), [`899214298`](https://github.com/withastro/astro/commit/899214298cee5f0c975c7245e623c649e1842d73), [`3a00ecb3e`](https://github.com/withastro/astro/commit/3a00ecb3eb4bc44be758c064f2bde6e247e8a593), [`5eba34fcc`](https://github.com/withastro/astro/commit/5eba34fcc663def20bdf6e0daad02a6a5472776b), [`2303f9514`](https://github.com/withastro/astro/commit/2303f95142aa740c99213a098f82b99dd37d74a0), [`1ca81c16b`](https://github.com/withastro/astro/commit/1ca81c16b8b66236e092e6eb6ec3f73f5668421c), [`b66d7195c`](https://github.com/withastro/astro/commit/b66d7195c17a55ea0931bc3744888bd4f5f01ce6)]:
107
+ - astro@2.0.0
108
+ - @astrojs/prism@2.0.0
109
+
110
+ ## 2.0.0-beta.2
111
+
112
+ <details>
113
+ <summary>See changes in 2.0.0-beta.2</summary>
114
+
115
+ ### Major Changes
116
+
117
+ - [#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
118
+
119
+ - [#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!
120
+
121
+ ```diff
122
+ import { defineConfig } from 'astro/config';
123
+
124
+ export default defineConfig({
125
+ - experimental: { contentCollections: true }
126
+ })
127
+
128
+ ```
129
+
130
+ - [#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
131
+
132
+ 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.
133
+
134
+ ### Patch Changes
135
+
136
+ - [#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
137
+
138
+ - 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)]:
139
+ - astro@2.0.0-beta.2
140
+ - @astrojs/prism@2.0.0-beta.0
141
+
142
+ </details>
143
+
3
144
  ## 2.0.0-beta.1
4
145
 
146
+ <details>
147
+ <summary>See changes in 2.0.0-beta.1</summary>
148
+
5
149
  ### Minor Changes
6
150
 
7
151
  - [#5769](https://github.com/withastro/astro/pull/5769) [`93e633922`](https://github.com/withastro/astro/commit/93e633922c2e449df3bb2357b3683af1d3c0e07b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce a `smartypants` flag to opt-out of Astro's default SmartyPants plugin.
@@ -34,8 +178,13 @@
34
178
  });
35
179
  ```
36
180
 
181
+ </details>
182
+
37
183
  ## 2.0.0-beta.0
38
184
 
185
+ <details>
186
+ <summary>See changes in 2.0.0-beta.0</summary>
187
+
39
188
  ### Major Changes
40
189
 
41
190
  - [#5687](https://github.com/withastro/astro/pull/5687) [`e2019be6f`](https://github.com/withastro/astro/commit/e2019be6ffa46fa33d92cfd346f9ecbe51bb7144) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This means `data.astro.frontmatter` is now the _complete_ Markdown or MDX document's frontmatter, rather than an empty object.
@@ -134,6 +283,8 @@
134
283
  - `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
135
284
  - `gfm` (`true` by default) to toggle GitHub-Flavored Markdown in MDX. This replaces the `extendPlugins: 'defaults'` option.
136
285
 
286
+ </details>
287
+
137
288
  ## 1.2.0
138
289
 
139
290
  ### 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",
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"
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",
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",
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 */