@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 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.C-9yBNNX.mjs';
5
- export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.C-9yBNNX.mjs';
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.C-9yBNNX.js';
5
- export { M as MapLike, a as RehypeShikiExtraOptions } from './shared/rehype.C-9yBNNX.js';
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
- const res = handler(tree, node);
105
- if (!res)
102
+ }
103
+ const parsed = handler(tree, node);
104
+ if (!parsed)
106
105
  return;
107
106
  let lang;
108
107
  let lazyLoad = false;
109
- if (!res.lang) {
108
+ if (!parsed.lang) {
110
109
  lang = defaultLanguage;
111
- } else if (highlighter.getLoadedLanguages().includes(res.lang) || isSpecialLang(res.lang)) {
112
- lang = res.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 = res.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 processNode = () => {
122
- const meta = res.meta ? parseMetaString?.(res.meta, node, tree) : undefined;
123
- const fragment = highlight(lang, res.code, res.meta, meta ?? {});
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 (res.type === "inline") {
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
- queue.push(highlighter.loadLanguage(lang).then(() => processNode()));
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.C-9yBNNX.mjs';
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.C-9yBNNX.js';
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.1.0",
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.1.0",
53
- "shiki": "2.1.0"
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.1.0"
60
+ "@shikijs/transformers": "2.3.0"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "unbuild",