Types overview

import type { function sveltekit(config?: KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">): Promise<Plugin[]>

Returns the SvelteKit Vite plugins. Since version 2.62.0 you can pass configuration directly, in which case svelte.config.js is ignored. Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte.

sveltekit
} from '@sveltejs/kit/vite'
import type { import BundledLanguageBundledLanguage } from 'shiki/langs' import type { import PluginPlugin } from 'unified' import type {
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
} from 'vite'
/** * The options accepted by SvelteKit's `sveltekit()` vite plugin. * * On the newer SvelteKit project layout there is no `svelte.config.js` and all * config (`compilerOptions`, `adapter`, ...) is passed inline to `sveltekit()` * in `vite.config.ts`. Forward those options through `sveltepress()` so the * standalone `sveltekit()` plugin can be removed (having both crashes the dev * server with duplicated Svelte compilation). */ export type type SvelteKitOptions = (KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">) | undefined

The options accepted by SvelteKit's sveltekit() vite plugin.

On the newer SvelteKit project layout there is no svelte.config.js and all config (compilerOptions, adapter, ...) is passed inline to sveltekit() in vite.config.ts. Forward those options through sveltepress() so the standalone sveltekit() plugin can be removed (having both crashes the dev server with duplicated Svelte compilation).

SvelteKitOptions
= type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never

Obtain the parameters of a function type in a tuple

Parameters
<typeof function sveltekit(config?: KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">): Promise<Plugin[]>

Returns the SvelteKit Vite plugins. Since version 2.62.0 you can pass configuration directly, in which case svelte.config.js is ignored. Any options that don't belong to SvelteKit are passed through to vite-plugin-svelte.

sveltekit
>[0]
export type type RemarkLiveCode = Plugin<[], any>RemarkLiveCode = import PluginPlugin<[], any> export type type Highlighter = (code: string, lang: BundledLanguage, meta?: string) => string | Promise<string>Highlighter = (code: stringcode: string, lang: BundledLanguagelang: import BundledLanguageBundledLanguage, meta: string | undefinedmeta?: string) => string | interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string>
export type type ThemeVitePlugins = PluginOption[] | ((corePlugin: PluginOption) => Promise<PluginOption[]>) | ((corePlugin: PluginOption) => PluginOption[])ThemeVitePlugins =
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
[] | ((corePlugin: PluginOptioncorePlugin:
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
) => interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
[]>) | ((corePlugin: PluginOptioncorePlugin:
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
) =>
type PluginOption = Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[] | Promise<Plugin<any> | {
    name: string;
} | FalsyPlugin | PluginOption[]>
PluginOption
[])
export interface SiteConfig { SiteConfig.title?: string | undefinedtitle?: string SiteConfig.description?: string | undefineddescription?: string } export interface ResolvedTheme { ResolvedTheme.name: stringname: string ResolvedTheme.globalLayout: stringglobalLayout: string ResolvedTheme.pageLayout: stringpageLayout: string ResolvedTheme.vitePlugins: ThemeVitePluginsvitePlugins: type ThemeVitePlugins = PluginOption[] | ((corePlugin: PluginOption) => Promise<PluginOption[]>) | ((corePlugin: PluginOption) => PluginOption[])ThemeVitePlugins ResolvedTheme.highlighter: Highlighterhighlighter: type Highlighter = (code: string, lang: BundledLanguage, meta?: string) => string | Promise<string>Highlighter ResolvedTheme.remarkPlugins?: Plugin[] | undefinedremarkPlugins?: import PluginPlugin[] ResolvedTheme.rehypePlugins?: Plugin[] | undefinedrehypePlugins?: import PluginPlugin[] /** * The footnote label used for [remark rehype](https://github.com/remarkjs/remark-rehype#api) */ ResolvedTheme.footnoteLabel?: string | undefined

The footnote label used for remark rehype

footnoteLabel
?: string
/** Receive the core version configuration before theme plugins are resolved. */ ResolvedTheme.configureVersions?: ((versions: VersionPluginOptions) => void) | undefined

Receive the core version configuration before theme plugins are resolved.

configureVersions
?: (
versions: false | {
    manifest?: string;
} | undefined
versions
:
type VersionPluginOptions = false | {
    manifest?: string;
} | undefined
VersionPluginOptions
) => void
} export type
type VersionPluginOptions = false | {
    manifest?: string;
} | undefined
VersionPluginOptions
= SveltepressVitePluginOptions['versions']
export type type RemarkPluginsOrderer = (themeRemarkPlugins: Plugin[]) => Plugin[]RemarkPluginsOrderer = ((themeRemarkPlugins: Plugin[]themeRemarkPlugins: import PluginPlugin[]) => import PluginPlugin[]) export type type RehypePluginsOrderer = (themeRehypePlugins: Plugin[]) => Plugin[]RehypePluginsOrderer = ((themeRehypePlugins: Plugin[]themeRehypePlugins: import PluginPlugin[]) => import PluginPlugin[]) export interface PageInfo { PageInfo.title: stringtitle: string PageInfo.routePath: stringroutePath: string PageInfo.content: stringcontent: string PageInfo.frontmatter: Record<string, unknown>frontmatter: type Record<K extends keyof any, T> = { [P in K]: T; }

Construct a type with a set of properties K of type T

Record
<string, unknown>
} /** * A single locale of a multi-locale site. Keyed by its URL prefix (`'/'` for * the default locale, `'/zh/'`, `'/bn/'`, ...). */ export interface interface LocaleConfig<ThemeOptions = any>

A single locale of a multi-locale site. Keyed by its URL prefix ('/' for the default locale, '/zh/', '/bn/', ...).

LocaleConfig
<function (type parameter) ThemeOptions in LocaleConfig<ThemeOptions = any>ThemeOptions = any> {
/** BCP 47 language tag, e.g. `'en'`, `'zh-CN'`, `'bn'`. */ LocaleConfig<ThemeOptions = any>.lang: string

BCP 47 language tag, e.g. 'en', 'zh-CN', 'bn'.

lang
: string
/** User-facing label rendered in the language switcher. */ LocaleConfig<ThemeOptions = any>.label: string

User-facing label rendered in the language switcher.

label
: string
/** The locale's full theme options. */ LocaleConfig<ThemeOptions = any>.theme: ThemeOptions = any

The locale's full theme options.

theme
: function (type parameter) ThemeOptions in LocaleConfig<ThemeOptions = any>ThemeOptions
/** * Logical routes available in this locale (no locale prefix). Populated by * the core plugin from the routes directory; only needed explicitly when * constructing configs directly. */ LocaleConfig<ThemeOptions = any>.routes?: string[] | undefined

Logical routes available in this locale (no locale prefix). Populated by the core plugin from the routes directory; only needed explicitly when constructing configs directly.

routes
?: string[]
} /** Multi-locale site configuration keyed by URL prefix. */ export type
type LocalesConfig<ThemeOptions = any> = {
    [x: string]: LocaleConfig<ThemeOptions>;
}

Multi-locale site configuration keyed by URL prefix.

LocalesConfig
<function (type parameter) ThemeOptions in type LocalesConfig<ThemeOptions = any>ThemeOptions = any> = type Record<K extends keyof any, T> = { [P in K]: T; }

Construct a type with a set of properties K of type T

Record
<string, interface LocaleConfig<ThemeOptions = any>

A single locale of a multi-locale site. Keyed by its URL prefix ('/' for the default locale, '/zh/', '/bn/', ...).

LocaleConfig
<function (type parameter) ThemeOptions in type LocalesConfig<ThemeOptions = any>ThemeOptions>>
/** A locale resolved from a route: the locale config plus its matched prefix. */ export interface interface ResolvedLocale<ThemeOptions = any>

A locale resolved from a route: the locale config plus its matched prefix.

ResolvedLocale
<function (type parameter) ThemeOptions in ResolvedLocale<ThemeOptions = any>ThemeOptions = any> extends interface LocaleConfig<ThemeOptions = any>

A single locale of a multi-locale site. Keyed by its URL prefix ('/' for the default locale, '/zh/', '/bn/', ...).

LocaleConfig
<function (type parameter) ThemeOptions in ResolvedLocale<ThemeOptions = any>ThemeOptions> {
/** The locale's URL prefix, e.g. `'/'`, `'/zh/'`. */ ResolvedLocale<ThemeOptions = any>.prefix: string

The locale's URL prefix, e.g. '/', '/zh/'.

prefix
: string
} /** The target of a locale switch. */ export interface LocaleSwitchTarget { LocaleSwitchTarget.href: stringhref: string /** Whether the target locale lacks the logical page and the href falls back to its home. */ LocaleSwitchTarget.fallback: boolean

Whether the target locale lacks the logical page and the href falls back to its home.

fallback
: boolean
} /** * Slim per-locale version snapshot used by the language switcher. Only the * fields needed to keep the same frozen version (and fall back otherwise) * are required; full manifests stay on `virtual:sveltepress/versions`. */ export interface LocaleVersionSnapshot { LocaleVersionSnapshot.basePath: stringbasePath: string
LocaleVersionSnapshot.current: {
    id: string;
    routes?: string[];
}
current
: { id: stringid: string, routes?: string[] | undefinedroutes?: string[] }
LocaleVersionSnapshot.versions: {
    id: string;
    routes?: string[];
}[]
versions
: interface Array<T>Array<{ id: stringid: string, routes?: string[] | undefinedroutes?: string[] }>
} export interface LlmsConfig { LlmsConfig.enabled?: boolean | undefinedenabled?: boolean LlmsConfig.title?: string | undefinedtitle?: string LlmsConfig.description?: string | undefineddescription?: string LlmsConfig.baseUrl?: string | undefinedbaseUrl?: string LlmsConfig.routesDir?: string | undefinedroutesDir?: string LlmsConfig.filter?: ((filePath: string, frontmatter: Record<string, unknown>) => boolean) | undefinedfilter?: (filePath: stringfilePath: string, frontmatter: Record<string, unknown>frontmatter: type Record<K extends keyof any, T> = { [P in K]: T; }

Construct a type with a set of properties K of type T

Record
<string, unknown>) => boolean
LlmsConfig.sort?: ((a: PageInfo, b: PageInfo) => number) | undefinedsort?: (a: PageInfoa: PageInfo, b: PageInfob: PageInfo) => number } export interface SveltepressVitePluginOptions { SveltepressVitePluginOptions.theme?: ResolvedTheme | undefinedtheme?: ResolvedTheme SveltepressVitePluginOptions.siteConfig?: SiteConfig | undefinedsiteConfig?: SiteConfig SveltepressVitePluginOptions.addInspect?: boolean | undefinedaddInspect?: boolean SveltepressVitePluginOptions.remarkPlugins?: Plugin[] | RemarkPluginsOrderer | undefinedremarkPlugins?: import PluginPlugin[] | type RemarkPluginsOrderer = (themeRemarkPlugins: Plugin[]) => Plugin[]RemarkPluginsOrderer SveltepressVitePluginOptions.rehypePlugins?: Plugin[] | RehypePluginsOrderer | undefinedrehypePlugins?: import PluginPlugin[] | type RehypePluginsOrderer = (themeRehypePlugins: Plugin[]) => Plugin[]RehypePluginsOrderer SveltepressVitePluginOptions.llms?: LlmsConfig | undefinedllms?: LlmsConfig /** * Multi-locale site configuration keyed by URL prefix (`'/'` for the default * locale, `'/zh/'`, `'/bn/'`, ...). Each entry carries that locale's `lang`, * a user-facing `label` for the switcher, and its full theme options. * * When omitted the site stays single-locale and behavior is unchanged. */ SveltepressVitePluginOptions.locales?: LocalesConfig<any> | undefined

Multi-locale site configuration keyed by URL prefix ('/' for the default locale, '/zh/', '/bn/', ...). Each entry carries that locale's lang, a user-facing label for the switcher, and its full theme options.

When omitted the site stays single-locale and behavior is unchanged.

locales
?:
type LocalesConfig<ThemeOptions = any> = {
    [x: string]: LocaleConfig<ThemeOptions>;
}

Multi-locale site configuration keyed by URL prefix.

LocalesConfig
/** * Enable document version management by discovering * `sveltepress.versions.json`, override its location, or disable discovery. */
SveltepressVitePluginOptions.versions?: false | {
    manifest?: string;
} | undefined

Enable document version management by discovering sveltepress.versions.json, override its location, or disable discovery.

versions
?: false | {
manifest?: string | undefinedmanifest?: string } /** * Options forwarded to the SvelteKit vite plugin that `sveltepress()` sets up * internally. * * Use this on the newer SvelteKit layout (no `svelte.config.js`, config passed * inline to `sveltekit()\SveltepressVitePluginOptions.svelteKitOptions?: (KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">) | undefined

Options forwarded to the SvelteKit vite plugin that sveltepress() sets up internally.

Use this on the newer SvelteKit layout (no svelte.config.js, config passed inline to sveltekit()) to move your compilerOptions, adapter, etc. into sveltepress() and remove the standalone sveltekit() plugin. '.md' is always added to extensions automatically.

When omitted, SvelteKit reads its config from svelte.config.js as before.

svelteKitOptions
?: type SvelteKitOptions = (KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">) | undefined

The options accepted by SvelteKit's sveltekit() vite plugin.

On the newer SvelteKit project layout there is no svelte.config.js and all config (compilerOptions, adapter, ...) is passed inline to sveltekit() in vite.config.ts. Forward those options through sveltepress() so the standalone sveltekit() plugin can be removed (having both crashes the dev server with duplicated Svelte compilation).

SvelteKitOptions
/** * Options for Pagefind static local search indexing. * Set to `false` to disable automatic post-build indexing. */ SveltepressVitePluginOptions.pagefind?: any

Options for Pagefind static local search indexing. Set to false to disable automatic post-build indexing.

pagefind
?: boolean | import('./pagefind.js').PagefindOptions
} export type type LoadTheme<ThemeOptions = any> = (themeOptions?: ThemeOptions) => ResolvedThemeLoadTheme<function (type parameter) ThemeOptions in type LoadTheme<ThemeOptions = any>ThemeOptions = any> = (themeOptions: ThemeOptions | undefinedthemeOptions?: function (type parameter) ThemeOptions in type LoadTheme<ThemeOptions = any>ThemeOptions) => ResolvedTheme export type type RawRemarkPlugin = anyRawRemarkPlugin = import PluginPlugin<any[], any> | [import PluginPlugin<any[], any>, any] export type type AcceptableRemarkPlugin = any[]AcceptableRemarkPlugin = interface Array<T>Array<type RawRemarkPlugin = anyRawRemarkPlugin>
ts
Expand code

Plugin options

siteConfig

  • title: The site's title. Would be 'Untitled site' if not provided.
  • description: The site's description. Would be 'Build by sveltepress' if not provided.

addInspect

If set to true, will add Vite plugin inspect. It is useful to inspect or observe the Vite pipeline.

theme

See ResolvedTheme below

remarkPlugins

The remark plugins used for markdown parse. Read Remark plugins for more details.

Customize remark/rehype plugins order

The remarkPlugins and rehypePlugins can be one of these two format:

  1. An array of Plugins. The plugins provided here will run after theme provide remark plugins.
  2. A function that accept the themeRemarkPlugins then return an array of Plugins, for example:
vite.config.ts
import { const defaultTheme: ThemeDefaultdefaultTheme } from '@sveltepress/theme-default'
import { const sveltepress: (options?: SveltepressVitePluginOptions) => PluginOptionsveltepress } from '@sveltepress/vite'
import { function defineConfig(config: UserConfig): UserConfig (+5 overloads)

Type helper to make it easier to use vite.config.ts accepts a direct

UserConfig

object, or a function that returns it. The function receives a

ConfigEnv

object.

defineConfig
} from 'vite'
export default function defineConfig(config: UserConfig): UserConfig (+5 overloads)

Type helper to make it easier to use vite.config.ts accepts a direct

UserConfig

object, or a function that returns it. The function receives a

ConfigEnv

object.

defineConfig
({
UserConfig.plugins?: PluginOption[] | undefined

Array of vite plugins to use.

plugins
: [
function sveltepress(options?: SveltepressVitePluginOptions): PluginOptionsveltepress({ SveltepressVitePluginOptions.theme?: ResolvedTheme | undefinedtheme: function defaultTheme(themeOptions?: DefaultThemeOptions | undefined): ResolvedThemedefaultTheme(/* theme options */), SveltepressVitePluginOptions.remarkPlugins?: Plugin[] | RemarkPluginsOrderer | undefinedremarkPlugins: (themeRemarkPlugins: Plugin[]themeRemarkPlugins) => { // Add your custom plugin. Feel free to control the final order to apply all the plugins return [ ...themeRemarkPlugins: Plugin[]themeRemarkPlugins ] } }) ] })
ts

rehypePlugins

The rehype plugins used for html generator. Read Rehype plugins for more details.

llms

Generate machine-readable documentation indexes during production builds. It is disabled by default.

vite.config.ts
import { const sveltepress: (options?: SveltepressVitePluginOptions) => PluginOptionsveltepress } from '@sveltepress/vite'

function sveltepress(options?: SveltepressVitePluginOptions): PluginOptionsveltepress({
  SveltepressVitePluginOptions.siteConfig?: SiteConfig | undefinedsiteConfig: {
    SiteConfig.title?: string | undefinedtitle: 'My docs',
    SiteConfig.description?: string | undefineddescription: 'Documentation for my project',
  },
  SveltepressVitePluginOptions.llms?: LlmsConfig | undefinedllms: {
    LlmsConfig.enabled?: boolean | undefinedenabled: true,
    LlmsConfig.baseUrl?: string | undefinedbaseUrl: 'https://docs.example.com',
    LlmsConfig.filter?: ((filePath: string, frontmatter: Record<string, unknown>) => boolean) | undefinedfilter: (_filePath: string_filePath, frontmatter: Record<string, unknown>frontmatter) => frontmatter: Record<string, unknown>frontmatter.unknownllms !== false,
  },
})
ts
OptionTypeDefaultPurpose
enabledbooleanfalseWrite llms.txt and llms-full.txt during a build.
titlestringsiteConfig.titleTitle used in both generated files.
descriptionstringsiteConfig.descriptionDescription used in both generated files.
baseUrlstring''Absolute site origin prepended to route links.
routesDirstring'src/routes'Directory scanned for pages.
filter(filePath, frontmatter) => booleanExclude selected pages.
sort(a, b) => numberroute pathCustomize page order.

The generator reads Markdown pages only; Svelte-only pages and runtime data are not included. With incremental document versions, historical indexes read each page's frozen Markdown artifact rather than current source. Builds write the files into both static/ and the production bundle so a clean CI build includes them in the deployed output. Decide whether to commit the static/ copies or ignore and regenerate them consistently in CI.

Version change discovery

versions

Document version management is discovered from sveltepress.versions.json by default. Disable discovery or choose another manifest path explicitly:

import { const sveltepress: (options?: SveltepressVitePluginOptions) => PluginOptionsveltepress } from '@sveltepress/vite'

function sveltepress(options?: SveltepressVitePluginOptions): PluginOptionsveltepress({
  
SveltepressVitePluginOptions.versions?: false | {
    manifest?: string;
} | undefined

Enable document version management by discovering sveltepress.versions.json, override its location, or disable discovery.

versions
: false,
}) function sveltepress(options?: SveltepressVitePluginOptions): PluginOptionsveltepress({
SveltepressVitePluginOptions.versions?: false | {
    manifest?: string;
} | undefined

Enable document version management by discovering sveltepress.versions.json, override its location, or disable discovery.

versions
: { manifest?: string | undefinedmanifest: 'config/document-versions.json' },
})
ts

When enabled, virtual:sveltepress/versions exports changeSets and resolveVersionChanges(versionId?) alongside the manifest and route helpers. See Document version management for snapshot and What’s New usage.

Locales, Pagefind, and locale hooks

locales

Opt-in multi-locale configuration keyed by URL prefix ('/', '/zh/', …). Each entry provides lang, label, and that locale's theme options. When omitted, the site stays single-locale. See Internationalization.

pagefind

Controls post-build Pagefind indexing for Local Search. Defaults to enabled; set pagefind: false to disable, or pass a PagefindOptions object (rootSelector, excludeSelectors, forceLanguage, outputPath, …). Historical version indexes are frozen with syncHistoricalPagefind when document versions are enabled.

virtual:sveltepress/locale

When locales is set, this virtual module exports locales, resolveLocale, resolveLocalizedPath, and resolveLocaleSwitch. Without locales, locales is null and the helpers no-op.

createLocaleHandle

Import from /vite/hooks to set <html lang> during SSR from the active locale. Pair it with src/hooks.server.js as shown in the i18n guide.

ResolvedTheme

name

The name of the theme.

globalLayout

The absolute path of the global layout. Should be a svelte file For example: path.resolve(process.cwd(), 'ThemeGlobalLayout.svelte')

pageLayout

The absolute path of the page layout. Should be a svelte file For example: path.resolve(process.cwd(), 'ThemePageLayout.svelte')

vitePlugins

  • If passed a plugin or a group of plugins, these plugins would applied in before sveltepress
  • If passed a function, it will accept the sveltepress plugin and need to return a group of plugins. You can customize the sveltepress plugin order in your returned plugin chain.
About theme vite plugins

It maybe a little strange that theme has vite plugins. But it is useful when the theme want's to add some virtual modules or write some temp files.

highlighter

Used for code highlighting. For example, the default theme use Shiki. You can check the default theme highlighter source code for detailed usage.

remarkPlugins

The remark plugins used for Markdown parsing. Read Remark plugins for more details.

rehypePlugins

The rehype plugins used for HTML generation. Read Rehype plugins for more details.

Plugins order

The remark and rehype plugins that theme provide would be called before the plugins provide by vite plugin. For example:

vite.config.(js|ts)
import { const defaultTheme: ThemeDefaultdefaultTheme } from '@sveltepress/theme-default'
import { const sveltepress: (options?: SveltepressVitePluginOptions) => PluginOptionsveltepress } from '@sveltepress/vite'
import { function defineConfig(config: UserConfig): UserConfig (+5 overloads)

Type helper to make it easier to use vite.config.ts accepts a direct

UserConfig

object, or a function that returns it. The function receives a

ConfigEnv

object.

defineConfig
} from 'vite'
export default function defineConfig(config: UserConfig): UserConfig (+5 overloads)

Type helper to make it easier to use vite.config.ts accepts a direct

UserConfig

object, or a function that returns it. The function receives a

ConfigEnv

object.

defineConfig
({
UserConfig.plugins?: PluginOption[] | undefined

Array of vite plugins to use.

plugins
: [
function sveltepress(options?: SveltepressVitePluginOptions): PluginOptionsveltepress({ SveltepressVitePluginOptions.theme?: ResolvedTheme | undefinedtheme: function defaultTheme(themeOptions?: DefaultThemeOptions | undefined): ResolvedThemedefaultTheme(/* theme options */), SveltepressVitePluginOptions.remarkPlugins?: Plugin[] | RemarkPluginsOrderer | undefinedremarkPlugins: [/* yourRemarkPlugin */] }) ] })
ts

yourRemarkPlugin would run after the remark plugins in defaultTheme

footnoteLabel

Customize the footnotes title, default is: "Footnotes"

Virtual modules

virtual:sveltepress/site

This module holds the siteConfig. For example:

<script>
  import 
const siteConfig: {
    title: string;
    description: string;
}
siteConfig
from 'virtual:sveltepress/site'
</script> <p>The site title is: {
const siteConfig: {
    title: string;
    description: string;
}
siteConfig
.title: stringtitle}</p>
<p>The site description is: {
const siteConfig: {
    title: string;
    description: string;
}
siteConfig
.description: stringdescription}</p>
svelte

Low level API

The @sveltepress/vite package has a low level function mdToSvelte.

It is used for all the major Markdown rendering in Sveltepress.

It can be used for a more basic Markdown render engine involved with Svelte.

Here's usage example:

import { 
function mdToSvelte({ mdContent, remarkPlugins, rehypePlugins, highlighter, filename, footnoteLabel, data: inputData, }: CompileOptions): Promise<{
    data: Record<string, any>;
    code: string;
}>
mdToSvelte
} from '@sveltepress/vite'
const const mdContent: "\ ---\ title: Foo\ ---\ <script>\ const foo = 'bar'\ </script>\ # Title\ \ foo in script is: {foo}\ \ [Foo Link](https://foo.bar)\ "mdContent = ` --- title: Foo --- <script> const foo = 'bar' </script> # Title foo in script is: {foo} [Foo Link](https://foo.bar) ` const { const code: stringcode, const data: Record<string, any>data } = await
function mdToSvelte({ mdContent, remarkPlugins, rehypePlugins, highlighter, filename, footnoteLabel, data: inputData, }: CompileOptions): Promise<{
    data: Record<string, any>;
    code: string;
}>
mdToSvelte
({
CompileOptions.mdContent: stringmdContent, CompileOptions.remarkPlugins?: (Plugin<any[], any> | [Plugin<any[], any>, any])[] | undefinedremarkPlugins: [], // your custom remark plugins CompileOptions.rehypePlugins?: Plugin[] | undefinedrehypePlugins: [], // your custom rehype plugins CompileOptions.highlighter?: Highlighter | undefinedhighlighter: async (code: stringcode, lang: BundledLanguagelang, meta: string | undefinedmeta) => var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.PromiseConstructor.resolve<string>(value: string): Promise<string> (+2 overloads)

Creates a new resolved promise for the provided value.

@paramvalue A promise.@returnsA promise whose internal state matches the provided promise.
resolve
('The rendered highlighted code html'), // your custom code highlighter
CompileOptions.filename: stringfilename: 'foo.md', // the virtual file path }) // The rendered svelte code const code: stringcode // The frontmatter object, { title: 'Foo' } const data: Record<string, any>data
ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Literal code-block preparation

@sveltepress/vite/highlight

Import prepareCodeBlock from @sveltepress/vite/highlight and pass { mode: 'literal' } as its third argument when the source must not be transformed. Code commands such as // [svp! hl] and a leading // @noErrors remain unchanged in processedCode, while metadata parsing still resolves title and ln.

import { function prepareCodeBlock(code: string, meta?: string, options?: PrepareCodeBlockOptions): PreparedCodeBlock

Parse code block metadata and process code commands. Call BEFORE Shiki highlighting.

prepareCodeBlock
} from '@sveltepress/vite/highlight'
const const prepared: PreparedCodeBlockprepared = function prepareCodeBlock(code: string, meta?: string, options?: PrepareCodeBlockOptions): PreparedCodeBlock

Parse code block metadata and process code commands. Call BEFORE Shiki highlighting.

prepareCodeBlock
(
'// @noErrors\ const value = 1 ', 'title="source.md" ln', { PrepareCodeBlockOptions.mode?: "commands" | "literal" | undefined

Use literal mode to skip code commands and

@noErrorsprocessing.
mode
: 'literal' },
)
ts

Here prepared.processedCode equals the input, prepared.title is 'source.md', and prepared.containLineNumbers is true. prepared.noErrors remains false because literal mode preserves @noErrors instead of processing it as a directive.

Working with TypeScript

You need to include @sveltepress/vite/types in your src/app.d.ts to get plugin options and virtual module's type tips

/src/app.d.ts
/// <reference types="@sveltepress/vite/types" />

// Your other types
ts