fumadocs-core 13.4.1 → 13.4.3

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.
@@ -37,6 +37,12 @@ type RehypeCodeOptions = RehypeShikiOptions & {
37
37
  * @defaultValue true
38
38
  */
39
39
  tab?: false;
40
+ /**
41
+ * Enable Shiki's experimental JS engine
42
+ *
43
+ * @defaultValue false
44
+ */
45
+ experimentalJSEngine?: boolean;
40
46
  };
41
47
  /**
42
48
  * Handle codeblocks
@@ -13,11 +13,16 @@ import {
13
13
  } from "remark-gfm";
14
14
 
15
15
  // src/mdx-plugins/rehype-code.ts
16
- import rehypeShiki from "@shikijs/rehype";
16
+ import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
17
17
  import {
18
18
  transformerNotationHighlight,
19
19
  transformerNotationWordHighlight
20
20
  } from "@shikijs/transformers";
21
+ import {
22
+ getSingletonHighlighter,
23
+ createJavaScriptRegexEngine,
24
+ bundledLanguages
25
+ } from "shiki";
21
26
 
22
27
  // src/mdx-plugins/transformer-icon.ts
23
28
  var defaultShortcuts = {
@@ -183,6 +188,7 @@ var rehypeCodeDefaultOptions = {
183
188
  dark: "github-dark"
184
189
  },
185
190
  defaultLanguage: "plaintext",
191
+ experimentalJSEngine: false,
186
192
  defaultColor: false,
187
193
  transformers: [
188
194
  transformerNotationHighlight(),
@@ -241,7 +247,25 @@ function rehypeCode(options = {}) {
241
247
  if (codeOptions.tab !== false) {
242
248
  codeOptions.transformers = [...codeOptions.transformers, transformerTab()];
243
249
  }
244
- return rehypeShiki.call(this, codeOptions);
250
+ let themeItems = [];
251
+ if ("themes" in codeOptions) {
252
+ themeItems = Object.values(codeOptions.themes);
253
+ } else if ("theme" in codeOptions) {
254
+ themeItems = [codeOptions.theme];
255
+ }
256
+ const highlighter = getSingletonHighlighter({
257
+ engine: codeOptions.experimentalJSEngine ? createJavaScriptRegexEngine() : void 0,
258
+ themes: themeItems.filter(Boolean),
259
+ langs: codeOptions.langs ?? Object.keys(bundledLanguages)
260
+ });
261
+ return async (tree, file) => {
262
+ const transformer = rehypeShikiFromHighlighter(
263
+ await highlighter,
264
+ codeOptions
265
+ );
266
+ await transformer(tree, file, () => {
267
+ });
268
+ };
245
269
  }
246
270
  function transformerTab() {
247
271
  return {
@@ -281,9 +305,20 @@ function remarkImage({
281
305
  useImport = true,
282
306
  publicDir = path.join(process.cwd(), "public")
283
307
  } = {}) {
284
- return async (tree) => {
308
+ return async (tree, file) => {
285
309
  const importsToInject = [];
286
310
  const promises = [];
311
+ function getImportPath(src) {
312
+ if (!src.startsWith("/")) return src;
313
+ if (file.path) {
314
+ const relative = path.relative(
315
+ path.dirname(file.path),
316
+ path.join(publicDir, src)
317
+ );
318
+ return relative.startsWith("./") ? relative : `./${relative}`;
319
+ }
320
+ return path.join(publicDir, src);
321
+ }
287
322
  visit(tree, "image", (node) => {
288
323
  const src = decodeURI(node.url);
289
324
  if (!src) return;
@@ -325,10 +360,7 @@ function remarkImage({
325
360
  const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => src.endsWith(ext));
326
361
  importsToInject.push({
327
362
  variableName,
328
- importPath: slash(
329
- // with imports, relative paths don't have to be absolute
330
- src.startsWith("/") ? path.join(publicDir, src) : src
331
- )
363
+ importPath: slash(getImportPath(src))
332
364
  });
333
365
  Object.assign(node, {
334
366
  type: "mdxJsxFlowElement",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "13.4.1",
3
+ "version": "13.4.3",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -127,8 +127,8 @@
127
127
  ],
128
128
  "dependencies": {
129
129
  "@formatjs/intl-localematcher": "^0.5.4",
130
- "@shikijs/rehype": "^1.13.0",
131
- "@shikijs/transformers": "^1.13.0",
130
+ "@shikijs/rehype": "^1.15.2",
131
+ "@shikijs/transformers": "^1.15.2",
132
132
  "flexsearch": "0.7.21",
133
133
  "github-slugger": "^2.0.0",
134
134
  "image-size": "^1.1.1",
@@ -139,7 +139,7 @@
139
139
  "remark-gfm": "^4.0.0",
140
140
  "remark-mdx": "^3.0.1",
141
141
  "scroll-into-view-if-needed": "^3.1.0",
142
- "shiki": "^1.13.0",
142
+ "shiki": "^1.15.2",
143
143
  "swr": "^2.2.5",
144
144
  "unist-util-visit": "^5.0.0"
145
145
  },
@@ -151,11 +151,11 @@
151
151
  "@types/hast": "^3.0.4",
152
152
  "@types/mdast": "^4.0.3",
153
153
  "@types/negotiator": "^0.6.3",
154
- "@types/node": "22.3.0",
155
- "@types/react": "^18.3.3",
154
+ "@types/node": "22.5.2",
155
+ "@types/react": "^18.3.5",
156
156
  "@types/react-dom": "^18.3.0",
157
157
  "algoliasearch": "^4.24.0",
158
- "next": "^14.2.5",
158
+ "next": "^14.2.7",
159
159
  "unified": "^11.0.5",
160
160
  "eslint-config-custom": "0.0.0",
161
161
  "tsconfig": "0.0.0"