@astrojs/markdown-remark 5.1.1 → 5.3.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/dist/highlight.js +2 -2
- package/dist/index.js +3 -2
- package/dist/rehype-collect-headings.js +2 -2
- package/dist/shiki.d.ts +1 -1
- package/dist/shiki.js +11 -5
- package/dist/types.d.ts +5 -3
- package/package.json +10 -11
package/dist/highlight.js
CHANGED
|
@@ -16,13 +16,13 @@ async function highlightCodeBlocks(tree, highlighter) {
|
|
|
16
16
|
let languageMatch;
|
|
17
17
|
let { className } = node.properties;
|
|
18
18
|
if (typeof className === "string") {
|
|
19
|
-
languageMatch =
|
|
19
|
+
languageMatch = languagePattern.exec(className);
|
|
20
20
|
} else if (Array.isArray(className)) {
|
|
21
21
|
for (const cls of className) {
|
|
22
22
|
if (typeof cls !== "string") {
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
|
-
languageMatch =
|
|
25
|
+
languageMatch = languagePattern.exec(cls);
|
|
26
26
|
if (languageMatch) {
|
|
27
27
|
break;
|
|
28
28
|
}
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,8 @@ const markdownConfigDefaults = {
|
|
|
31
31
|
theme: "github-dark",
|
|
32
32
|
themes: {},
|
|
33
33
|
wrap: false,
|
|
34
|
-
transformers: []
|
|
34
|
+
transformers: [],
|
|
35
|
+
langAlias: {}
|
|
35
36
|
},
|
|
36
37
|
remarkPlugins: [],
|
|
37
38
|
rehypePlugins: [],
|
|
@@ -117,7 +118,7 @@ function prefixError(err, prefix) {
|
|
|
117
118
|
err.message = `${prefix}:
|
|
118
119
|
${err.message}`;
|
|
119
120
|
return err;
|
|
120
|
-
} catch
|
|
121
|
+
} catch {
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ""}`);
|
|
@@ -13,7 +13,7 @@ function rehypeHeadingIds() {
|
|
|
13
13
|
if (node.type !== "element") return;
|
|
14
14
|
const { tagName } = node;
|
|
15
15
|
if (tagName[0] !== "h") return;
|
|
16
|
-
const [, level] =
|
|
16
|
+
const [, level] = /h([0-6])/.exec(tagName) ?? [];
|
|
17
17
|
if (!level) return;
|
|
18
18
|
const depth = Number.parseInt(level);
|
|
19
19
|
let text = "";
|
|
@@ -22,7 +22,7 @@ function rehypeHeadingIds() {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
if (child.type === "raw") {
|
|
25
|
-
if (
|
|
25
|
+
if (/^\n?<.*>\n?$/.test(child.value)) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/dist/shiki.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ export interface ShikiHighlighter {
|
|
|
9
9
|
meta?: string;
|
|
10
10
|
}): Promise<string>;
|
|
11
11
|
}
|
|
12
|
-
export declare function createShikiHighlighter({ langs, theme, themes, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
|
12
|
+
export declare function createShikiHighlighter({ langs, theme, themes, defaultColor, wrap, transformers, langAlias, }?: ShikiConfig): Promise<ShikiHighlighter>;
|
package/dist/shiki.js
CHANGED
|
@@ -18,23 +18,28 @@ async function createShikiHighlighter({
|
|
|
18
18
|
langs = [],
|
|
19
19
|
theme = "github-dark",
|
|
20
20
|
themes = {},
|
|
21
|
+
defaultColor,
|
|
21
22
|
wrap = false,
|
|
22
|
-
transformers = []
|
|
23
|
+
transformers = [],
|
|
24
|
+
langAlias = {}
|
|
23
25
|
} = {}) {
|
|
24
26
|
theme = theme === "css-variables" ? cssVariablesTheme() : theme;
|
|
25
27
|
const highlighter = await getHighlighter({
|
|
26
28
|
langs: ["plaintext", ...langs],
|
|
29
|
+
langAlias,
|
|
27
30
|
themes: Object.values(themes).length ? Object.values(themes) : [theme]
|
|
28
31
|
});
|
|
29
32
|
return {
|
|
30
33
|
async highlight(code, lang = "plaintext", options) {
|
|
34
|
+
const resolvedLang = langAlias[lang] ?? lang;
|
|
31
35
|
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
32
|
-
if (!isSpecialLang(lang) && !loadedLanguages.includes(
|
|
36
|
+
if (!isSpecialLang(lang) && !loadedLanguages.includes(resolvedLang)) {
|
|
33
37
|
try {
|
|
34
|
-
await highlighter.loadLanguage(
|
|
38
|
+
await highlighter.loadLanguage(resolvedLang);
|
|
35
39
|
} catch (_err) {
|
|
40
|
+
const langStr = lang === resolvedLang ? `"${lang}"` : `"${lang}" (aliased to "${resolvedLang}")`;
|
|
36
41
|
console.warn(
|
|
37
|
-
`[Shiki] The language
|
|
42
|
+
`[Shiki] The language ${langStr} doesn't exist, falling back to "plaintext".`
|
|
38
43
|
);
|
|
39
44
|
lang = "plaintext";
|
|
40
45
|
}
|
|
@@ -43,6 +48,7 @@ async function createShikiHighlighter({
|
|
|
43
48
|
const inline = options?.inline ?? false;
|
|
44
49
|
return highlighter.codeToHtml(code, {
|
|
45
50
|
...themeOptions,
|
|
51
|
+
defaultColor,
|
|
46
52
|
lang,
|
|
47
53
|
// NOTE: while we can spread `options.attributes` here so that Shiki can auto-serialize this as rendered
|
|
48
54
|
// attributes on the top-level tag, it's not clear whether it is fine to pass all attributes as meta, as
|
|
@@ -71,7 +77,7 @@ async function createShikiHighlighter({
|
|
|
71
77
|
}
|
|
72
78
|
},
|
|
73
79
|
line(node) {
|
|
74
|
-
if (
|
|
80
|
+
if (resolvedLang === "diff") {
|
|
75
81
|
const innerSpanNode = node.children[0];
|
|
76
82
|
const innerSpanTextNode = innerSpanNode?.type === "element" && innerSpanNode.children?.[0];
|
|
77
83
|
if (innerSpanTextNode && innerSpanTextNode.type === "text") {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as hast from 'hast';
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
3
|
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
4
|
-
import type { BuiltinTheme, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
|
|
4
|
+
import type { BuiltinTheme, HighlighterCoreOptions, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
|
|
5
5
|
import type * as unified from 'unified';
|
|
6
|
-
import type { VFile } from 'vfile';
|
|
6
|
+
import type { DataMap, VFile } from 'vfile';
|
|
7
7
|
export type { Node } from 'unist';
|
|
8
8
|
export type MarkdownAstroData = {
|
|
9
9
|
frontmatter: Record<string, any>;
|
|
@@ -16,8 +16,10 @@ export type RemarkRehype = RemarkRehypeOptions;
|
|
|
16
16
|
export type ThemePresets = BuiltinTheme | 'css-variables';
|
|
17
17
|
export interface ShikiConfig {
|
|
18
18
|
langs?: LanguageRegistration[];
|
|
19
|
+
langAlias?: HighlighterCoreOptions['langAlias'];
|
|
19
20
|
theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
|
|
20
21
|
themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
|
|
22
|
+
defaultColor?: 'light' | 'dark' | string | false;
|
|
21
23
|
wrap?: boolean | null;
|
|
22
24
|
transformers?: ShikiTransformer[];
|
|
23
25
|
}
|
|
@@ -51,7 +53,7 @@ export interface MarkdownHeading {
|
|
|
51
53
|
text: string;
|
|
52
54
|
}
|
|
53
55
|
export interface MarkdownVFile extends VFile {
|
|
54
|
-
data: {
|
|
56
|
+
data: Record<string, unknown> & Partial<DataMap> & {
|
|
55
57
|
__astroHeadings?: MarkdownHeading[];
|
|
56
58
|
imagePaths?: Set<string>;
|
|
57
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,31 +27,31 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"github-slugger": "^2.0.0",
|
|
30
|
-
"hast-util-from-html": "^2.0.
|
|
30
|
+
"hast-util-from-html": "^2.0.3",
|
|
31
31
|
"hast-util-to-text": "^4.0.2",
|
|
32
32
|
"import-meta-resolve": "^4.1.0",
|
|
33
33
|
"mdast-util-definitions": "^6.0.0",
|
|
34
34
|
"rehype-raw": "^7.0.0",
|
|
35
|
-
"rehype-stringify": "^10.0.
|
|
35
|
+
"rehype-stringify": "^10.0.1",
|
|
36
36
|
"remark-gfm": "^4.0.0",
|
|
37
37
|
"remark-parse": "^11.0.0",
|
|
38
|
-
"remark-rehype": "^11.1.
|
|
39
|
-
"remark-smartypants": "^3.0.
|
|
40
|
-
"shiki": "^1.
|
|
38
|
+
"remark-rehype": "^11.1.1",
|
|
39
|
+
"remark-smartypants": "^3.0.2",
|
|
40
|
+
"shiki": "^1.22.0",
|
|
41
41
|
"unified": "^11.0.5",
|
|
42
42
|
"unist-util-remove-position": "^5.0.0",
|
|
43
43
|
"unist-util-visit": "^5.0.0",
|
|
44
44
|
"unist-util-visit-parents": "^6.0.1",
|
|
45
|
-
"vfile": "^6.0.
|
|
45
|
+
"vfile": "^6.0.3",
|
|
46
46
|
"@astrojs/prism": "3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/estree": "^1.0.
|
|
49
|
+
"@types/estree": "^1.0.6",
|
|
50
50
|
"@types/hast": "^3.0.4",
|
|
51
51
|
"@types/mdast": "^4.0.4",
|
|
52
|
-
"@types/unist": "^3.0.
|
|
52
|
+
"@types/unist": "^3.0.3",
|
|
53
53
|
"esbuild": "^0.21.5",
|
|
54
|
-
"mdast-util-mdx-expression": "^2.0.
|
|
54
|
+
"mdast-util-mdx-expression": "^2.0.1",
|
|
55
55
|
"astro-scripts": "0.0.14"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"prepublish": "pnpm build",
|
|
62
62
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
|
|
63
63
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
64
|
-
"postbuild": "astro-scripts copy \"src/**/*.js\"",
|
|
65
64
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
66
65
|
"test": "astro-scripts test \"test/**/*.test.js\""
|
|
67
66
|
}
|