@mralfarrakhan/svork 0.5.0

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/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Svork
2
+
3
+ Svork provides `svelteMarkdown`, a Svelte 5 preprocessor for Markdown files that need a small amount of Svelte interop.
4
+
5
+ It is intended for blog/content pages where Markdown should stay ergonomic while still allowing frontmatter, scripts, components, and inline expressions like `{post.title}`.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add svork
11
+ ```
12
+
13
+ Svork has a peer dependency on Svelte 5.
14
+
15
+ ## Usage
16
+
17
+ Add the preprocessor to your Svelte config:
18
+
19
+ ```js
20
+ import { svelteMarkdown } from "svork";
21
+
22
+ export default {
23
+ preprocess: [svelteMarkdown()],
24
+ extensions: [".svelte", ".md"],
25
+ };
26
+ ```
27
+
28
+ Then write Markdown with the supported Svelte syntax:
29
+
30
+ ```svelte
31
+ ---
32
+ title: Hello
33
+ author: Budi
34
+ ---
35
+
36
+ <script lang="ts">
37
+ import Badge from "./Badge.svelte";
38
+
39
+ const label = "New";
40
+ </script>
41
+
42
+ # {metadata.title}
43
+
44
+ <Badge text={label} />
45
+
46
+ Hello, {metadata.author}.
47
+ ```
48
+
49
+ Frontmatter is exported as `metadata` from the instance script:
50
+
51
+ ```svelte
52
+ export const metadata = {
53
+ title: "Hello",
54
+ author: "Budi",
55
+ };
56
+ ```
57
+
58
+ ## Options
59
+
60
+ ```ts
61
+ type SvelteMarkdownOptions = {
62
+ extensions?: string[];
63
+ remarkPlugins?: PluggableList;
64
+ rehypePlugins?: PluggableList;
65
+ };
66
+ ```
67
+
68
+ `extensions` defaults to `[".md"]`.
69
+
70
+ Example with common unified plugins:
71
+
72
+ ```js
73
+ import rehypeExpressiveCode from "rehype-expressive-code";
74
+ import remarkGfm from "remark-gfm";
75
+ import { svelteMarkdown } from "svork";
76
+
77
+ export default {
78
+ preprocess: [
79
+ svelteMarkdown({
80
+ remarkPlugins: [remarkGfm],
81
+ rehypePlugins: [[rehypeExpressiveCode, { themes: ["github-light"] }]],
82
+ }),
83
+ ],
84
+ extensions: [".svelte", ".md"],
85
+ };
86
+ ```
87
+
88
+ ## Behavior
89
+
90
+ - Parses source with Svelte before Markdown processing so Svelte spans can be protected.
91
+ - Hides Markdown code spans and fenced code blocks from the initial Svelte parse, so examples containing `{`, `}`, quotes, or component-like text stay ordinary code.
92
+ - Processes the document as one Markdown stream, preserving inline components inside paragraphs and list items.
93
+ - Preserves instance scripts, module scripts, Svelte components, and normal inline expression tags.
94
+ - Runs user `remarkPlugins` and `rehypePlugins` through the unified pipeline.
95
+ - Escapes remaining text and attribute braces after rehype plugins run, so generated highlighter markup remains Svelte-safe.
96
+ - Emits unsupported Svelte syntax as text, including `{#if}`, `{#each}`, `{#snippet}`, `{@html}`, `{@render}`, and lowercase-element directives such as `bind:*` or `class:*`.
97
+ - Falls back to Markdown processing with metadata export when Svelte parsing fails.
98
+
99
+ ## Development
100
+
101
+ ```sh
102
+ bun install
103
+ bun run test
104
+ bun run typecheck
105
+ bun run build
106
+ ```