@astrojs/mdx 0.10.1 → 0.10.3
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 +5 -0
- package/CHANGELOG.md +20 -0
- package/README.md +48 -0
- package/dist/astro-data-utils.js +2 -0
- package/dist/remark-shiki.js +16 -5
- package/package.json +3 -3
- package/src/astro-data-utils.ts +2 -0
- package/src/remark-shiki.ts +16 -6
- package/test/fixtures/mdx-frontmatter/src/layouts/Base.astro +4 -0
- package/test/mdx-frontmatter.test.js +5 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[35m@astrojs/mdx:build: [0mcache hit, replaying output [2mce9fa72396235d9a[0m
|
|
2
|
+
[35m@astrojs/mdx:build: [0m
|
|
3
|
+
[35m@astrojs/mdx:build: [0m> @astrojs/mdx@0.10.3 build /home/runner/work/astro/astro/packages/integrations/mdx
|
|
4
|
+
[35m@astrojs/mdx:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[35m@astrojs/mdx:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @astrojs/mdx
|
|
2
2
|
|
|
3
|
+
## 0.10.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4519](https://github.com/withastro/astro/pull/4519) [`a2e8e76c3`](https://github.com/withastro/astro/commit/a2e8e76c303e8d6f39c24c122905a10f06907997) Thanks [@JuanM04](https://github.com/JuanM04)! - Upgraded Shiki to v0.11.1
|
|
8
|
+
|
|
9
|
+
- [#4530](https://github.com/withastro/astro/pull/4530) [`8504cd79b`](https://github.com/withastro/astro/commit/8504cd79b708e0d3bf1a2bb4ff9b86936bdd692b) Thanks [@kylebutts](https://github.com/kylebutts)! - Add custom components to README
|
|
10
|
+
|
|
11
|
+
## 0.10.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#4423](https://github.com/withastro/astro/pull/4423) [`d4cd7a59f`](https://github.com/withastro/astro/commit/d4cd7a59fd38d411c442a818cfaab40f74106628) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Update Markdown type signature to match new markdown plugin,and update top-level layout props for better alignment
|
|
16
|
+
|
|
17
|
+
## 0.10.2-next.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#4423](https://github.com/withastro/astro/pull/4423) [`d4cd7a59f`](https://github.com/withastro/astro/commit/d4cd7a59fd38d411c442a818cfaab40f74106628) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Update Markdown type signature to match new markdown plugin,and update top-level layout props for better alignment
|
|
22
|
+
|
|
3
23
|
## 0.10.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -249,6 +249,54 @@ const { title, fancyJsHelper } = Astro.props;
|
|
|
249
249
|
<!-- -->
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
+
### Custom components
|
|
253
|
+
|
|
254
|
+
Under the hood, MDX will convert Markdown into HTML components. For example, this blockquote:
|
|
255
|
+
|
|
256
|
+
```md
|
|
257
|
+
> A blockquote with *some* emphasis.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
will be converted into this HTML:
|
|
261
|
+
|
|
262
|
+
```html
|
|
263
|
+
<blockquote>
|
|
264
|
+
<p>A blockquote with <em>some</em> emphasis.</p>
|
|
265
|
+
</blockquote>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
But what if you want to specify your own markup for these blockquotes? In the above example, you could create a custom `<Blockquote />` component (in any language) that either has a `<slot />` component or accepts a `children` prop.
|
|
269
|
+
|
|
270
|
+
```astro title="src/components/Blockquote.astro"
|
|
271
|
+
<blockquote class="bg-blue-50 p-4">
|
|
272
|
+
<span class="text-4xl text-blue-600 mb-2">“</span>
|
|
273
|
+
<slot />
|
|
274
|
+
</blockquote>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Then in the MDX file you import the component and export it to the `components` export.
|
|
278
|
+
|
|
279
|
+
```mdx title="src/pages/posts/post-1.mdx" {2}
|
|
280
|
+
import Blockquote from '../components/Blockquote.astro';
|
|
281
|
+
export const components = { blockquote: Blockquote };
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Now, writing the standard Markdown blockquote syntax (`>`) will use your custom `<Blockquote />` component instead. No need to use a component in Markdown, or write a remark/rehype plugin! Visit the [MDX website](https://mdxjs.com/table-of-components/) for a full list of HTML elements that can be overwritten as custom components.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
#### Custom components with imported `mdx`
|
|
288
|
+
|
|
289
|
+
When rendering imported MDX content, custom components can also be passed via the `components` prop:
|
|
290
|
+
|
|
291
|
+
```astro title="src/pages/page.astro" "components={{ h1: Heading }}"
|
|
292
|
+
---
|
|
293
|
+
import Content from '../content.mdx';
|
|
294
|
+
import Heading from '../Heading.astro';
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
<Content components={{ h1: Heading }} />
|
|
298
|
+
```
|
|
299
|
+
|
|
252
300
|
### Syntax highlighting
|
|
253
301
|
|
|
254
302
|
The MDX integration respects [your project's `markdown.syntaxHighlight` configuration](https://docs.astro.build/en/guides/markdown-content/#syntax-highlighting).
|
package/dist/astro-data-utils.js
CHANGED
package/dist/remark-shiki.js
CHANGED
|
@@ -5,7 +5,22 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false })
|
|
|
5
5
|
const cacheID = typeof theme === "string" ? theme : theme.name;
|
|
6
6
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
7
7
|
if (!highlighterAsync) {
|
|
8
|
-
highlighterAsync = getHighlighter({ theme })
|
|
8
|
+
highlighterAsync = getHighlighter({ theme }).then((hl) => {
|
|
9
|
+
hl.setColorReplacements({
|
|
10
|
+
"#000001": "var(--astro-code-color-text)",
|
|
11
|
+
"#000002": "var(--astro-code-color-background)",
|
|
12
|
+
"#000004": "var(--astro-code-token-constant)",
|
|
13
|
+
"#000005": "var(--astro-code-token-string)",
|
|
14
|
+
"#000006": "var(--astro-code-token-comment)",
|
|
15
|
+
"#000007": "var(--astro-code-token-keyword)",
|
|
16
|
+
"#000008": "var(--astro-code-token-parameter)",
|
|
17
|
+
"#000009": "var(--astro-code-token-function)",
|
|
18
|
+
"#000010": "var(--astro-code-token-string-expression)",
|
|
19
|
+
"#000011": "var(--astro-code-token-punctuation)",
|
|
20
|
+
"#000012": "var(--astro-code-token-link)"
|
|
21
|
+
});
|
|
22
|
+
return hl;
|
|
23
|
+
});
|
|
9
24
|
highlighterCacheAsync.set(cacheID, highlighterAsync);
|
|
10
25
|
}
|
|
11
26
|
const highlighter = await highlighterAsync;
|
|
@@ -28,10 +43,6 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false })
|
|
|
28
43
|
}
|
|
29
44
|
let html = highlighter.codeToHtml(node.value, { lang });
|
|
30
45
|
html = html.replace('<pre class="shiki"', `<pre class="astro-code"`);
|
|
31
|
-
html = html.replace(
|
|
32
|
-
/style="(background-)?color: var\(--shiki-/g,
|
|
33
|
-
'style="$1color: var(--astro-code-'
|
|
34
|
-
);
|
|
35
46
|
if (node.lang === "diff") {
|
|
36
47
|
html = html.replace(
|
|
37
48
|
/<span class="line"><span style="(.*?)">([\+|\-])/g,
|
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.10.
|
|
4
|
+
"version": "0.10.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"remark-frontmatter": "^4.0.1",
|
|
35
35
|
"remark-gfm": "^3.0.1",
|
|
36
36
|
"remark-smartypants": "^2.0.0",
|
|
37
|
-
"shiki": "^0.
|
|
37
|
+
"shiki": "^0.11.1",
|
|
38
38
|
"unist-util-visit": "^4.1.0",
|
|
39
39
|
"vfile": "^5.3.2"
|
|
40
40
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/chai": "^4.3.1",
|
|
43
43
|
"@types/mocha": "^9.1.1",
|
|
44
44
|
"@types/yargs-parser": "^21.0.0",
|
|
45
|
-
"astro": "1.
|
|
45
|
+
"astro": "1.1.2",
|
|
46
46
|
"astro-scripts": "0.0.7",
|
|
47
47
|
"chai": "^4.3.6",
|
|
48
48
|
"linkedom": "^0.14.12",
|
package/src/astro-data-utils.ts
CHANGED
package/src/remark-shiki.ts
CHANGED
|
@@ -14,7 +14,22 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
|
|
|
14
14
|
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
|
|
15
15
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
16
16
|
if (!highlighterAsync) {
|
|
17
|
-
highlighterAsync = getHighlighter({ theme })
|
|
17
|
+
highlighterAsync = getHighlighter({ theme }).then((hl) => {
|
|
18
|
+
hl.setColorReplacements({
|
|
19
|
+
'#000001': 'var(--astro-code-color-text)',
|
|
20
|
+
'#000002': 'var(--astro-code-color-background)',
|
|
21
|
+
'#000004': 'var(--astro-code-token-constant)',
|
|
22
|
+
'#000005': 'var(--astro-code-token-string)',
|
|
23
|
+
'#000006': 'var(--astro-code-token-comment)',
|
|
24
|
+
'#000007': 'var(--astro-code-token-keyword)',
|
|
25
|
+
'#000008': 'var(--astro-code-token-parameter)',
|
|
26
|
+
'#000009': 'var(--astro-code-token-function)',
|
|
27
|
+
'#000010': 'var(--astro-code-token-string-expression)',
|
|
28
|
+
'#000011': 'var(--astro-code-token-punctuation)',
|
|
29
|
+
'#000012': 'var(--astro-code-token-link)',
|
|
30
|
+
});
|
|
31
|
+
return hl;
|
|
32
|
+
});
|
|
18
33
|
highlighterCacheAsync.set(cacheID, highlighterAsync);
|
|
19
34
|
}
|
|
20
35
|
const highlighter = await highlighterAsync;
|
|
@@ -52,11 +67,6 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
|
|
|
52
67
|
|
|
53
68
|
// Replace "shiki" class naming with "astro".
|
|
54
69
|
html = html.replace('<pre class="shiki"', `<pre class="astro-code"`);
|
|
55
|
-
// Replace "shiki" css variable naming with "astro".
|
|
56
|
-
html = html.replace(
|
|
57
|
-
/style="(background-)?color: var\(--shiki-/g,
|
|
58
|
-
'style="$1color: var(--astro-code-'
|
|
59
|
-
);
|
|
60
70
|
// Add "user-select: none;" for "+"/"-" diff symbols
|
|
61
71
|
if (node.lang === 'diff') {
|
|
62
72
|
html = html.replace(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
const {
|
|
3
3
|
content = { title: "content didn't work" },
|
|
4
|
+
file = "file didn't work",
|
|
5
|
+
url = "url didn't work",
|
|
4
6
|
frontmatter = {
|
|
5
7
|
title: "frontmatter didn't work",
|
|
6
8
|
file: "file didn't work",
|
|
@@ -24,6 +26,8 @@ const {
|
|
|
24
26
|
<p data-frontmatter-title>{frontmatter.title}</p>
|
|
25
27
|
<p data-frontmatter-file>{frontmatter.file}</p>
|
|
26
28
|
<p data-frontmatter-url>{frontmatter.url}</p>
|
|
29
|
+
<p data-file>{frontmatter.file}</p>
|
|
30
|
+
<p data-url>{frontmatter.url}</p>
|
|
27
31
|
<p data-layout-rendered>Layout rendered!</p>
|
|
28
32
|
<ul data-headings>
|
|
29
33
|
{headings.map(heading => <li>{heading.slug}</li>)}
|
|
@@ -57,17 +57,21 @@ describe('MDX frontmatter', () => {
|
|
|
57
57
|
expect(headingSlugs).to.contain('section-2');
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
it('passes "file" and "url" to layout
|
|
60
|
+
it('passes "file" and "url" to layout', async () => {
|
|
61
61
|
const html = await fixture.readFile('/with-headings/index.html');
|
|
62
62
|
const { document } = parseHTML(html);
|
|
63
63
|
|
|
64
64
|
const frontmatterFile = document.querySelector('[data-frontmatter-file]')?.textContent;
|
|
65
65
|
const frontmatterUrl = document.querySelector('[data-frontmatter-url]')?.textContent;
|
|
66
|
+
const file = document.querySelector('[data-file]')?.textContent;
|
|
67
|
+
const url = document.querySelector('[data-url]')?.textContent;
|
|
66
68
|
|
|
67
69
|
expect(frontmatterFile?.endsWith('with-headings.mdx')).to.equal(
|
|
68
70
|
true,
|
|
69
71
|
'"file" prop does not end with correct path or is undefined'
|
|
70
72
|
);
|
|
71
73
|
expect(frontmatterUrl).to.equal('/with-headings');
|
|
74
|
+
expect(file).to.equal(frontmatterFile);
|
|
75
|
+
expect(url).to.equal(frontmatterUrl);
|
|
72
76
|
});
|
|
73
77
|
});
|