Skip to content

Commit 279c4f1

Browse files
Improve docs structure and split advanced guides
Reorganize navigation around Quickstart, Guide, and Advanced sections and move advanced topics into focused pages. Update examples and option docs so snippets are valid, copy-pasteable, and aligned with current package behavior.
1 parent e376049 commit 279c4f1

14 files changed

Lines changed: 201 additions & 145 deletions

File tree

apps/documentation/docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Bring the power of Markdoc right into your Svelte applications.
1515

1616
## Quick links
1717

18-
- [Install](/guide/install/)
18+
- [Quickstart](/guide/install/)
1919
- [Configuration](/guide/configuration/)
20+
- [Advanced](/advanced/content-indexing/)
2021
- [GitHub](https://github.com/TorstenDittmann/svelte-markdoc-preprocess)

apps/documentation/docs/SUMMARY.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Summary
22

33
- [Introduction](README.md)
4+
- [Quickstart](guide/install.md)
45
- Guide
5-
- [Install](guide/install.md)
66
- [Configuration](guide/configuration.md)
77
- [Nodes](guide/nodes.md)
88
- [Tags](guide/tags.md)
99
- [Layouts](guide/layouts.md)
1010
- [Partials](guide/partials.md)
11-
- [Advanced](guide/advanced.md)
11+
- Advanced
12+
- [Indexing](advanced/content-indexing.md)
13+
- [VS Code schema](advanced/vscode-schema.md)
14+
- [Markdoc config](advanced/markdoc-config.md)
15+
- [Code highlighting](advanced/highlighting.md)

apps/documentation/docs/_meta.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Indexing
2+
3+
Each `.markdoc` file exports `frontmatter`, so you can build content lists (for example blog indexes) from `load` functions.
4+
5+
```md title="src/routes/blog/hello.markdoc"
6+
---
7+
title: My Blog Post
8+
description: This post explains how indexing works.
9+
date: 2026-01-01
10+
---
11+
12+
# My Blog Post
13+
```
14+
15+
```ts title="src/routes/blog/+page.server.ts"
16+
export function load() {
17+
const modules = import.meta.glob('./*.markdoc', {
18+
eager: true,
19+
});
20+
21+
const posts = Object.entries(modules).map(([filepath, module]) => {
22+
const { frontmatter } = module as {
23+
frontmatter: {
24+
title: string;
25+
description?: string;
26+
date?: string;
27+
};
28+
};
29+
30+
return {
31+
slug: filepath.replace('./', '').replace('.markdoc', ''),
32+
...frontmatter,
33+
};
34+
});
35+
36+
return { posts };
37+
}
38+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Add custom code highlighting
2+
3+
Use `highlighter` to transform fenced code blocks before rendering.
4+
5+
```js title="svelte.config.js"
6+
import { markdoc } from 'svelte-markdoc-preprocess';
7+
8+
markdoc({
9+
highlighter: async (code, language) => {
10+
return `<pre data-language="${language}"><code>${code}</code></pre>`;
11+
},
12+
});
13+
```
14+
15+
The function receives `(code, language)` and must return an HTML string.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Pass custom Markdoc config
2+
3+
Use the `config` option to pass options directly to Markdoc.
4+
5+
```js title="svelte.config.js"
6+
import { markdoc } from 'svelte-markdoc-preprocess';
7+
8+
markdoc({
9+
config: {
10+
variables: {
11+
company: 'Acme',
12+
},
13+
functions: {
14+
includes: {
15+
transform(parameters) {
16+
const [array, value] = Object.values(parameters);
17+
return Array.isArray(array) ? array.includes(value) : false;
18+
},
19+
},
20+
},
21+
},
22+
});
23+
```
24+
25+
Refer to the Markdoc config reference for all available options: https://markdoc.dev/docs/config#options
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Visual Studio Code schema support
2+
3+
With `generateSchema: true` (default), the preprocessor writes `.svelte-kit/markdoc_schema.js`.
4+
5+
You can point the official [Markdoc VS Code extension](https://marketplace.visualstudio.com/items?itemName=Stripe.markdoc-language-support) to that file in `markdoc.config.json`:
6+
7+
```json title="markdoc.config.json"
8+
[
9+
{
10+
"id": "my-site",
11+
"path": "src/routes",
12+
"schema": {
13+
"path": ".svelte-kit/markdoc_schema.js",
14+
"type": "esm",
15+
"property": "default",
16+
"watch": true
17+
}
18+
}
19+
]
20+
```

apps/documentation/docs/guide/_meta.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/documentation/docs/guide/advanced.md

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,117 @@
11
# Configuration
22

3-
You can pass the configuration to the preprocessor in the `svelte.config.js` like this:
3+
Pass options to `markdoc(...)` inside your `svelte.config.js`.
44

55
```js title="svelte.config.js"
6+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
67
import { markdoc } from 'svelte-markdoc-preprocess';
78

9+
/** @type {import('@sveltejs/kit').Config} */
810
const config = {
911
preprocess: [
1012
vitePreprocess(),
1113
markdoc({
12-
// configuration here
14+
// options here
1315
}),
1416
],
17+
extensions: ['.markdoc', '.svelte'],
1518
};
19+
20+
export default config;
1621
```
1722

1823
## Options
1924

20-
#### `extensions`
25+
### `extensions`
26+
27+
**Type:** `string[]`
28+
29+
**Default:** `['.markdoc', '.mdoc', '.markdown', '.md']`
30+
31+
File extensions to process with Markdoc.
32+
33+
### `nodes`
34+
35+
**Type:** `string | null`
36+
37+
**Default:** `null`
38+
39+
Absolute path to a `.svelte` file that exports node components from `<script module>`.
2140

22-
**Type**: `string[]`
41+
### `tags`
2342

24-
**Default**: `['.markdoc', '.mdoc', '.markdown', '.md']`
43+
**Type:** `string | null`
2544

26-
Extensions to be processed.
45+
**Default:** `null`
2746

28-
#### `nodes`
47+
Absolute path to a `.svelte` file that exports tag components from `<script module>`.
2948

30-
**Type**: `string | null`
49+
### `partials`
3150

32-
**Default**: `null`
51+
**Type:** `string | null`
3352

34-
Absoulute path to the `.svelte` file exporting components for nodes.
53+
**Default:** `null`
3554

36-
#### tags
55+
Absolute path to the partials directory.
3756

38-
**Type**: `string | null`
57+
### `generateSchema`
3958

40-
**Default**: `null`
59+
**Type:** `boolean`
4160

42-
Absoulute path to the `.svelte` file exporting components for tags.
61+
**Default:** `true`
4362

44-
#### partials
63+
Generates `.svelte-kit/markdoc_schema.js` for the official [Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=Stripe.markdoc-language-support).
4564

46-
**Type**: `string`
65+
### `layouts`
4766

48-
**Default**: `null`
67+
**Type:** `Record<string, string> | null`
4968

50-
Absoulute path to the folder for partials.
69+
**Default:** `null`
5170

52-
#### generateSchema
71+
Map of layout names to absolute `.svelte` file paths.
5372

54-
**Type**: `boolean`
73+
### `validationThreshold`
5574

56-
**Default**: `true`
75+
**Type:** `"debug" | "info" | "warning" | "error" | "critical" | null`
5776

58-
Generate schema files under `./svelte-kit/markdoc-schema.json` to be used with the official [Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=Stripe.markdoc-language-support).
77+
**Default:** `'error'`
5978

60-
#### layouts
79+
Minimum validation level that should fail the build.
6180

62-
**Type**: `Record<string, string> | null`
81+
### `allowComments`
6382

64-
**Default**: `null`
83+
**Type:** `boolean`
6584

66-
Layouts to be used for pages.
85+
**Default:** `false`
6786

68-
#### validationThreshold
87+
Allow HTML comments (`<!-- -->`) in Markdoc files.
6988

70-
**Type**: `"error" | "debug" | "info" | "warning" | "critical"`
89+
### `config`
7190

72-
**Default**: `error`
91+
**Type:** `ConfigType | null`
7392

74-
The threshold for validation errors to stop the build.
93+
**Default:** `null`
7594

76-
#### allowComments
95+
Pass configuration directly to Markdoc (for example `variables`, `functions`, `validation`, `tags`, `nodes`, and `partials`).
7796

78-
**Type**: `boolean`
97+
### `highlighter`
7998

80-
**Default**: `false`
99+
**Type:** `((code: string, language: string) => Promise<string>) | null`
81100

82-
Allow comments in the markdown files.
101+
**Default:** `null`
102+
103+
Custom syntax highlighter used for fenced code blocks. The returned string is rendered as HTML.
104+
105+
```js title="svelte.config.js"
106+
import { markdoc } from 'svelte-markdoc-preprocess';
107+
108+
markdoc({
109+
highlighter: async (code, language) => {
110+
if (language === 'js') {
111+
return `<span class="language-js">${code}</span>`;
112+
}
113+
114+
return code;
115+
},
116+
});
117+
```

0 commit comments

Comments
 (0)