@mistweaverco/mdsvex-shiki 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025+ mistweaverco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # mdsvex-shiki
2
+
3
+ Supports most [common transformers][shiki-transformers] out of the box.
4
+
5
+ ## Installation
6
+
7
+ Using bun:
8
+
9
+ ```bash
10
+ bun add @mistweaverco/mdsvex-shiki#v1.0.12
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Available options are as follows:
16
+
17
+ - `displayTitle`: Whether to show the title bar when a title is
18
+ provided in the code block info string. (default: `false`)
19
+ - `displayLang`: Whether to show the language label in
20
+ the title bar. (default: `false`)
21
+ - `disableCopyButton`: Whether to disable the copy button.
22
+ (default: `false`)
23
+ - `shikiOptions`: Options passed directly to Shiki's `codeToHtml` function.
24
+ - `theme`: Shiki theme to use. (default: `"tokyo-night"`)
25
+ - `transformers`: Array of [Shiki transformers][shiki-transformers] to apply.
26
+ By default, the following transformers are included:
27
+ - `transformerMetaHighlight()`
28
+ - `transformerMetaWordHighlight()`
29
+ - `transformerNotationDiff()`
30
+ - `transformerNotationHighlight()`
31
+ - `transformerNotationWordHighlight()`
32
+ - `transformerNotationErrorLevel()`
33
+
34
+ ```js
35
+ const options = {
36
+ displayTitle: true,
37
+ displayLang: true,
38
+ shikiOptions: {
39
+ theme: 'nord',
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### Import styles
45
+
46
+ If you just want to basic Shiki styling without the bar,
47
+ you don't need to import this CSS file.
48
+
49
+ If you to display the title, language and/or copy button,
50
+ you **must** import the CSS file.
51
+
52
+ Probably in the root layout or HTML file that wraps your markdown content.
53
+
54
+ (e.g., `src/routes/blog/+layout.svelte` or `src/app.html`)
55
+
56
+ ```js
57
+ import '@mistweaverco/mdsvex-shiki/styles.css';
58
+ ```
59
+
60
+ Now, you can use the bar features in your code blocks.
61
+
62
+ ### Enable Copy Button Functionality
63
+
64
+ To make the copy button work,
65
+ you need to apply the `copyAction` Svelte action to
66
+ a container element that wraps your markdown content.
67
+
68
+ In your layout file (e.g., `src/routes/blog/+layout.svelte`):
69
+
70
+ ```svelte
71
+ <script>
72
+ import { copyAction } from '@mistweaverco/mdsvex-shiki';
73
+ </script>
74
+
75
+ <div use:copyAction>
76
+ <slot />
77
+ </div>
78
+ ```
79
+
80
+ Or if you're rendering markdown content directly:
81
+
82
+ ```svelte
83
+ <script>
84
+ import { copyAction } from '@mistweaverco/mdsvex-shiki';
85
+ </script>
86
+
87
+ <div use:copyAction>
88
+ {@html content}
89
+ </div>
90
+ ```
91
+
92
+ The copy button will automatically copy the code content to
93
+ the clipboard when clicked and show a "Copied!" feedback message.
94
+
95
+ In `svelte.config.js`:
96
+ ```js
97
+ import mdsvexShiki from 'mdsvex-shiki'
98
+
99
+ const config = {
100
+ // ...
101
+ preprocess: [
102
+ // ...
103
+ mdsvex({
104
+ // ...
105
+ highlight: {
106
+ highlighter: await mdsvexShiki({
107
+ displayTitle: true,
108
+ displayLang: true,
109
+ shikiOptions: {
110
+ // Shiki options
111
+ // every option supported by Shiki's `codeToHtml` function
112
+ // with defaults for `theme` and `formatters`
113
+ theme: 'nord',
114
+ wrap: true,
115
+ },
116
+ })
117
+ }
118
+ }),
119
+ ],
120
+ }
121
+ ```
122
+
123
+
124
+
125
+ [shiki-transformers]: https://shiki.style/packages/transformers