Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ docs-kit builds on a stack that your site already uses:

* Node 22 or later.
* A TanStack Start site on Cloudflare Workers, built with Vite and Tailwind CSS 4.
* Fumadocs: `fumadocs-core` and `fumadocs-ui` 16.15.15 or later in version 16, and `fumadocs-mdx` 15.4.5 or later in version 15.
* Fumadocs: `fumadocs-core` and `fumadocs-ui` 16.19.7 or later in version 16, and `fumadocs-mdx` 15.4.7 or later in version 15. Earlier `fumadocs-mdx` releases include a file without recording where its text came from, so the Markdown copy of a page with `<include>` is garbled.

The peer dependencies are `react`, `react-dom`, `fumadocs-core`, `fumadocs-ui`,
`fumadocs-mdx`, `@tanstack/react-router` and `lucide-react`. `posthog-js` is an
Expand Down Expand Up @@ -80,17 +80,21 @@ draws as plain monospace text with no chip.
### Configure the MDX source

In `source.config.ts`, import from `@withmarfa/docs-kit/config`, not from `/mdx`: the config entry reaches Fumadocs's Node-only plugins, and `/mdx` stays free of them so a page can load it in the browser. Use `codeOptions` for code highlighting and
`llmsOptions` to write the Markdown copy of each page. `llmsOptions` already
`llmsCopy` to write the Markdown copy of each page. `llmsCopy` already
writes the kit's own components (`Callout`, `Cards`, `Steps`, `Terminal` and the
others); give it a rewrite for each component that your site adds:
others); give it a rewrite for each component that your site adds. It returns
two parts that work together: the `options` that ask Fumadocs for the copy as
text, and the `plugin` that writes each component, fenced block and table of
the copy. Fumadocs writes the copy from a page's own source, after the remark
plugins have run, so the plugin goes in `remarkPlugins`:

```ts
// source.config.ts
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
import { pageSchema } from 'fumadocs-core/source/schema';
import { codeOptions, llmsOptions, rehypeTableLabels } from '@withmarfa/docs-kit/config';
import { codeOptions, llmsCopy, rehypeTableLabels } from '@withmarfa/docs-kit/config';

const llms = llmsOptions({
const llms = llmsCopy({
// Components whose children are the content: the copy keeps the children.
wrappers: ['ReferenceList'],
// Components that need their own text. Each rewrite returns Markdown.
Expand All @@ -103,18 +107,29 @@ export const docs = defineDocs({
dir: 'content/docs',
docs: {
schema: pageSchema,
postprocess: { includeProcessedMarkdown: llms },
postprocess: { includeProcessedMarkdown: llms.options },
},
});

export default defineConfig({
mdxOptions: {
remarkPlugins: (plugins) => [...plugins, llms.plugin],
rehypePlugins: (plugins) => [...plugins, rehypeTableLabels],
rehypeCodeOptions: codeOptions(),
},
});
```

A rewrite is given the element's `attribute(name)`, its content as Markdown with
`inner()`, and `flow(children)` for nodes you pick from `node.children`. Without
`llms.plugin` in `remarkPlugins`, the copy still builds but keeps every
component as written, so a page's Markdown holds JSX.

The copy writes a fenced block with `tab="..."` as the tab's label in bold, then
the block without its `tab` and `tab-group` attributes. An `npm` or
`package-install` block keeps the fence as written: Fumadocs's own `remarkNpm`
pins the authored block as the page's source, and the copy follows it.

`codeOptions` takes the same options as Fumadocs's `rehypeCodeOptions`, such as
`langs` for a custom grammar. It keeps Fumadocs's notation comments, which
`styles.css` draws: end a line with `// [!code highlight]` for a quiet tint
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@
},
"dependencies": {
"@types/mdx": "^2.0.14",
"mdast-util-gfm-table": "^2.0.0",
"tailwind-merge": "^3.7.0",
"yaml": "2.9.1"
},
"peerDependencies": {
"@tanstack/react-router": ">=1.170.0",
"fumadocs-core": "^16.15.15",
"fumadocs-mdx": "^15.4.5",
"fumadocs-ui": "^16.15.15",
"fumadocs-core": "^16.19.7",
"fumadocs-mdx": "^15.4.7",
"fumadocs-ui": "^16.19.7",
"lucide-react": ">=1.48.0",
"posthog-js": ">=1.434.0",
"react": "^19.3.0",
Expand All @@ -88,9 +87,9 @@
"@types/node": "^26.6.3",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"fumadocs-core": "16.15.15",
"fumadocs-mdx": "15.4.5",
"fumadocs-ui": "16.15.15",
"fumadocs-core": "16.19.8",
"fumadocs-mdx": "15.6.4",
"fumadocs-ui": "16.19.8",
"jsdom": "^31.0.1",
"lucide-react": "^1.48.0",
"posthog-js": "^1.434.16",
Expand Down
Loading