Skip to content

View as Markdown

The View as Markdown action navigates to the page’s markdown route, where the body is served as text/markdown. The browser shows the page’s markdown — raw source by default, or the flattened output of renderMarkdown if you’ve configured it — useful for confirming what gets copied, what an LLM sees, or just inspecting the canonical markdown of a page.

  • Verifying that the markdown route returns what you expect.
  • Linking someone to the markdown of a docs page.
  • Manual extraction by readers who prefer the markdown to the rendered HTML.

viewMarkdown is on by default. To disable it:

starlightLlmActions({
actions: {
viewMarkdown: false,
},
})

When disabled, the action is removed from the dropdown.

The action is a plain anchor (<a href>) under the hood. Clicking it navigates to the URL produced by markdownUrl (default /{slug}.md), which the plugin’s injected route serves as text/markdown; charset=utf-8. The body is the matching Content Collection entry’s, either as authored or flattened, depending on renderMarkdown.

Browsers display text/markdown as plain text. There’s no fallback rendering inside the docs site — the user sees exactly what an LLM, fetcher, or script would see at that URL.

That header is the dev-server story. On a static build the route is prerendered to a file and the header goes with it, so what a reader actually receives is whatever your host says about a .md file. Getting the charset wrong there turns every smart quote on the page into mojibake. See Deployment.

View as Markdown only appears on pages that have a Markdown route to point at. A page outside every collection named in collections gets no .md file, so the item is dropped rather than linking to a 404. A page your own route file renders with <StarlightPage> is the usual case. Copy as Markdown goes with it; the Open in… providers stay, falling back to the page’s own URL.

Use markdownUrl to change the path pattern, e.g. to serve under .txt:

starlightLlmActions({
markdownUrl: '/{slug}.txt',
})
  • Copy as Markdown — copies the same content to the clipboard instead of navigating.
  • injectRoute — opt out of the plugin’s built-in markdown route if your site already publishes per-page markdown.