How it works
The content model, the markdown pipeline, and navigation.
Markdown as routes
DocSmith leans on mdsvex, which compiles markdown into real Svelte components. A file becomes a page by its position on disk, with no loader and no catch-all route:
- src
- routes
- docs
- guides
- routing
- +page.md
- routing
- guides
- docs
- routes
The file above serves /docs/guides/routing. Because it is a normal SvelteKit
route, you can drop interactive Svelte components straight into the markdown and
they run as part of the same app.
One name, two plugins
DocSmith ships two things both called docsmith(), imported from two entry
points. They do different jobs:
svelte-docsmith/preprocessis a Svelte preprocessor, added insvelte.config.js. It runs at compile time and turns each.mdfile into a styled, highlighted page (mdsvex, Shiki, heading anchors, the page layout).svelte-docsmith/viteis a Vite plugin, added invite.config.ts. It runs at build time and generates the content index (below) plus the?sourcetransform that powers live examples.
You need both
The preprocessor and the Vite plugin are not interchangeable. The preprocessor renders your pages; the Vite plugin builds the sidebar and live-example source. Register one without the other and either your pages or your navigation goes missing.
Nav is derived, never written
There is no navigation array to maintain. The docsmith() Vite plugin reads
each page’s frontmatter into the svelte-docsmith/content module, and DocsShell groups the entries into the sidebar:
section names the group; order sorts entries within it; groups are ordered
by the smallest order they contain. Add a page, and it slots into the sidebar
in the right place automatically.
Two tables of contents, two jobs
DocSmith keeps two structures, and they never overlap:
- The content index owns build-time structure. The
docsmith()Vite plugin scans frontmatter into the sidebar navigation. - The runtime TOC engine owns in-page scroll tracking. It scans the rendered headings and highlights the section you are reading.
The highlighting pipeline
Code blocks are highlighted by Shiki inside the docsmith() preprocessor, with a generous default language set. Unknown
languages fall back to plain text instead of failing the build:
Highlighting is dual-theme: the same markup carries light and dark colors and flips with the page theme, so your code reads correctly either way.