@astrojs/markdown-remark 0.6.0 → 0.6.1-next.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.
- package/CHANGELOG.md +10 -4
- package/dist/index.js +10 -3
- package/dist/remark-shiki.d.ts +3 -0
- package/dist/remark-shiki.js +21 -0
- package/dist/types.d.ts +4 -1
- package/package.json +2 -1
- package/src/index.ts +9 -1
- package/src/remark-shiki.ts +23 -0
- package/src/types.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 0.6.1-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2497](https://github.com/withastro/astro/pull/2497) [`6fe1b027`](https://github.com/withastro/astro/commit/6fe1b0279fce5a7a0e90ff79746ea0b641da3e21) Thanks [@JuanM04](https://github.com/JuanM04)! - Add Shiki as an alternative to Prism
|
|
8
|
+
|
|
3
9
|
## 0.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -105,10 +111,10 @@
|
|
|
105
111
|
|
|
106
112
|
```js
|
|
107
113
|
export default {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
markdownOptions: {
|
|
115
|
+
remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
|
|
116
|
+
rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
|
|
117
|
+
},
|
|
112
118
|
};
|
|
113
119
|
```
|
|
114
120
|
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { remarkJsx, loadRemarkJsx } from "./remark-jsx.js";
|
|
|
26
26
|
import rehypeJsx from "./rehype-jsx.js";
|
|
27
27
|
import rehypeEscape from "./rehype-escape.js";
|
|
28
28
|
import remarkPrism from "./remark-prism.js";
|
|
29
|
+
import remarkShiki from "./remark-shiki.js";
|
|
29
30
|
import remarkUnwrap from "./remark-unwrap.js";
|
|
30
31
|
import { loadPlugins } from "./load-plugins.js";
|
|
31
32
|
import { unified } from "unified";
|
|
@@ -42,10 +43,12 @@ async function renderMarkdownWithFrontmatter(contents, opts) {
|
|
|
42
43
|
const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
|
|
43
44
|
const DEFAULT_REHYPE_PLUGINS = ["rehype-slug"];
|
|
44
45
|
async function renderMarkdown(content, opts) {
|
|
45
|
-
var _a, _b;
|
|
46
|
+
var _a, _b, _c, _d;
|
|
46
47
|
let { remarkPlugins = [], rehypePlugins = [] } = opts != null ? opts : {};
|
|
47
48
|
const scopedClassName = (_a = opts == null ? void 0 : opts.$) == null ? void 0 : _a.scopedClassName;
|
|
48
49
|
const mode = (_b = opts == null ? void 0 : opts.mode) != null ? _b : "mdx";
|
|
50
|
+
const syntaxHighlight = (_c = opts == null ? void 0 : opts.syntaxHighlight) != null ? _c : "prism";
|
|
51
|
+
const shikiTheme = (_d = opts == null ? void 0 : opts.shikiTheme) != null ? _d : "github-dark";
|
|
49
52
|
const isMDX = mode === "mdx";
|
|
50
53
|
const { headers, rehypeCollectHeaders } = createCollectHeaders();
|
|
51
54
|
await Promise.all([loadRemarkExpressions(), loadRemarkJsx()]);
|
|
@@ -62,7 +65,11 @@ async function renderMarkdown(content, opts) {
|
|
|
62
65
|
if (scopedClassName) {
|
|
63
66
|
parser.use([scopedStyles(scopedClassName)]);
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
if (syntaxHighlight === "prism") {
|
|
69
|
+
parser.use([remarkPrism(scopedClassName)]);
|
|
70
|
+
} else if (syntaxHighlight === "shiki") {
|
|
71
|
+
parser.use([await remarkShiki(shikiTheme)]);
|
|
72
|
+
}
|
|
66
73
|
parser.use([[markdownToHtml, { allowDangerousHtml: true, passThrough: ["raw", "mdxTextExpression", "mdxJsxTextElement", "mdxJsxFlowElement"] }]]);
|
|
67
74
|
loadedRehypePlugins.forEach(([plugin, opts2]) => {
|
|
68
75
|
parser.use([[plugin, opts2]]);
|
|
@@ -89,4 +96,4 @@ export {
|
|
|
89
96
|
renderMarkdown,
|
|
90
97
|
renderMarkdownWithFrontmatter
|
|
91
98
|
};
|
|
92
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
99
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUVBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUVBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUtBLDZDQUFvRCxVQUFrQixNQUF3QztBQUM3RyxRQUFNLEVBQUUsTUFBTSxhQUFhLFlBQVksT0FBTztBQUM5QyxRQUFNLFFBQVEsTUFBTSxlQUFlLFNBQVM7QUFDNUMsU0FBTyxpQ0FBSyxRQUFMLEVBQVk7QUFBQTtBQUdiLE1BQU0seUJBQXlCLENBQUMsY0FBYztBQUU5QyxNQUFNLHlCQUF5QixDQUFDO0FBR3ZDLDhCQUFxQyxTQUFpQixNQUF3QztBQXBDOUY7QUFxQ0MsTUFBSSxFQUFFLGdCQUFnQixJQUFJLGdCQUFnQixPQUFPLHNCQUFRO0FBQ3pELFFBQU0sa0JBQWtCLG1DQUFNLE1BQU4sbUJBQVM7QUFDakMsUUFBTSxPQUFPLG1DQUFNLFNBQU4sWUFBYztBQUMzQixRQUFNLGtCQUFrQixtQ0FBTSxvQkFBTixZQUF5QjtBQUNqRCxRQUFNLGFBQWEsbUNBQU0sZUFBTixZQUFvQjtBQUN2QyxRQUFNLFFBQVEsU0FBUztBQUN2QixRQUFNLEVBQUUsU0FBUyx5QkFBeUI7QUFFMUMsUUFBTSxRQUF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O0FBRU4sTUFBSTtBQUNKLE1BQUk7QUFDSCxVQUFNLFFBQVEsTUFBTSxPQUFPLElBQUksQ0FBQyx1QkFBdUIsSUFBSSxpQkFBaUIsRUFBRSxvQkFBb0IsUUFBUSxRQUFRO0FBQ2xILGFBQVMsTUFBTTtBQUFBLFdBQ1AsS0FBUDtBQUNELFlBQVEsTUFBTTtBQUNkLFVBQU07QUFBQTtBQUdQLFNBQU87QUFBQSxJQUNOLFVBQVUsRUFBRSxTQUFTLFFBQVEsU0FBUyxNQUFNLE9BQU87QUFBQSxJQUNuRCxNQUFNLE9BQU87QUFBQTtBQUFBO0FBSWYsSUFBTyxjQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import shiki from "shiki";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
const remarkShiki = async (theme) => {
|
|
4
|
+
const highlighter = await shiki.getHighlighter({ theme });
|
|
5
|
+
return () => (tree) => {
|
|
6
|
+
visit(tree, "code", (node) => {
|
|
7
|
+
var _a;
|
|
8
|
+
let html = highlighter.codeToHtml(node.value, { lang: (_a = node.lang) != null ? _a : "plaintext" });
|
|
9
|
+
html = html.replace('<pre class="shiki"', '<pre class="astro-code"');
|
|
10
|
+
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
|
11
|
+
node.type = "html";
|
|
12
|
+
node.value = html;
|
|
13
|
+
node.children = [];
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
var remark_shiki_default = remarkShiki;
|
|
18
|
+
export {
|
|
19
|
+
remark_shiki_default as default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlbWFyay1zaGlraS50cyJdLAogICJtYXBwaW5ncyI6ICJBQUFBO0FBQ0E7QUFFQSxNQUFNLGNBQWMsT0FBTyxVQUF1QjtBQUNqRCxRQUFNLGNBQWMsTUFBTSxNQUFNLGVBQWUsRUFBRTtBQUVqRCxTQUFPLE1BQU0sQ0FBQyxTQUFjO0FBQzNCLFVBQU0sTUFBTSxRQUFRLENBQUMsU0FBUztBQVBoQztBQVFHLFVBQUksT0FBTyxZQUFZLFdBQVcsS0FBSyxPQUFPLEVBQUUsTUFBTSxXQUFLLFNBQUwsWUFBYTtBQUduRSxhQUFPLEtBQUssUUFBUSxzQkFBc0I7QUFFMUMsYUFBTyxLQUFLLFFBQVEsOENBQThDO0FBRWxFLFdBQUssT0FBTztBQUNaLFdBQUssUUFBUTtBQUNiLFdBQUssV0FBVztBQUFBO0FBQUE7QUFBQTtBQUtuQixJQUFPLHVCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import * as unified from 'unified';
|
|
1
|
+
import type * as unified from 'unified';
|
|
2
|
+
import type * as shiki from 'shiki';
|
|
2
3
|
export declare type UnifiedPluginImport = Promise<{
|
|
3
4
|
default: unified.Plugin;
|
|
4
5
|
}>;
|
|
5
6
|
export declare type Plugin = string | [string, any] | UnifiedPluginImport | [UnifiedPluginImport, any];
|
|
6
7
|
export interface AstroMarkdownOptions {
|
|
7
8
|
mode?: 'md' | 'mdx';
|
|
9
|
+
syntaxHighlight?: 'prism' | 'shiki' | false;
|
|
10
|
+
shikiTheme?: shiki.Theme;
|
|
8
11
|
remarkPlugins?: Plugin[];
|
|
9
12
|
rehypePlugins?: Plugin[];
|
|
10
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "0.6.0",
|
|
3
|
+
"version": "0.6.1-next.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"remark-parse": "^10.0.1",
|
|
39
39
|
"remark-rehype": "^10.0.1",
|
|
40
40
|
"remark-smartypants": "^2.0.0",
|
|
41
|
+
"shiki": "^0.10.0",
|
|
41
42
|
"unified": "^10.1.1",
|
|
42
43
|
"unist-util-map": "^3.0.0",
|
|
43
44
|
"unist-util-visit": "^4.1.0"
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { remarkJsx, loadRemarkJsx } from './remark-jsx.js';
|
|
|
9
9
|
import rehypeJsx from './rehype-jsx.js';
|
|
10
10
|
import rehypeEscape from './rehype-escape.js';
|
|
11
11
|
import remarkPrism from './remark-prism.js';
|
|
12
|
+
import remarkShiki from './remark-shiki.js';
|
|
12
13
|
import remarkUnwrap from './remark-unwrap.js';
|
|
13
14
|
import { loadPlugins } from './load-plugins.js';
|
|
14
15
|
|
|
@@ -37,6 +38,8 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
|
|
|
37
38
|
let { remarkPlugins = [], rehypePlugins = [] } = opts ?? {};
|
|
38
39
|
const scopedClassName = opts?.$?.scopedClassName;
|
|
39
40
|
const mode = opts?.mode ?? 'mdx';
|
|
41
|
+
const syntaxHighlight = opts?.syntaxHighlight ?? 'prism';
|
|
42
|
+
const shikiTheme = opts?.shikiTheme ?? 'github-dark';
|
|
40
43
|
const isMDX = mode === 'mdx';
|
|
41
44
|
const { headers, rehypeCollectHeaders } = createCollectHeaders();
|
|
42
45
|
|
|
@@ -64,7 +67,12 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
|
|
|
64
67
|
parser.use([scopedStyles(scopedClassName)]);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
if (syntaxHighlight === 'prism') {
|
|
71
|
+
parser.use([remarkPrism(scopedClassName)]);
|
|
72
|
+
} else if (syntaxHighlight === 'shiki') {
|
|
73
|
+
parser.use([await remarkShiki(shikiTheme)]);
|
|
74
|
+
}
|
|
75
|
+
|
|
68
76
|
parser.use([[markdownToHtml as any, { allowDangerousHtml: true, passThrough: ['raw', 'mdxTextExpression', 'mdxJsxTextElement', 'mdxJsxFlowElement'] }]]);
|
|
69
77
|
|
|
70
78
|
loadedRehypePlugins.forEach(([plugin, opts]) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import shiki from 'shiki';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
const remarkShiki = async (theme: shiki.Theme) => {
|
|
5
|
+
const highlighter = await shiki.getHighlighter({ theme });
|
|
6
|
+
|
|
7
|
+
return () => (tree: any) => {
|
|
8
|
+
visit(tree, 'code', (node) => {
|
|
9
|
+
let html = highlighter.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
|
|
10
|
+
|
|
11
|
+
// Replace "shiki" class naming with "astro".
|
|
12
|
+
html = html.replace('<pre class="shiki"', '<pre class="astro-code"');
|
|
13
|
+
// Replace "shiki" css variable naming with "astro".
|
|
14
|
+
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
|
15
|
+
|
|
16
|
+
node.type = 'html';
|
|
17
|
+
node.value = html;
|
|
18
|
+
node.children = [];
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default remarkShiki;
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import * as unified from 'unified';
|
|
1
|
+
import type * as unified from 'unified';
|
|
2
|
+
import type * as shiki from 'shiki';
|
|
2
3
|
|
|
3
4
|
export type UnifiedPluginImport = Promise<{ default: unified.Plugin }>;
|
|
4
5
|
export type Plugin = string | [string, any] | UnifiedPluginImport | [UnifiedPluginImport, any];
|
|
5
6
|
|
|
6
7
|
export interface AstroMarkdownOptions {
|
|
7
8
|
mode?: 'md' | 'mdx';
|
|
9
|
+
syntaxHighlight?: 'prism' | 'shiki' | false;
|
|
10
|
+
shikiTheme?: shiki.Theme;
|
|
8
11
|
remarkPlugins?: Plugin[];
|
|
9
12
|
rehypePlugins?: Plugin[];
|
|
10
13
|
}
|