1
- # A demo of \ ` sveltedown\ `
1
+ # A demo of ` sveltedown `
2
2
3
- \ ` sveltedown\ ` is a markdown component for Svelte.
3
+ ` sveltedown ` is a markdown component for Svelte.
4
4
5
5
👉 Changes are re-rendered as you type.
6
6
10
10
11
11
- Follows [ CommonMark] ( https://commonmark.org )
12
12
- Optionally follows [ GitHub Flavored Markdown] ( https://github.github.com/gfm/ )
13
- - Renders Svelte elements -- no \ ` @html\ ` needed
14
- - Lets you define your own snippets (to \ ` @render myHeading\ ` instead of \ ` 'h1'\ ` )
13
+ - Renders Svelte elements -- no ` @html ` needed
14
+ - Lets you define your own snippets (to ` @render myHeading ` instead of ` 'h1' ` )
15
15
- Has a lot of plugins
16
16
17
17
## Contents
18
18
19
19
Here is an example of a plugin in action
20
- ([ \ ` remark-toc\ `] ( https://github.com/remarkjs/remark-toc ) ).
20
+ ([ ` remark-toc ` ] ( https://github.com/remarkjs/remark-toc ) ).
21
21
** This section is replaced by an actual table of contents** .
22
22
23
23
## Syntax highlighting
24
24
25
25
Here is an example of a plugin to highlight code:
26
- [ \ ` @shikijs/rehype\ `] ( https://shiki.matsu.io/packages/rehype ) .
26
+ [ ` @shikijs/rehype ` ] ( https://shiki.matsu.io/packages/rehype ) .
27
27
28
- Create a shared highlighter in \ ` load\ ` :
28
+ Create a shared highlighter in ` load ` :
29
29
30
- \`\`\ ` ts
30
+ `` `ts
31
31
// src/routes/+page.ts
32
32
import { createHighlighterCore } from ' shiki/core' ;
33
33
import { createOnigurumaEngine } from ' shiki/engine/oniguruma' ;
34
34
35
35
export const load = async () => {
36
- const highlighter = await createHighlighterCore({
37
- themes: [ import('@shikijs/themes /github-light'), import('@shikijs/themes /github-dark')] ,
38
- langs: [
39
- import('@shikijs/langs /svelte'),
40
- import('@shikijs/langs /javascript'),
41
- import('@shikijs/langs /typescript'),
42
- import('@shikijs/langs /markdown')
43
- ] ,
44
- engine: createOnigurumaEngine(() => import('shiki/wasm'))
45
- });
46
-
47
- return {
48
- highlighter,
49
- };
50
-
36
+ const highlighter = await createHighlighterCore ({
37
+ themes: [import (' @shikijs/themes/github-light' ), import (' @shikijs/themes/github-dark' )],
38
+ langs: [
39
+ import (' @shikijs/langs/svelte' ),
40
+ import (' @shikijs/langs/javascript' ),
41
+ import (' @shikijs/langs/typescript' ),
42
+ import (' @shikijs/langs/markdown' )
43
+ ],
44
+ engine: createOnigurumaEngine (() => import (' shiki/wasm' ))
45
+ });
46
+
47
+ return {
48
+ highlighter
49
+ };
51
50
};
52
- \`\`\ `
51
+ `` `
53
52
54
53
...and then use it in your component:
55
54
56
- \`\`\` svelte
57
-
55
+ ``` svelte
58
56
<script lang="ts">
59
- // src/routes/+page.svelte
60
- import { Markdown } from ' sveltedown' ;
61
- import rehypeShikiFromHighlighter from ' @shikijs/rehype/core' ;
57
+ // src/routes/+page.svelte
58
+ import { Markdown } from 'sveltedown';
59
+ import rehypeShikiFromHighlighter from '@shikijs/rehype/core';
62
60
63
- const { data } = $props ();
61
+ const { data } = $props();
64
62
65
- let content = $state (' ' );
63
+ let content = $state('');
66
64
</script>
67
65
68
66
<Markdown
69
- {content}
70
- rehypePlugins={[
71
- [
72
- rehypeShikiFromHighlighter,
73
- data.highlighter,
74
- { themes: { light: 'github-light', dark: 'github-dark' } }
75
- ]
76
- ] }
67
+ {content}
68
+ rehypePlugins={[
69
+ [
70
+ rehypeShikiFromHighlighter,
71
+ data.highlighter,
72
+ { themes: { light: 'github-light', dark: 'github-dark' } }
73
+ ]
74
+ ]}
77
75
/>
78
- \`\`\ `
76
+ `` `
79
77
80
- Alternatively, if you're using \ ` experimental.async\ ` , you can use \ ` MarkdownAsync\ ` instead, which doesn't require setting up your highlighter in \ ` load\ ` .
78
+ Alternatively, if you're using ` experimental.async ` , you can use ` MarkdownAsync ` instead, which doesn't require setting up your highlighter in ` load ` .
81
79
If you're doing lots of highlighting, though, it's probably better to create your highlighter in some higher-level root scope and share it via context so that it
82
80
doesn't have to be recreated over and over again.
83
81
@@ -86,17 +84,17 @@ Pretty neat, eh?
86
84
## GitHub flavored markdown (GFM)
87
85
88
86
For GFM, you can _ also_ use a plugin:
89
- [ \ ` remark-gfm\ `] ( https://github.com/remarkjs/remark-gfm ) .
87
+ [ ` remark-gfm ` ] ( https://github.com/remarkjs/remark-gfm ) .
90
88
It adds support for GitHub-specific extensions to the language:
91
89
tables, strikethrough, tasklists, and literal URLs.
92
90
93
91
These features ** do not work by default** .
94
92
👆 Use the toggle above to add the plugin.
95
93
96
- | Feature | Support |
97
- | ---------: | :--------------------- |
98
- | CommonMark | 100% |
99
- | GFM | 100% w/ \ ` remark-gfm\ ` |
94
+ | Feature | Support |
95
+ | ---------: | :------------------- |
96
+ | CommonMark | 100% |
97
+ | GFM | 100% w/ ` remark-gfm ` |
100
98
101
99
~~ strikethrough~~
102
100
@@ -108,38 +106,34 @@ https://example.com
108
106
## HTML in markdown
109
107
110
108
⚠️ HTML in markdown is quite unsafe, but if you want to support it, you can
111
- use [ \ ` rehype-raw\ `] ( https://github.com/rehypejs/rehype-raw ) .
109
+ use [ ` rehype-raw ` ] ( https://github.com/rehypejs/rehype-raw ) .
112
110
You should probably combine it with
113
- [ \ ` rehype-sanitize\ `] ( https://github.com/rehypejs/rehype-sanitize ) .
111
+ [ ` rehype-sanitize ` ] ( https://github.com/rehypejs/rehype-sanitize ) .
114
112
115
113
<blockquote >
116
114
👆 Use the toggle above to add the plugin.
117
115
</blockquote >
118
116
119
117
## Components
120
118
121
- You can render custom content by mapping HTML elements to other HTML elements or by passing snippets for full custom control over rendering. HTML and SVG element tags are available as props directly on \` Markdown\` .
122
-
123
- \`\`\` svelte filename=src/lib/markdown.svelte
119
+ You can render custom content by mapping HTML elements to other HTML elements or by passing snippets for full custom control over rendering. HTML and SVG element tags are available as props directly on ` Markdown ` .
124
120
121
+ ``` svelte
125
122
<script lang="ts">
126
- import { Markdown } from ' sveltedown' ;
127
- import MyFancyDiv from ' $lib/my-fancy-div.svelte' ;
123
+ import { Markdown } from 'sveltedown';
124
+ import MyFancyDiv from '$lib/my-fancy-div.svelte';
128
125
129
- let content = $state (' ' );
126
+ let content = $state('');
130
127
</script>
131
128
132
129
<!-- use h2s instead of h1s for # headings -->
133
-
134
130
<Markdown {content} h1="h2">
135
-
136
- <!-- use a custom component instead of divs -->
137
-
138
- {#snippet div({ props, children })}
139
- <MyFancyDiv {...props}>{@render children()}</MyFancyDiv >
140
- {/snippet}
131
+ <!-- use a custom component instead of divs -->
132
+ {#snippet div({ props, children })}
133
+ <MyFancyDiv {...props}>{@render children()}</MyFancyDiv>
134
+ {/snippet}
141
135
</Markdown>
142
- \`\`\ `
136
+ `` `
143
137
144
138
## More info?
145
139
0 commit comments