@vercel/geistdocs 2.15.1 → 2.15.3-canary.633944d

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.
Files changed (37) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/internal/search-ranking.d.ts +45 -0
  3. package/dist/internal/search-ranking.d.ts.map +1 -0
  4. package/dist/internal/search-ranking.js +186 -0
  5. package/dist/next.d.ts +9 -1
  6. package/dist/next.d.ts.map +1 -1
  7. package/dist/next.js +25 -2
  8. package/dist/routes/search.d.ts.map +1 -1
  9. package/dist/routes/search.js +80 -4
  10. package/dist/source-config.d.ts +10 -1
  11. package/dist/source-config.d.ts.map +1 -1
  12. package/dist/source-config.js +20 -10
  13. package/docs/agents.md +1 -1
  14. package/docs/llms.txt +24 -1
  15. package/docs/manifest.json +1 -1
  16. package/docs/pages/configuration.md +8 -0
  17. package/docs/pages/provider.md +15 -0
  18. package/native-mdx/LICENSE-mdxjs-rs +22 -0
  19. package/native-mdx/binaries/darwin-arm64.node +0 -0
  20. package/native-mdx/binaries/linux-x64-gnu.node +0 -0
  21. package/native-mdx/loader-mdx.cjs +9 -0
  22. package/native-mdx/loader-mdx.mjs +216 -0
  23. package/native-mdx/native-binding.cjs +25 -0
  24. package/package.json +15 -8
  25. package/rehype-code-highlights.d.ts +13 -0
  26. package/rehype-code-highlights.js +230 -0
  27. package/source-config.js +24 -10
  28. package/template/app/[lang]/(home)/opengraph-image.tsx +4 -28
  29. package/template/app/[lang]/og/[...slug]/route.tsx +5 -68
  30. package/template/content/docs/configuration.mdx +8 -0
  31. package/template/content/docs/provider.mdx +15 -0
  32. package/template/lib/geistdocs/geist-mono-regular.ttf +0 -0
  33. package/template/lib/geistdocs/og.tsx +95 -0
  34. package/template/package.json +1 -1
  35. package/template/app/[lang]/og/[...slug]/background.png +0 -0
  36. package/template/app/[lang]/og/[...slug]/geist-sans-semibold.ttf +0 -0
  37. /package/template/{app/[lang]/og/[...slug] → lib/geistdocs}/geist-sans-regular.ttf +0 -0
@@ -50,6 +50,21 @@ const Layout = ({ children }: LayoutProps) => (
50
50
 
51
51
  The generated local adapter imports the package provider and passes your site config to it.
52
52
 
53
+ ## Search relevance
54
+
55
+ `createSearchRoute` ranks pages before selecting their matching sections. Exact page titles come first, followed by exact `keywords` aliases. These matches retain every query word, so `use cache` ranks ahead of `Cache` for that query. They precede matches with English filler words removed and full-page matches weighted toward titles, keywords, and descriptions. Section overview pages use their navigation folder name instead of the generic “Overview” title. Lower-priority English matching ignores common filler words such as “how to” and “using”; other locales keep their existing tokenizers.
56
+
57
+ Add a small set of search phrases to the canonical page's frontmatter:
58
+
59
+ ```yaml
60
+ title: Generating Structured Data
61
+ keywords:
62
+ - structured output
63
+ - structured outputs
64
+ ```
65
+
66
+ Use phrases readers actually search for, and assign each alias to its canonical page. Avoid copying the same keywords onto every related page. English results must cover the whole query; if no page covers it, partial section matches remain available. Results contain at most 20 pages and two distinct matching snippets per page, retaining section links and breadcrumbs. Locale, visibility, and `filterPage` restrictions still apply.
67
+
53
68
  ## Search scope
54
69
 
55
70
  A search index partitioned by version, section, or product usually wants the dialog to answer from the partition the reader is in. Pass that scope as `search.options.tag`:
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2022 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // CommonJS entry for Turbopack/webpack, like fumadocs-mdx's own shim.
3
+ module.exports = function loader(source) {
4
+ const callback = this.async();
5
+ import("./loader-mdx.mjs").then(
6
+ (mod) => mod.run.call(this, source, callback),
7
+ callback
8
+ );
9
+ };
@@ -0,0 +1,216 @@
1
+ // Webpack/Turbopack loader for MDX, backed by the native fumadocs-mdx-rs
2
+ // compiler. Mirrors fumadocs-mdx's `createMdxLoader`: config, collection,
3
+ // frontmatter validation, and doc plugins stay in JS (they're user code);
4
+ // parsing, transforms, highlighting, and codegen run natively. Files that
5
+ // use something the native pipeline doesn't cover go to fumadocs-mdx.
6
+ import { createRequire } from "node:module";
7
+ import path from "node:path";
8
+ import { pathToFileURL } from "node:url";
9
+
10
+ // fumadocs-mdx 14.0.4 internals (not in its public exports).
11
+ const fumadocsDist = path.dirname(
12
+ new URL(import.meta.resolve("fumadocs-mdx")).pathname
13
+ );
14
+ const internal = (chunk) =>
15
+ import(pathToFileURL(path.join(fumadocsDist, chunk)).href);
16
+ const { fumaMatter } = await internal("chunk-VWJKRQZR.js");
17
+ const { getCore } = await internal("chunk-CGGDM5F3.js");
18
+ const { createStandaloneConfigLoader } = await internal("chunk-NKIL543T.js");
19
+
20
+ const require = createRequire(import.meta.url);
21
+ const native = require(
22
+ process.env.FUMADOCS_MDX_RS_BINARY ?? "./native-binding.cjs"
23
+ );
24
+
25
+ let configLoader;
26
+ let jsLoader;
27
+ const compatibility = new Map();
28
+
29
+ // The plugin list the native pipeline implements: Geistdocs' defaults with
30
+ // Highlights (`defineGeistdocsSourceConfig()`), in fumadocs-mdx's order.
31
+ const NATIVE_REMARK = [
32
+ ["remarkGfm"],
33
+ ["remarkSteps"],
34
+ ["remarkHeading", { generateToc: false }],
35
+ ["remarkImage", { useImport: true }],
36
+ ["remarkCodeTab"],
37
+ ["remarkNpm"],
38
+ ["remarkMdxMermaid"],
39
+ ["remarkDetails"],
40
+ ["remarkStructure", { exportAs: "structuredData" }],
41
+ ];
42
+ const NATIVE_REHYPE = [
43
+ ["rehypeCodeHighlights"],
44
+ ["rehypeTaskListLabels"],
45
+ ["rehypeToc"],
46
+ ];
47
+ const NATIVE_OPTION_KEYS = new Set([
48
+ "remarkPlugins",
49
+ "rehypePlugins",
50
+ "outputFormat",
51
+ ]);
52
+
53
+ const samePlugins = (actual, expected) =>
54
+ actual.length === expected.length &&
55
+ actual.every((entry, index) => {
56
+ const [plugin, options] = Array.isArray(entry) ? entry : [entry];
57
+ const [name, expectedOptions] = expected[index];
58
+ if (plugin?.name !== name) {
59
+ return false;
60
+ }
61
+ if (name === "rehypeCodeHighlights") {
62
+ // Geistdocs forces the theme; any other option changes the output.
63
+ return Object.keys(options ?? {}).every(
64
+ (key) => key === "themes" || key === "defaultColor"
65
+ );
66
+ }
67
+ return (
68
+ JSON.stringify(options ?? {}) === JSON.stringify(expectedOptions ?? {})
69
+ );
70
+ });
71
+
72
+ /** Why a collection's MDX options need the JS pipeline, if they do. */
73
+ async function incompatibility(config, collection) {
74
+ const key = collection?.name ?? "global";
75
+ if (!compatibility.has(key)) {
76
+ const options = await config.getMDXOptions(collection, "bundler");
77
+ let reason = null;
78
+ const extraKeys = Object.keys(options).filter(
79
+ (k) => !NATIVE_OPTION_KEYS.has(k)
80
+ );
81
+ if (extraKeys.length > 0) {
82
+ reason = `MDX options: ${extraKeys.join(", ")}`;
83
+ } else if (!samePlugins(options.remarkPlugins ?? [], NATIVE_REMARK)) {
84
+ reason = "custom remark plugins";
85
+ } else if (!samePlugins(options.rehypePlugins ?? [], NATIVE_REHYPE)) {
86
+ reason = "custom rehype plugins or Shiki";
87
+ }
88
+ compatibility.set(key, reason);
89
+ }
90
+ return compatibility.get(key);
91
+ }
92
+
93
+ /** The doc collection behind a `doc` or `docs` collection. */
94
+ const docCollectionOf = (collection) => {
95
+ if (collection?.type === "doc") {
96
+ return collection;
97
+ }
98
+ if (collection?.type === "docs") {
99
+ return collection.docs;
100
+ }
101
+ };
102
+
103
+ async function fallback({ source, development, query, compiler, filePath }) {
104
+ jsLoader ??= (await internal("chunk-USWQVJWR.js")).createMdxLoader(
105
+ configLoader
106
+ );
107
+ const out = await jsLoader.load({
108
+ getSource: () => source,
109
+ development,
110
+ query,
111
+ compiler,
112
+ filePath,
113
+ });
114
+ return out.code;
115
+ }
116
+
117
+ const literal = (value) => {
118
+ if (value instanceof Date) {
119
+ return `new Date(${JSON.stringify(value.toISOString())})`;
120
+ }
121
+ if (value === undefined) {
122
+ return "undefined";
123
+ }
124
+ return JSON.stringify(value);
125
+ };
126
+
127
+ export async function load({
128
+ source,
129
+ filePath,
130
+ query,
131
+ development,
132
+ compiler,
133
+ options,
134
+ }) {
135
+ configLoader ??= createStandaloneConfigLoader({
136
+ core: getCore(options),
137
+ buildConfig: false,
138
+ mode: development ? "dev" : "production",
139
+ });
140
+ const core = configLoader.core;
141
+ const config = await configLoader.getConfig();
142
+ const matter = fumaMatter(source);
143
+ const collection = query.collection
144
+ ? config.getCollection(query.collection)
145
+ : undefined;
146
+ const docCollection = docCollectionOf(collection);
147
+ if (docCollection) {
148
+ matter.data = await core.transformFrontmatter(
149
+ { collection: docCollection, filePath, source },
150
+ matter.data
151
+ );
152
+ }
153
+ if (query.only === "frontmatter") {
154
+ return `export const frontmatter = ${JSON.stringify(matter.data)}`;
155
+ }
156
+
157
+ if (await incompatibility(config, docCollection)) {
158
+ return fallback({ source, development, query, compiler, filePath });
159
+ }
160
+
161
+ const result = native.compile(
162
+ matter.content,
163
+ JSON.stringify(matter.data ?? {}),
164
+ {
165
+ filePath,
166
+ includeProcessedMarkdown:
167
+ docCollection?.postprocess?.includeProcessedMarkdown === true,
168
+ development,
169
+ }
170
+ );
171
+ if (result.fallback) {
172
+ return fallback({ source, development, query, compiler, filePath });
173
+ }
174
+
175
+ // Doc plugins (e.g. last-modified) contribute extra exports.
176
+ let code = result.code;
177
+ if (docCollection) {
178
+ const file = await core.transformVFile(
179
+ { collection: docCollection, filePath, source },
180
+ { data: {}, path: filePath, value: source }
181
+ );
182
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
183
+ code += `\nexport let ${name} = ${literal(value)};`;
184
+ }
185
+ }
186
+ return code;
187
+ }
188
+
189
+ /** Webpack loader entry. */
190
+ export default function loader(source) {
191
+ return run.call(this, source, this.async());
192
+ }
193
+
194
+ /** Loader body with an explicit callback (used by the CJS shim). */
195
+ export async function run(source, callback) {
196
+ const options = this.getOptions();
197
+ this.cacheable(true);
198
+ this.addDependency(options.absoluteCompiledConfigPath);
199
+ try {
200
+ const query = Object.fromEntries(
201
+ new URLSearchParams(this.resourceQuery.slice(1))
202
+ );
203
+ const code = await load({
204
+ source,
205
+ filePath: this.resourcePath,
206
+ query,
207
+ development: this.mode === "development",
208
+ compiler: this,
209
+ options,
210
+ });
211
+ callback(undefined, code);
212
+ } catch (error) {
213
+ error.message = `${path.relative(this.context, this.resourcePath)}: ${error.message}`;
214
+ callback(error);
215
+ }
216
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const { existsSync } = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const local = path.join(__dirname, "fumadocs-mdx-rs.node");
7
+ const platform = `${process.platform}-${process.arch}${process.platform === "linux" ? "-gnu" : ""}`;
8
+ const bundled = path.join(__dirname, "binaries", `${platform}.node`);
9
+
10
+ if (existsSync(local)) {
11
+ module.exports = require(local);
12
+ } else {
13
+ if (
14
+ !existsSync(bundled) ||
15
+ (process.platform === "linux" &&
16
+ !process.report.getReport().header.glibcVersionRuntime)
17
+ ) {
18
+ throw new Error(
19
+ `This Geistdocs native MDX canary has no binary for ${platform}. ` +
20
+ "Supported: macOS arm64 and Linux x64 (glibc). " +
21
+ "Remove experimentalMdxLoader to use the JS compiler."
22
+ );
23
+ }
24
+ module.exports = require(bundled);
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vercel/geistdocs",
3
3
  "description": "Runtime and CLI for Geistdocs projects.",
4
- "version": "2.15.1",
4
+ "version": "2.15.3-canary.633944d",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,6 +27,8 @@
27
27
  "cli.js",
28
28
  "dist",
29
29
  "docs",
30
+ "rehype-code-highlights.d.ts",
31
+ "rehype-code-highlights.js",
30
32
  "rehype-task-list-labels.d.ts",
31
33
  "rehype-task-list-labels.js",
32
34
  "remark-details.d.ts",
@@ -37,7 +39,8 @@
37
39
  "shared-theme.css",
38
40
  "styles.css",
39
41
  "theme.css",
40
- "LICENSE"
42
+ "LICENSE",
43
+ "native-mdx"
41
44
  ],
42
45
  "exports": {
43
46
  "./changelog": {
@@ -299,7 +302,12 @@
299
302
  },
300
303
  "./styles.css": "./styles.css",
301
304
  "./theme.css": "./theme.css",
302
- "./package.json": "./package.json"
305
+ "./package.json": "./package.json",
306
+ "./native-mdx": "./native-mdx/loader-mdx.cjs"
307
+ },
308
+ "scripts": {
309
+ "build": "rm -rf dist docs template && node ./scripts/bundle-template.mjs && node ./scripts/bundle-docs.mjs && tsc -p tsconfig.runtime.json && tsup --config tsup.config.cli.ts",
310
+ "dev": "tsc -p tsconfig.runtime.json --watch --preserveWatchOutput"
303
311
  },
304
312
  "dependencies": {
305
313
  "@ai-sdk/react": "^3.0.134",
@@ -307,6 +315,8 @@
307
315
  "@modelcontextprotocol/server": "^2.0.0",
308
316
  "@next/env": "16.3.3",
309
317
  "@orama/tokenizers": "^3.1.16",
318
+ "@pierre/highlights": "0.5.1",
319
+ "@shikijs/rehype": "3.19.0",
310
320
  "@streamdown/cjk": "^1.0.1",
311
321
  "@types/mdx": "^2.0.13",
312
322
  "@types/react": "^19.2.7",
@@ -335,6 +345,7 @@
335
345
  "remark-mdx": "^3.1.1",
336
346
  "remark-parse": "^11.0.0",
337
347
  "remark-stringify": "^11.0.0",
348
+ "shiki": "3.19.0",
338
349
  "sonner": "^2.0.8",
339
350
  "streamdown": "^2.1.0",
340
351
  "tailwind-merge": "^3.4.0",
@@ -364,9 +375,5 @@
364
375
  "react-dom": "^19.2.3",
365
376
  "tsup": "^8.5.1",
366
377
  "typescript": "^5.9.3"
367
- },
368
- "scripts": {
369
- "build": "rm -rf dist docs template && node ./scripts/bundle-template.mjs && node ./scripts/bundle-docs.mjs && tsc -p tsconfig.runtime.json && tsup --config tsup.config.cli.ts",
370
- "dev": "tsc -p tsconfig.runtime.json --watch --preserveWatchOutput"
371
378
  }
372
- }
379
+ }
@@ -0,0 +1,13 @@
1
+ import type { RehypeCodeOptions } from "fumadocs-core/mdx-plugins";
2
+ import type { Root } from "hast";
3
+
4
+ /** Zed-format Geist theme for @pierre/highlights, using Geist's Shiki CSS variables. */
5
+ export declare const geistHighlightsTheme: Record<string, unknown>;
6
+
7
+ /**
8
+ * Experimental drop-in for Fumadocs' `rehypeCode` that tokenizes with
9
+ * @pierre/highlights while keeping Shiki's HAST output and transformers.
10
+ */
11
+ export declare const rehypeCodeHighlights: (
12
+ options?: Partial<RehypeCodeOptions>
13
+ ) => (tree: Root, file: unknown) => Promise<void>;
@@ -0,0 +1,230 @@
1
+ import { codeToTokens, isSupportedLanguage } from "@pierre/highlights";
2
+ import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
3
+ import {
4
+ rehypeCodeDefaultOptions,
5
+ transformerIcon,
6
+ transformerTab,
7
+ } from "fumadocs-core/mdx-plugins";
8
+ import { tokensToHast, transformerDecorations } from "shiki/core";
9
+
10
+ // Experimental: highlights code blocks with @pierre/highlights (hand-written
11
+ // Wasm lexers) instead of Shiki's TextMate grammars, while keeping Shiki's
12
+ // HAST output and transformer pipeline so Fumadocs' code block features
13
+ // (titles, icons, tabs, line notation, diffs, focus) keep working.
14
+
15
+ const v = (name) => `token-${name}`;
16
+
17
+ // Maps Highlights' Zed token names onto the same CSS variables the Geist
18
+ // Shiki theme uses (see `geistShikiTheme`), so the existing palette applies.
19
+ // With a `cssVariables` palette, colors are variable suffixes: `token-keyword`
20
+ // renders as `var(--shiki-token-keyword)`.
21
+ export const geistHighlightsTheme = {
22
+ name: "geist",
23
+ appearance: "light",
24
+ cssVariables: {
25
+ prefix: "--shiki-",
26
+ defaults: { "color-text": "inherit", "color-background": "transparent" },
27
+ },
28
+ style: {
29
+ "editor.foreground": "color-text",
30
+ "editor.background": "color-background",
31
+ syntax: {
32
+ comment: v("comment"),
33
+ "comment.doc": v("comment"),
34
+ "keyword.jsdoc": v("comment"),
35
+ "type.jsdoc": v("comment"),
36
+ "variable.jsdoc": v("comment"),
37
+ constant: v("constant"),
38
+ "constant.builtin": v("constant"),
39
+ boolean: v("constant"),
40
+ number: v("constant"),
41
+ enum: v("constant"),
42
+ "variable.special": v("constant"),
43
+ function: v("function"),
44
+ "function.definition": v("function"),
45
+ "function.method": v("function"),
46
+ constructor: v("function"),
47
+ type: v("function"),
48
+ "type.class": v("function"),
49
+ tag: v("function"),
50
+ "tag.jsx": v("function"),
51
+ "tag.component.jsx": v("function"),
52
+ "tag.doctype": v("function"),
53
+ title: v("function"),
54
+ namespace: v("function"),
55
+ selector: v("function"),
56
+ "selector.class": v("function"),
57
+ "selector.id": v("function"),
58
+ "selector.pseudo": v("function"),
59
+ attribute: v("constant"),
60
+ "attribute.jsx": v("constant"),
61
+ "variable.parameter": v("parameter"),
62
+ property: v("parameter"),
63
+ "property.json_key": v("parameter"),
64
+ label: v("parameter"),
65
+ "text.jsx": v("parameter"),
66
+ "punctuation.list_marker": v("parameter"),
67
+ keyword: v("keyword"),
68
+ "keyword.control": v("keyword"),
69
+ "keyword.declaration": v("keyword"),
70
+ "keyword.import": v("keyword"),
71
+ "keyword.operator": v("keyword"),
72
+ operator: v("keyword"),
73
+ preproc: v("keyword"),
74
+ string: v("string"),
75
+ "string.escape": v("string"),
76
+ "string.special": v("string"),
77
+ "string.special.symbol": v("string"),
78
+ "text.literal": v("string"),
79
+ "string.regex": v("string-expression"),
80
+ punctuation: v("punctuation"),
81
+ "punctuation.bracket": v("punctuation"),
82
+ "punctuation.delimiter": v("punctuation"),
83
+ "punctuation.special": v("keyword"),
84
+ "punctuation.markup": v("punctuation"),
85
+ "punctuation.bracket.html": v("parameter"),
86
+ "punctuation.bracket.jsx": v("parameter"),
87
+ "punctuation.delimiter.html": v("parameter"),
88
+ "punctuation.delimiter.jsx": v("parameter"),
89
+ link_uri: v("link"),
90
+ link_text: v("parameter"),
91
+ },
92
+ },
93
+ };
94
+
95
+ // Fenced-code names that Highlights doesn't know but Shiki users write.
96
+ const LANG_ALIASES = {
97
+ plaintext: "plain",
98
+ txt: "plain",
99
+ "": "plain",
100
+ };
101
+
102
+ const resolveLang = (lang) => {
103
+ const name = LANG_ALIASES[lang] ?? lang ?? "plain";
104
+ return isSupportedLanguage(name) ? name : "plain";
105
+ };
106
+
107
+ const TRAILING_NEWLINE = /\n$/;
108
+
109
+ const ENFORCE_ORDER = { pre: 0, undefined: 1, post: 2 };
110
+
111
+ const getTransformers = (options) => [
112
+ ...[...(options.transformers ?? [])].sort(
113
+ (a, b) => ENFORCE_ORDER[a.enforce] - ENFORCE_ORDER[b.enforce]
114
+ ),
115
+ transformerDecorations(),
116
+ ];
117
+
118
+ const UNSTYLED = "var(--shiki-foreground)";
119
+
120
+ const tokenize = (code, options) => {
121
+ const result = codeToTokens(code, {
122
+ lang: resolveLang(options.lang),
123
+ themes: { light: geistHighlightsTheme },
124
+ defaultColor: "light",
125
+ cssVariablePrefix: "--shiki-",
126
+ });
127
+ // Highlights colors unstyled runs with `var(--shiki-foreground)`; Shiki uses
128
+ // the theme foreground, which Geist defines as `--shiki-color-text`.
129
+ for (const line of result.tokens) {
130
+ for (const token of line) {
131
+ if (token.htmlStyle?.color === UNSTYLED) {
132
+ token.htmlStyle = { ...token.htmlStyle, color: result.fg };
133
+ }
134
+ }
135
+ }
136
+ return {
137
+ tokens: result.tokens,
138
+ fg: result.fg,
139
+ bg: result.bg,
140
+ themeName: "shiki-themes geist",
141
+ };
142
+ };
143
+
144
+ /**
145
+ * A minimal Shiki highlighter: enough of the API for `@shikijs/rehype/core`.
146
+ * Mirrors Shiki's `codeToHast` (preprocess → tokens → token transformers →
147
+ * `tokensToHast`), swapping the tokenizer for Highlights.
148
+ */
149
+ export const highlightsShikiAdapter = {
150
+ getLoadedLanguages: () => [],
151
+ loadLanguage: async () => undefined,
152
+ codeToTokens: (code, options) => tokenize(code, options),
153
+ codeToHast(code, options) {
154
+ const transformers = getTransformers(options);
155
+ const context = {
156
+ meta: {},
157
+ options,
158
+ codeToHast: (c, o) => highlightsShikiAdapter.codeToHast(c, o),
159
+ codeToTokens: (c, o) => tokenize(c, o),
160
+ };
161
+
162
+ let input = code;
163
+ for (const transformer of transformers) {
164
+ input = transformer.preprocess?.call(context, input, options) || input;
165
+ }
166
+
167
+ let { tokens, fg, bg, themeName } = tokenize(input, options);
168
+ const contextSource = {
169
+ ...context,
170
+ get source() {
171
+ return input;
172
+ },
173
+ };
174
+ for (const transformer of transformers) {
175
+ tokens = transformer.tokens?.call(contextSource, tokens) || tokens;
176
+ }
177
+
178
+ return tokensToHast(
179
+ tokens,
180
+ {
181
+ ...options,
182
+ fg,
183
+ bg,
184
+ themeName,
185
+ transformers: options.transformers,
186
+ },
187
+ contextSource
188
+ );
189
+ },
190
+ };
191
+
192
+ /** Drop-in for Fumadocs' `rehypeCode`, backed by @pierre/highlights. */
193
+ export const rehypeCodeHighlights = (userOptions = {}) => {
194
+ const options = { ...rehypeCodeDefaultOptions, ...userOptions };
195
+ const transformers = [...(options.transformers ?? [])];
196
+
197
+ // Same preprocessing as Fumadocs' rehypeCode.
198
+ transformers.unshift({
199
+ name: "rehype-code:pre-process",
200
+ preprocess(code, { meta }) {
201
+ if (meta && "__parsed_raw" in meta) {
202
+ meta.__raw = meta.__parsed_raw;
203
+ // biome-ignore lint/performance/noDelete: matches Fumadocs.
204
+ delete meta.__parsed_raw;
205
+ }
206
+ if (meta && options.filterMetaString) {
207
+ meta.__raw = options.filterMetaString(meta.__raw ?? "");
208
+ }
209
+ return code.replace(TRAILING_NEWLINE, "");
210
+ },
211
+ });
212
+ if (options.icon !== false) {
213
+ transformers.push(transformerIcon(options.icon));
214
+ }
215
+ if (options.tab !== false) {
216
+ transformers.push(transformerTab());
217
+ }
218
+
219
+ // `lazy` routes every language through `loadLanguage`, which is a no-op:
220
+ // Highlights bundles its lexers and unknown languages fall back to plain.
221
+ const transformer = rehypeShikiFromHighlighter(highlightsShikiAdapter, {
222
+ ...options,
223
+ lazy: true,
224
+ transformers,
225
+ });
226
+
227
+ return async (tree, file) => {
228
+ await transformer(tree, file, () => undefined);
229
+ };
230
+ };
package/source-config.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  } from "fumadocs-mdx/config";
16
16
  import lastModified from "fumadocs-mdx/plugins/last-modified";
17
17
  import { z } from "zod";
18
+ import { rehypeCodeHighlights } from "./rehype-code-highlights.js";
18
19
  import { rehypeTaskListLabels } from "./rehype-task-list-labels.js";
19
20
  import { remarkDetails } from "./remark-details.js";
20
21
 
@@ -276,11 +277,18 @@ export const resolveGeistdocsRemarkPlugins = (
276
277
  // Mirrors src/source-config.ts. Geistdocs rehype plugins run after the
277
278
  // consumer's: an array is handed to Fumadocs, which places it among its
278
279
  // defaults; a function receives those defaults and returns the final list.
279
- export const resolveGeistdocsRehypePlugins = (consumerPlugins) => {
280
+ export const resolveGeistdocsRehypePlugins = (
281
+ consumerPlugins,
282
+ leadingPlugins = []
283
+ ) => {
280
284
  if (typeof consumerPlugins === "function") {
281
- return (defaults) => [...consumerPlugins(defaults), rehypeTaskListLabels];
285
+ return (defaults) => [
286
+ ...leadingPlugins,
287
+ ...consumerPlugins(defaults),
288
+ rehypeTaskListLabels,
289
+ ];
282
290
  }
283
- return [...(consumerPlugins ?? []), rehypeTaskListLabels];
291
+ return [...leadingPlugins, ...(consumerPlugins ?? []), rehypeTaskListLabels];
284
292
  };
285
293
 
286
294
  export const defineGeistdocsSourceConfig = (config = {}) => {
@@ -288,21 +296,27 @@ export const defineGeistdocsSourceConfig = (config = {}) => {
288
296
  ? config.mdxOptions.remarkPlugins
289
297
  : [];
290
298
  const existingPlugins = Array.isArray(config.plugins) ? config.plugins : [];
299
+ const { highlighter = "highlights", ...fumadocsConfig } = config;
300
+ const rehypeCodeOptions = {
301
+ ...config.mdxOptions?.rehypeCodeOptions,
302
+ themes: { light: geistShikiTheme },
303
+ defaultColor: "light",
304
+ };
305
+ // `highlights` swaps Shiki's tokenizer for @pierre/highlights; `shiki`
306
+ // keeps Fumadocs' rehypeCode.
307
+ const useHighlights = highlighter === "highlights";
291
308
 
292
309
  return defineFumadocsConfig({
293
- ...config,
310
+ ...fumadocsConfig,
294
311
  mdxOptions: {
295
312
  ...config.mdxOptions,
296
313
  remarkPlugins: (defaults) =>
297
314
  resolveGeistdocsRemarkPlugins(defaults, existingRemarkPlugins),
298
315
  rehypePlugins: resolveGeistdocsRehypePlugins(
299
- config.mdxOptions?.rehypePlugins
316
+ config.mdxOptions?.rehypePlugins,
317
+ useHighlights ? [[rehypeCodeHighlights, rehypeCodeOptions]] : []
300
318
  ),
301
- rehypeCodeOptions: {
302
- ...config.mdxOptions?.rehypeCodeOptions,
303
- themes: { light: geistShikiTheme },
304
- defaultColor: "light",
305
- },
319
+ rehypeCodeOptions: useHighlights ? false : rehypeCodeOptions,
306
320
  },
307
321
  plugins: [
308
322
  lastModified({ versionControl: getLastModified }),