@astrojs/markdown-remark 1.0.0 → 1.1.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 +2 -2
- package/CHANGELOG.md +22 -0
- package/dist/index.js +7 -4
- package/dist/remark-shiki.js +16 -5
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/index.ts +6 -3
- package/src/remark-shiki.ts +16 -6
- package/src/types.ts +11 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [
|
|
1
|
+
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [2mddf2e92d592039b4[0m
|
|
2
2
|
[35m@astrojs/markdown-remark:build: [0m
|
|
3
|
-
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@1.
|
|
3
|
+
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@1.1.1 build /home/runner/work/astro/astro/packages/markdown/remark
|
|
4
4
|
[35m@astrojs/markdown-remark:build: [0m> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
|
|
5
5
|
[35m@astrojs/markdown-remark:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
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
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#4474](https://github.com/withastro/astro/pull/4474) [`ac0321824`](https://github.com/withastro/astro/commit/ac03218247763e4782824e220a384fd20ae6d769) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Add "extends" to markdown plugin config to preserve Astro defaults
|
|
14
|
+
|
|
15
|
+
* [#4138](https://github.com/withastro/astro/pull/4138) [`839097c84`](https://github.com/withastro/astro/commit/839097c84e830542c17c18d8337a88de8885c356) Thanks [@gtnbssn](https://github.com/gtnbssn)! - Makes remark-rehype options available in astro.config.mjs
|
|
16
|
+
|
|
17
|
+
## 1.1.0-next.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [#4474](https://github.com/withastro/astro/pull/4474) [`ac0321824`](https://github.com/withastro/astro/commit/ac03218247763e4782824e220a384fd20ae6d769) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Add "extends" to markdown plugin config to preserve Astro defaults
|
|
22
|
+
|
|
23
|
+
* [#4138](https://github.com/withastro/astro/pull/4138) [`839097c84`](https://github.com/withastro/astro/commit/839097c84e830542c17c18d8337a88de8885c356) Thanks [@gtnbssn](https://github.com/gtnbssn)! - Makes remark-rehype options available in astro.config.mjs
|
|
24
|
+
|
|
3
25
|
## 1.0.0
|
|
4
26
|
|
|
5
27
|
### Major Changes
|
package/dist/index.js
CHANGED
|
@@ -29,15 +29,17 @@ async function renderMarkdown(content, opts) {
|
|
|
29
29
|
shikiConfig = {},
|
|
30
30
|
remarkPlugins = [],
|
|
31
31
|
rehypePlugins = [],
|
|
32
|
+
remarkRehype = {},
|
|
33
|
+
extendDefaultPlugins = false,
|
|
32
34
|
isAstroFlavoredMd = false
|
|
33
35
|
} = opts;
|
|
34
36
|
const input = new VFile({ value: content, path: fileURL });
|
|
35
37
|
const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
|
|
36
38
|
const { headings, rehypeCollectHeadings } = createCollectHeadings();
|
|
37
39
|
let parser = unified().use(markdown).use(remarkInitializeAstroData).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
|
|
38
|
-
if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
|
|
39
|
-
remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
|
|
40
|
-
rehypePlugins = [...DEFAULT_REHYPE_PLUGINS];
|
|
40
|
+
if (extendDefaultPlugins || remarkPlugins.length === 0 && rehypePlugins.length === 0) {
|
|
41
|
+
remarkPlugins = [...DEFAULT_REMARK_PLUGINS, ...remarkPlugins];
|
|
42
|
+
rehypePlugins = [...DEFAULT_REHYPE_PLUGINS, ...rehypePlugins];
|
|
41
43
|
}
|
|
42
44
|
const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
|
|
43
45
|
const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));
|
|
@@ -63,7 +65,8 @@ async function renderMarkdown(content, opts) {
|
|
|
63
65
|
"mdxJsxFlowElement",
|
|
64
66
|
"mdxJsxTextElement",
|
|
65
67
|
"mdxTextExpression"
|
|
66
|
-
] : []
|
|
68
|
+
] : [],
|
|
69
|
+
...remarkRehype
|
|
67
70
|
}
|
|
68
71
|
]
|
|
69
72
|
]);
|
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;
|
|
@@ -31,10 +46,6 @@ const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false },
|
|
|
31
46
|
'<pre class="shiki"',
|
|
32
47
|
`<pre is:raw class="astro-code${scopedClassName ? " " + scopedClassName : ""}"`
|
|
33
48
|
);
|
|
34
|
-
html = html.replace(
|
|
35
|
-
/style="(background-)?color: var\(--shiki-/g,
|
|
36
|
-
'style="$1color: var(--astro-code-'
|
|
37
|
-
);
|
|
38
49
|
if (node.lang === "diff") {
|
|
39
50
|
html = html.replace(
|
|
40
51
|
/<span class="line"><span style="(.*?)">([\+|\-])/g,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as hast from 'hast';
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
|
+
import type { all as Handlers, one as Handler, Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
3
4
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
|
4
5
|
import type * as unified from 'unified';
|
|
5
6
|
import type { VFile } from 'vfile';
|
|
@@ -8,6 +9,11 @@ export declare type RemarkPlugin<PluginParameters extends any[] = any[]> = unifi
|
|
|
8
9
|
export declare type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
|
|
9
10
|
export declare type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
|
|
10
11
|
export declare type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
|
|
12
|
+
export declare type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
|
|
13
|
+
handlers: typeof Handlers;
|
|
14
|
+
} & {
|
|
15
|
+
handler: typeof Handler;
|
|
16
|
+
};
|
|
11
17
|
export interface ShikiConfig {
|
|
12
18
|
langs?: ILanguageRegistration[];
|
|
13
19
|
theme?: Theme | IThemeRegistration;
|
|
@@ -20,6 +26,8 @@ export interface AstroMarkdownOptions {
|
|
|
20
26
|
shikiConfig?: ShikiConfig;
|
|
21
27
|
remarkPlugins?: RemarkPlugins;
|
|
22
28
|
rehypePlugins?: RehypePlugins;
|
|
29
|
+
remarkRehype?: RemarkRehype;
|
|
30
|
+
extendDefaultPlugins?: boolean;
|
|
23
31
|
}
|
|
24
32
|
export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
25
33
|
/** @internal */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"remark-parse": "^10.0.1",
|
|
33
33
|
"remark-rehype": "^10.1.0",
|
|
34
34
|
"remark-smartypants": "^2.0.0",
|
|
35
|
-
"shiki": "^0.
|
|
35
|
+
"shiki": "^0.11.1",
|
|
36
36
|
"unified": "^10.1.2",
|
|
37
37
|
"unist-util-map": "^3.1.1",
|
|
38
38
|
"unist-util-visit": "^4.1.0",
|
package/src/index.ts
CHANGED
|
@@ -38,6 +38,8 @@ export async function renderMarkdown(
|
|
|
38
38
|
shikiConfig = {},
|
|
39
39
|
remarkPlugins = [],
|
|
40
40
|
rehypePlugins = [],
|
|
41
|
+
remarkRehype = {},
|
|
42
|
+
extendDefaultPlugins = false,
|
|
41
43
|
isAstroFlavoredMd = false,
|
|
42
44
|
} = opts;
|
|
43
45
|
const input = new VFile({ value: content, path: fileURL });
|
|
@@ -49,9 +51,9 @@ export async function renderMarkdown(
|
|
|
49
51
|
.use(remarkInitializeAstroData)
|
|
50
52
|
.use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
|
|
51
53
|
|
|
52
|
-
if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
|
|
53
|
-
remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
|
|
54
|
-
rehypePlugins = [...DEFAULT_REHYPE_PLUGINS];
|
|
54
|
+
if (extendDefaultPlugins || (remarkPlugins.length === 0 && rehypePlugins.length === 0)) {
|
|
55
|
+
remarkPlugins = [...DEFAULT_REMARK_PLUGINS, ...remarkPlugins];
|
|
56
|
+
rehypePlugins = [...DEFAULT_REHYPE_PLUGINS, ...rehypePlugins];
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
|
|
@@ -85,6 +87,7 @@ export async function renderMarkdown(
|
|
|
85
87
|
'mdxTextExpression',
|
|
86
88
|
]
|
|
87
89
|
: [],
|
|
90
|
+
...remarkRehype,
|
|
88
91
|
},
|
|
89
92
|
],
|
|
90
93
|
]);
|
package/src/remark-shiki.ts
CHANGED
|
@@ -17,7 +17,22 @@ const remarkShiki = async (
|
|
|
17
17
|
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
|
|
18
18
|
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
|
19
19
|
if (!highlighterAsync) {
|
|
20
|
-
highlighterAsync = getHighlighter({ theme })
|
|
20
|
+
highlighterAsync = getHighlighter({ theme }).then((hl) => {
|
|
21
|
+
hl.setColorReplacements({
|
|
22
|
+
'#000001': 'var(--astro-code-color-text)',
|
|
23
|
+
'#000002': 'var(--astro-code-color-background)',
|
|
24
|
+
'#000004': 'var(--astro-code-token-constant)',
|
|
25
|
+
'#000005': 'var(--astro-code-token-string)',
|
|
26
|
+
'#000006': 'var(--astro-code-token-comment)',
|
|
27
|
+
'#000007': 'var(--astro-code-token-keyword)',
|
|
28
|
+
'#000008': 'var(--astro-code-token-parameter)',
|
|
29
|
+
'#000009': 'var(--astro-code-token-function)',
|
|
30
|
+
'#000010': 'var(--astro-code-token-string-expression)',
|
|
31
|
+
'#000011': 'var(--astro-code-token-punctuation)',
|
|
32
|
+
'#000012': 'var(--astro-code-token-link)',
|
|
33
|
+
});
|
|
34
|
+
return hl;
|
|
35
|
+
});
|
|
21
36
|
highlighterCacheAsync.set(cacheID, highlighterAsync);
|
|
22
37
|
}
|
|
23
38
|
const highlighter = await highlighterAsync;
|
|
@@ -58,11 +73,6 @@ const remarkShiki = async (
|
|
|
58
73
|
'<pre class="shiki"',
|
|
59
74
|
`<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`
|
|
60
75
|
);
|
|
61
|
-
// Replace "shiki" css variable naming with "astro".
|
|
62
|
-
html = html.replace(
|
|
63
|
-
/style="(background-)?color: var\(--shiki-/g,
|
|
64
|
-
'style="$1color: var(--astro-code-'
|
|
65
|
-
);
|
|
66
76
|
// Add "user-select: none;" for "+"/"-" diff symbols
|
|
67
77
|
if (node.lang === 'diff') {
|
|
68
78
|
html = html.replace(
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type * as hast from 'hast';
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
|
+
import type {
|
|
4
|
+
all as Handlers,
|
|
5
|
+
one as Handler,
|
|
6
|
+
Options as RemarkRehypeOptions,
|
|
7
|
+
} from 'remark-rehype';
|
|
3
8
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
|
4
9
|
import type * as unified from 'unified';
|
|
5
10
|
import type { VFile } from 'vfile';
|
|
@@ -20,6 +25,10 @@ export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugi
|
|
|
20
25
|
|
|
21
26
|
export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
|
|
22
27
|
|
|
28
|
+
export type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
|
|
29
|
+
handlers: typeof Handlers;
|
|
30
|
+
} & { handler: typeof Handler };
|
|
31
|
+
|
|
23
32
|
export interface ShikiConfig {
|
|
24
33
|
langs?: ILanguageRegistration[];
|
|
25
34
|
theme?: Theme | IThemeRegistration;
|
|
@@ -33,6 +42,8 @@ export interface AstroMarkdownOptions {
|
|
|
33
42
|
shikiConfig?: ShikiConfig;
|
|
34
43
|
remarkPlugins?: RemarkPlugins;
|
|
35
44
|
rehypePlugins?: RehypePlugins;
|
|
45
|
+
remarkRehype?: RemarkRehype;
|
|
46
|
+
extendDefaultPlugins?: boolean;
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|