@shikijs/rehype 2.1.0 → 2.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/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +23 -16
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/shared/{rehype.C-9yBNNX.d.mts → rehype.DcMmi29I.d.mts} +1 -3
- package/dist/shared/{rehype.C-9yBNNX.d.ts → rehype.DcMmi29I.d.ts} +1 -3
- package/package.json +4 -4
package/dist/core.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HighlighterGeneric } from '@shikijs/types';
|
|
2
2
|
import { Root } from 'hast';
|
|
3
3
|
import { Transformer } from 'unified';
|
|
4
|
-
import { R as RehypeShikiCoreOptions } from './shared/rehype.
|
|
5
|
-
export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.
|
|
4
|
+
import { R as RehypeShikiCoreOptions } from './shared/rehype.DcMmi29I.mjs';
|
|
5
|
+
export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.DcMmi29I.mjs';
|
|
6
6
|
import 'shiki';
|
|
7
7
|
|
|
8
8
|
declare function rehypeShikiFromHighlighter(highlighter: HighlighterGeneric<any, any>, options: RehypeShikiCoreOptions): Transformer<Root, Root>;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HighlighterGeneric } from '@shikijs/types';
|
|
2
2
|
import { Root } from 'hast';
|
|
3
3
|
import { Transformer } from 'unified';
|
|
4
|
-
import { R as RehypeShikiCoreOptions } from './shared/rehype.
|
|
5
|
-
export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.
|
|
4
|
+
import { R as RehypeShikiCoreOptions } from './shared/rehype.DcMmi29I.js';
|
|
5
|
+
export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.DcMmi29I.js';
|
|
6
6
|
import 'shiki';
|
|
7
7
|
|
|
8
8
|
declare function rehypeShikiFromHighlighter(highlighter: HighlighterGeneric<any, any>, options: RehypeShikiCoreOptions): Transformer<Root, Root>;
|
package/dist/core.mjs
CHANGED
|
@@ -95,35 +95,34 @@ function rehypeShikiFromHighlighter(highlighter, options) {
|
|
|
95
95
|
return;
|
|
96
96
|
if (node.tagName === "pre") {
|
|
97
97
|
handler = PreHandler;
|
|
98
|
-
}
|
|
99
|
-
if (node.tagName === "code" && inline) {
|
|
98
|
+
} else if (node.tagName === "code" && inline) {
|
|
100
99
|
handler = InlineCodeHandlers[inline];
|
|
101
|
-
}
|
|
102
|
-
if (!handler)
|
|
100
|
+
} else {
|
|
103
101
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
}
|
|
103
|
+
const parsed = handler(tree, node);
|
|
104
|
+
if (!parsed)
|
|
106
105
|
return;
|
|
107
106
|
let lang;
|
|
108
107
|
let lazyLoad = false;
|
|
109
|
-
if (!
|
|
108
|
+
if (!parsed.lang) {
|
|
110
109
|
lang = defaultLanguage;
|
|
111
|
-
} else if (highlighter.getLoadedLanguages().includes(
|
|
112
|
-
lang =
|
|
110
|
+
} else if (highlighter.getLoadedLanguages().includes(parsed.lang) || isSpecialLang(parsed.lang)) {
|
|
111
|
+
lang = parsed.lang;
|
|
113
112
|
} else if (lazy) {
|
|
114
113
|
lazyLoad = true;
|
|
115
|
-
lang =
|
|
114
|
+
lang = parsed.lang;
|
|
116
115
|
} else if (fallbackLanguage) {
|
|
117
116
|
lang = fallbackLanguage;
|
|
118
117
|
}
|
|
119
118
|
if (!lang)
|
|
120
119
|
return;
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
const fragment = highlight(
|
|
120
|
+
const meta = parsed.meta ? parseMetaString?.(parsed.meta, node, tree) : undefined;
|
|
121
|
+
const processNode = (targetLang) => {
|
|
122
|
+
const fragment = highlight(targetLang, parsed.code, parsed.meta, meta ?? {});
|
|
124
123
|
if (!fragment)
|
|
125
124
|
return;
|
|
126
|
-
if (
|
|
125
|
+
if (parsed.type === "inline") {
|
|
127
126
|
const head = fragment.children[0];
|
|
128
127
|
if (head.type === "element" && head.tagName === "pre") {
|
|
129
128
|
head.tagName = "span";
|
|
@@ -132,9 +131,17 @@ function rehypeShikiFromHighlighter(highlighter, options) {
|
|
|
132
131
|
parent.children[index] = fragment;
|
|
133
132
|
};
|
|
134
133
|
if (lazyLoad) {
|
|
135
|
-
|
|
134
|
+
try {
|
|
135
|
+
queue.push(highlighter.loadLanguage(lang).then(() => processNode(lang)));
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (fallbackLanguage)
|
|
138
|
+
return processNode(fallbackLanguage);
|
|
139
|
+
else if (onError)
|
|
140
|
+
onError(error);
|
|
141
|
+
else throw error;
|
|
142
|
+
}
|
|
136
143
|
} else {
|
|
137
|
-
processNode();
|
|
144
|
+
processNode(lang);
|
|
138
145
|
}
|
|
139
146
|
return "skip";
|
|
140
147
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageInput } from '@shikijs/types';
|
|
|
2
2
|
import { Root } from 'hast';
|
|
3
3
|
import { BuiltinLanguage } from 'shiki';
|
|
4
4
|
import { Plugin } from 'unified';
|
|
5
|
-
import { R as RehypeShikiCoreOptions } from './shared/rehype.
|
|
5
|
+
import { R as RehypeShikiCoreOptions } from './shared/rehype.DcMmi29I.mjs';
|
|
6
6
|
|
|
7
7
|
type RehypeShikiOptions = RehypeShikiCoreOptions & {
|
|
8
8
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageInput } from '@shikijs/types';
|
|
|
2
2
|
import { Root } from 'hast';
|
|
3
3
|
import { BuiltinLanguage } from 'shiki';
|
|
4
4
|
import { Plugin } from 'unified';
|
|
5
|
-
import { R as RehypeShikiCoreOptions } from './shared/rehype.
|
|
5
|
+
import { R as RehypeShikiCoreOptions } from './shared/rehype.DcMmi29I.js';
|
|
6
6
|
|
|
7
7
|
type RehypeShikiOptions = RehypeShikiCoreOptions & {
|
|
8
8
|
/**
|
|
@@ -17,9 +17,7 @@ interface RehypeShikiExtraOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
defaultLanguage?: string;
|
|
19
19
|
/**
|
|
20
|
-
* The fallback language to use when specified language is not loaded
|
|
21
|
-
*
|
|
22
|
-
* Ignored if `lazy` is enabled
|
|
20
|
+
* The fallback language to use when specified language is not loaded, or not included in the bundle
|
|
23
21
|
*/
|
|
24
22
|
fallbackLanguage?: string;
|
|
25
23
|
/**
|
|
@@ -17,9 +17,7 @@ interface RehypeShikiExtraOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
defaultLanguage?: string;
|
|
19
19
|
/**
|
|
20
|
-
* The fallback language to use when specified language is not loaded
|
|
21
|
-
*
|
|
22
|
-
* Ignored if `lazy` is enabled
|
|
20
|
+
* The fallback language to use when specified language is not loaded, or not included in the bundle
|
|
23
21
|
*/
|
|
24
22
|
fallbackLanguage?: string;
|
|
25
23
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/rehype",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "rehype integration for shiki",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"hast-util-to-string": "^3.0.1",
|
|
50
50
|
"unified": "^11.0.5",
|
|
51
51
|
"unist-util-visit": "^5.0.0",
|
|
52
|
-
"@shikijs/types": "2.
|
|
53
|
-
"shiki": "2.
|
|
52
|
+
"@shikijs/types": "2.3.0",
|
|
53
|
+
"shiki": "2.3.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"rehype-raw": "^7.0.0",
|
|
57
57
|
"rehype-stringify": "^10.0.1",
|
|
58
58
|
"remark-parse": "^11.0.0",
|
|
59
59
|
"remark-rehype": "^11.1.1",
|
|
60
|
-
"@shikijs/transformers": "2.
|
|
60
|
+
"@shikijs/transformers": "2.3.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "unbuild",
|