@astrojs/mdx 0.15.0 → 0.15.1
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.
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
1
|
+
[34m@astrojs/mdx:build: [0mcache hit, replaying output [2m86781ef119fbfda9[0m
|
|
2
|
+
[34m@astrojs/mdx:build: [0m
|
|
3
|
+
[34m@astrojs/mdx:build: [0m> @astrojs/mdx@0.15.1 build /home/runner/work/astro/astro/packages/integrations/mdx
|
|
4
|
+
[34m@astrojs/mdx:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[34m@astrojs/mdx:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @astrojs/mdx
|
|
2
2
|
|
|
3
|
+
## 0.15.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5978](https://github.com/withastro/astro/pull/5978) [`7abb1e905`](https://github.com/withastro/astro/commit/7abb1e9056c4b4fd0abfced347df32a41cdfbf28) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fix MDX heading IDs generation when using a frontmatter reference
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`7abb1e905`](https://github.com/withastro/astro/commit/7abb1e9056c4b4fd0abfced347df32a41cdfbf28)]:
|
|
10
|
+
- @astrojs/markdown-remark@2.0.1
|
|
11
|
+
|
|
3
12
|
## 0.15.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -8,46 +17,44 @@
|
|
|
8
17
|
|
|
9
18
|
- **Markdown**
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
- **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.
|
|
21
|
+
|
|
22
|
+
- 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.
|
|
14
23
|
|
|
15
24
|
- **Migrate `extendDefaultPlugins` to `gfm` and `smartypants`**
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
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:
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
- `markdown.gfm` to disable GitHub-Flavored Markdown
|
|
29
|
+
- `markdown.smartypants` to disable SmartyPants
|
|
21
30
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
```diff
|
|
32
|
+
// astro.config.mjs
|
|
33
|
+
import { defineConfig } from 'astro/config';
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
markdown: {
|
|
37
|
+
- extendDefaultPlugins: false,
|
|
38
|
+
+ smartypants: false,
|
|
39
|
+
+ gfm: false,
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
```
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
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`.
|
|
36
45
|
|
|
37
46
|
- **MDX**
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
- Support _all_ Markdown configuration options (except `drafts`) from your MDX integration config. This includes `syntaxHighlighting` and `shikiConfig` options to further customize the MDX renderer.
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
- 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.
|
|
42
51
|
|
|
43
52
|
- **Migrate MDX's `extendPlugins` to `extendMarkdownConfig`**
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
|
|
48
|
-
- `gfm` (`true` by default) and `smartypants` (`true` by default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces the `extendPlugins: 'defaults'` option.
|
|
49
|
-
|
|
54
|
+
You may have used the `extendPlugins` option to manage plugin defaults in MDX. This has been replaced by 3 flags:
|
|
50
55
|
|
|
56
|
+
- `extendMarkdownConfig` (`true` by default) to toggle Markdown config inheritance. This replaces the `extendPlugins: 'markdown'` option.
|
|
57
|
+
- `gfm` (`true` by default) and `smartypants` (`true` by default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces the `extendPlugins: 'defaults'` option.
|
|
51
58
|
|
|
52
59
|
- [#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.
|
|
53
60
|
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ You can configure how your MDX is rendered with the following options:
|
|
|
89
89
|
All [`markdown` configuration options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) except `drafts` can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config ([see the `extendMarkdownConfig` option](#extendmarkdownconfig) to modify this).
|
|
90
90
|
|
|
91
91
|
:::note
|
|
92
|
-
There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.build/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be
|
|
92
|
+
There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.build/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be overridden for MDX files specifically.
|
|
93
93
|
:::
|
|
94
94
|
|
|
95
95
|
```ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Use MDX within Astro",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@astrojs/markdown-remark": "^2.0.
|
|
26
|
+
"@astrojs/markdown-remark": "^2.0.1",
|
|
27
27
|
"@astrojs/prism": "^2.0.0",
|
|
28
28
|
"@mdx-js/mdx": "^2.1.2",
|
|
29
29
|
"@mdx-js/rollup": "^2.1.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@types/mdast": "^3.0.10",
|
|
49
49
|
"@types/mocha": "^9.1.1",
|
|
50
50
|
"@types/yargs-parser": "^21.0.0",
|
|
51
|
-
"astro": "2.0.
|
|
51
|
+
"astro": "2.0.2",
|
|
52
52
|
"astro-scripts": "0.0.10",
|
|
53
53
|
"chai": "^4.3.6",
|
|
54
54
|
"cheerio": "^1.0.0-rc.11",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The Frontmatter Title
|
|
3
|
+
keywords: [Keyword 1, Keyword 2, Keyword 3]
|
|
4
|
+
tags:
|
|
5
|
+
- Tag 1
|
|
6
|
+
- Tag 2
|
|
7
|
+
- Tag 3
|
|
8
|
+
items:
|
|
9
|
+
- value: Item 1
|
|
10
|
+
- value: Item 2
|
|
11
|
+
- value: Item 3
|
|
12
|
+
nested_items:
|
|
13
|
+
nested:
|
|
14
|
+
- value: Nested Item 1
|
|
15
|
+
- value: Nested Item 2
|
|
16
|
+
- value: Nested Item 3
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# {frontmatter.title}
|
|
20
|
+
|
|
21
|
+
This ID should be the frontmatter title.
|
|
22
|
+
|
|
23
|
+
## frontmatter.title
|
|
24
|
+
|
|
25
|
+
The ID should not be the frontmatter title.
|
|
26
|
+
|
|
27
|
+
### {frontmatter.keywords[1]}
|
|
28
|
+
|
|
29
|
+
The ID should be the frontmatter keyword #2.
|
|
30
|
+
|
|
31
|
+
### {frontmatter.tags[0]}
|
|
32
|
+
|
|
33
|
+
The ID should be the frontmatter tag #1.
|
|
34
|
+
|
|
35
|
+
#### {frontmatter.items[1].value}
|
|
36
|
+
|
|
37
|
+
The ID should be the frontmatter item #2.
|
|
38
|
+
|
|
39
|
+
##### {frontmatter.nested_items.nested[2].value}
|
|
40
|
+
|
|
41
|
+
The ID should be the frontmatter nested item #3.
|
|
42
|
+
|
|
43
|
+
###### {frontmatter.unknown}
|
|
44
|
+
|
|
45
|
+
This ID should not reference the frontmatter.
|
|
@@ -149,3 +149,46 @@ describe('MDX heading IDs can be injected before user plugins', () => {
|
|
|
149
149
|
expect(h1?.id).to.equal('heading-test');
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
|
+
|
|
153
|
+
describe('MDX headings with frontmatter', () => {
|
|
154
|
+
let fixture;
|
|
155
|
+
|
|
156
|
+
before(async () => {
|
|
157
|
+
fixture = await loadFixture({
|
|
158
|
+
root: new URL('./fixtures/mdx-get-headings/', import.meta.url),
|
|
159
|
+
integrations: [mdx()],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await fixture.build();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('adds anchor IDs to headings', async () => {
|
|
166
|
+
const html = await fixture.readFile('/test-with-frontmatter/index.html');
|
|
167
|
+
const { document } = parseHTML(html);
|
|
168
|
+
|
|
169
|
+
const h3Ids = document.querySelectorAll('h3').map((el) => el?.id);
|
|
170
|
+
|
|
171
|
+
expect(document.querySelector('h1').id).to.equal('the-frontmatter-title');
|
|
172
|
+
expect(document.querySelector('h2').id).to.equal('frontmattertitle');
|
|
173
|
+
expect(h3Ids).to.contain('keyword-2');
|
|
174
|
+
expect(h3Ids).to.contain('tag-1');
|
|
175
|
+
expect(document.querySelector('h4').id).to.equal('item-2');
|
|
176
|
+
expect(document.querySelector('h5').id).to.equal('nested-item-3');
|
|
177
|
+
expect(document.querySelector('h6').id).to.equal('frontmatterunknown');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('generates correct getHeadings() export', async () => {
|
|
181
|
+
const { headingsByPage } = JSON.parse(await fixture.readFile('/pages.json'));
|
|
182
|
+
expect(JSON.stringify(headingsByPage['./test-with-frontmatter.mdx'])).to.equal(
|
|
183
|
+
JSON.stringify([
|
|
184
|
+
{ depth: 1, slug: 'the-frontmatter-title', text: 'The Frontmatter Title' },
|
|
185
|
+
{ depth: 2, slug: 'frontmattertitle', text: 'frontmatter.title' },
|
|
186
|
+
{ depth: 3, slug: 'keyword-2', text: 'Keyword 2' },
|
|
187
|
+
{ depth: 3, slug: 'tag-1', text: 'Tag 1' },
|
|
188
|
+
{ depth: 4, slug: 'item-2', text: 'Item 2' },
|
|
189
|
+
{ depth: 5, slug: 'nested-item-3', text: 'Nested Item 3' },
|
|
190
|
+
{ depth: 6, slug: 'frontmatterunknown', text: 'frontmatter.unknown' },
|
|
191
|
+
])
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
});
|