Markdown
Components
In this section, we'll look at how you can work with Markdown files and how you can use Svelte components inside of them.
Markdown Files
Markdown files are just Svelte components. You can use them to create layouts __layout.md
, or
break large Markdown files into multiple components and import them like so:
The only difference between a Markdown file and Svelte component is that you can use top-level
tags such as <script>
, <script context="module">
, and <style>
multiple times.
The following is valid because KitDocs will merge top-level tags:
Frontmatter Store
We'll import the frontmatter
store for you so you can use it directly in your Markdown files like
so:
Global Components
You can create Svelte components that are global, meaning they're imported into every single Markdown file. In addition, global components are automatically mapped to Markdown containers, on which you can pass in props and dynamic slot elements.
First, create a component in the global markdown components directory:
Now, inside your markdown files you can use the <Button>
component like so:
Configuration
You can configure how global Svelte components are mapped to rules or containers by setting them in your plugin like so:
The configuration above will transform the following Markdown like so:
Change Directory
By default, the global components directory is set to src/kit-docs
. You can change it in
your plugin settings like so:
Default Components
There's a few components we provide out of the box such as CodeFence
, CodeInline
, Link
and
others. You can find all of our default components
on GitHub.
Overriding
If you want to override any of the default components, simply create a Svelte component with the same name in your global folder and make sure it accepts the same props.
For example, you can override CodeFence
by creating it in the global directory like so:
Finally, you can use the following minimal boilerplate and style the component as desired.