@humanspeak/svelte-markdown 0.6.8 → 0.7.1
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 +24 -17
- package/dist/SvelteMarkdown.svelte +26 -1
- package/dist/SvelteMarkdown.svelte.d.ts +22 -0
- package/package.json +32 -7
package/README.md
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
# Svelte Markdown
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@humanspeak/svelte-markdown)
|
|
4
|
+
[](https://github.com/humanspeak/svelte-markdown/actions/workflows/npm-publish.yml)
|
|
5
|
+
[](https://coveralls.io/github/humanspeak/svelte-markdown?branch=main)
|
|
6
|
+
[](https://github.com/humanspeak/svelte-markdown/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
<!-- [](https://bundlephobia.com/package/@humanspeak/svelte-markdown) -->
|
|
9
|
+
|
|
10
|
+
[](https://www.npmjs.com/package/@humanspeak/svelte-markdown)
|
|
11
|
+
[](https://github.com/humanspeak/svelte-markdown/actions/workflows/codeql.yml)
|
|
12
|
+
|
|
13
|
+
<!-- [](CODE_OF_CONDUCT.md) -->
|
|
14
|
+
|
|
15
|
+
[](http://www.typescriptlang.org/)
|
|
16
|
+
[](https://www.npmjs.com/package/@humanspeak/svelte-markdown)
|
|
17
|
+
[](https://github.com/humanspeak/svelte-markdown/graphs/commit-activity)
|
|
18
|
+
|
|
3
19
|
A markdown parser that renders into Svelte Components. Inspired by [ReactMarkdown](https://github.com/remarkjs/react-markdown).
|
|
4
20
|
|
|
21
|
+
Feel free to play with it and leave comments on its [homepage](https://markdown.svelte.page)
|
|
22
|
+
|
|
5
23
|
Rewriten for Svelte5 and all the updated goodies that have happened over the last two years. Also moved to Typescript because its the future!
|
|
6
24
|
|
|
7
25
|
## Installation
|
|
@@ -236,27 +254,16 @@ Note that the HTML paragraph must be enclosed within `<p>` tags.
|
|
|
236
254
|
|
|
237
255
|
Some tests have been added to the `tests` folder. You can clone this repo and create another svelte app and link it to this repo to try modifying it.
|
|
238
256
|
|
|
239
|
-
|
|
257
|
+
The current extenral dependencies are:
|
|
240
258
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
yarn dev
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
This will watch all changes and make the project linkable. Now on the app you created you can link it with:
|
|
248
|
-
|
|
249
|
-
```console
|
|
250
|
-
yarn link @humanspeak/svelte-markdown
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
And then import it like in the example above.
|
|
254
|
-
|
|
255
|
-
As of now the only external dependencys of this project is `marked`, `github-slugger`, `htmlparser2`.
|
|
259
|
+
- [Marked](https://marked.js.org/)
|
|
260
|
+
- [Github-Slugger](https://github.com/Flet/github-slugger)
|
|
261
|
+
- [HTMLParser2](https://github.com/fb55/htmlparser2).
|
|
256
262
|
|
|
257
263
|
## Related
|
|
258
264
|
|
|
259
265
|
- [ReactMarkdown](https://github.com/remarkjs/react-markdown) - React library to render markdown using React components. Inspiration for this library.
|
|
260
266
|
- [Svelte](https://svelte.dev) - JavaScript front-end framework.
|
|
261
|
-
- [Marked](https://marked.js.org/) - Markdown parser
|
|
262
267
|
- [Original](https://github.com/pablo-abc/svelte-markdown) - Original component
|
|
268
|
+
|
|
269
|
+
Made with ♥ by [Humanspeak](https://humanspeak.com)
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
A Svelte component that renders Markdown content into HTML using a customizable parser.
|
|
5
|
+
Supports both string input and pre-parsed markdown tokens, with configurable rendering
|
|
6
|
+
options and custom renderers.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```svelte
|
|
10
|
+
<SvelteMarkdown source="# Hello World" />
|
|
11
|
+
|
|
12
|
+
<SvelteMarkdown
|
|
13
|
+
source={markdownString}
|
|
14
|
+
options={{ headerIds: false }}
|
|
15
|
+
renderers={{ link: CustomLink }}
|
|
16
|
+
/>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
@property {string | Token[]} source - The markdown content to render, either as a string or pre-parsed tokens
|
|
20
|
+
@property {Partial<Renderers>} [renderers] - Custom renderers for markdown elements
|
|
21
|
+
@property {SvelteMarkdownOptions} [options] - Configuration options for the markdown parser
|
|
22
|
+
@property {boolean} [isInline=false] - Whether to parse the content as inline markdown
|
|
23
|
+
@property {function} [parsed] - Callback function called with the parsed tokens
|
|
24
|
+
-->
|
|
1
25
|
<script lang="ts">
|
|
2
26
|
import {
|
|
3
27
|
Lexer,
|
|
@@ -30,7 +54,8 @@
|
|
|
30
54
|
}: Props & {
|
|
31
55
|
[key: string]: unknown
|
|
32
56
|
} = $props()
|
|
33
|
-
|
|
57
|
+
// @ts-expect-error - Intentionally not using $state for tokens
|
|
58
|
+
let tokens: Token[] | undefined // eslint-disable-line svelte/valid-compile
|
|
34
59
|
let previousSource = $state<string | Token[] | undefined>(undefined)
|
|
35
60
|
let lexer: Lexer
|
|
36
61
|
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { type Token, type TokensList, type SvelteMarkdownOptions, type Renderers } from './utils/markdown-parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* A Svelte component that renders Markdown content into HTML using a customizable parser.
|
|
4
|
+
* Supports both string input and pre-parsed markdown tokens, with configurable rendering
|
|
5
|
+
* options and custom renderers.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <SvelteMarkdown source="# Hello World" />
|
|
10
|
+
*
|
|
11
|
+
* <SvelteMarkdown
|
|
12
|
+
* source={markdownString}
|
|
13
|
+
* options={{ headerIds: false }}
|
|
14
|
+
* renderers={{ link: CustomLink }}
|
|
15
|
+
* />
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @property {string | Token[]} source - The markdown content to render, either as a string or pre-parsed tokens
|
|
19
|
+
* @property {Partial<Renderers>} [renderers] - Custom renderers for markdown elements
|
|
20
|
+
* @property {SvelteMarkdownOptions} [options] - Configuration options for the markdown parser
|
|
21
|
+
* @property {boolean} [isInline=false] - Whether to parse the content as inline markdown
|
|
22
|
+
* @property {function} [parsed] - Callback function called with the parsed tokens
|
|
23
|
+
*/
|
|
2
24
|
declare const SvelteMarkdown: import("svelte").Component<{
|
|
3
25
|
source: Token[] | string;
|
|
4
26
|
renderers?: Partial<Renderers>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-markdown",
|
|
3
|
-
"description": "A markdown renderer for Svelte",
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "A powerful, customizable markdown renderer for Svelte with TypeScript support",
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
7
7
|
"build": "vite build && npm run package",
|
|
@@ -30,7 +30,22 @@
|
|
|
30
30
|
"svelte",
|
|
31
31
|
"markdown"
|
|
32
32
|
],
|
|
33
|
-
"
|
|
33
|
+
"keywords": [
|
|
34
|
+
"svelte",
|
|
35
|
+
"markdown",
|
|
36
|
+
"renderer",
|
|
37
|
+
"parser",
|
|
38
|
+
"marked",
|
|
39
|
+
"component",
|
|
40
|
+
"sveltekit",
|
|
41
|
+
"svelte5",
|
|
42
|
+
"md",
|
|
43
|
+
"documentation",
|
|
44
|
+
"html",
|
|
45
|
+
"converter",
|
|
46
|
+
"formatting"
|
|
47
|
+
],
|
|
48
|
+
"homepage": "https://markdown.svelte.page",
|
|
34
49
|
"files": [
|
|
35
50
|
"dist",
|
|
36
51
|
"!dist/**/*.test.*",
|
|
@@ -54,7 +69,7 @@
|
|
|
54
69
|
"dependencies": {
|
|
55
70
|
"github-slugger": "^2.0.0",
|
|
56
71
|
"htmlparser2": "^10.0.0",
|
|
57
|
-
"marked": "^15.0.
|
|
72
|
+
"marked": "^15.0.5"
|
|
58
73
|
},
|
|
59
74
|
"devDependencies": {
|
|
60
75
|
"@eslint/eslintrc": "^3.2.0",
|
|
@@ -66,7 +81,7 @@
|
|
|
66
81
|
"@testing-library/jest-dom": "^6.6.3",
|
|
67
82
|
"@testing-library/svelte": "^5.2.6",
|
|
68
83
|
"@testing-library/user-event": "^14.5.2",
|
|
69
|
-
"@types/node": "^22.10.
|
|
84
|
+
"@types/node": "^22.10.5",
|
|
70
85
|
"@typescript-eslint/eslint-plugin": "^8.19.0",
|
|
71
86
|
"@typescript-eslint/parser": "^8.19.0",
|
|
72
87
|
"@vitest/coverage-v8": "^2.1.8",
|
|
@@ -80,15 +95,25 @@
|
|
|
80
95
|
"prettier-plugin-svelte": "^3.3.2",
|
|
81
96
|
"prettier-plugin-tailwindcss": "^0.6.9",
|
|
82
97
|
"publint": "^0.2.12",
|
|
83
|
-
"svelte": "^5.16.
|
|
98
|
+
"svelte": "^5.16.1",
|
|
84
99
|
"svelte-check": "^4.1.1",
|
|
85
100
|
"typescript": "^5.7.2",
|
|
86
|
-
"vite": "^6.0.
|
|
101
|
+
"vite": "^6.0.7",
|
|
87
102
|
"vitest": "^2.1.8"
|
|
88
103
|
},
|
|
89
104
|
"overrides": {
|
|
90
105
|
"@sveltejs/kit": {
|
|
91
106
|
"cookie": "^0.7.0"
|
|
92
107
|
}
|
|
108
|
+
},
|
|
109
|
+
"volta": {
|
|
110
|
+
"node": "22.12.0"
|
|
111
|
+
},
|
|
112
|
+
"funding": {
|
|
113
|
+
"type": "github",
|
|
114
|
+
"url": "https://github.com/sponsors/humanspeak"
|
|
115
|
+
},
|
|
116
|
+
"publishConfig": {
|
|
117
|
+
"access": "public"
|
|
93
118
|
}
|
|
94
119
|
}
|