@astrojs/mdx 0.10.2 → 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.
@@ -1,5 +1,5 @@
1
- @astrojs/mdx:build: cache hit, replaying output 97b75f35cc1d424b
1
+ @astrojs/mdx:build: cache hit, replaying output ce9fa72396235d9a
2
2
  @astrojs/mdx:build: 
3
- @astrojs/mdx:build: > @astrojs/mdx@0.10.2 build /home/runner/work/astro/astro/packages/integrations/mdx
3
+ @astrojs/mdx:build: > @astrojs/mdx@0.10.3 build /home/runner/work/astro/astro/packages/integrations/mdx
4
4
  @astrojs/mdx:build: > astro-scripts build "src/**/*.ts" && tsc
5
5
  @astrojs/mdx:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 0.10.2
4
12
 
5
13
  ### 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).
@@ -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.2",
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.10.1",
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.1.0",
45
+ "astro": "1.1.2",
46
46
  "astro-scripts": "0.0.7",
47
47
  "chai": "^4.3.6",
48
48
  "linkedom": "^0.14.12",
@@ -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(