@humanspeak/svelte-markdown 0.8.12 → 0.8.14
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 +135 -0
- package/dist/Parser.svelte +9 -6
- package/dist/SvelteMarkdown.svelte +14 -10
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/renderers/Image.svelte +91 -2
- package/dist/renderers/Image.svelte.d.ts +2 -0
- package/dist/utils/cache.d.ts +5 -0
- package/dist/utils/cache.js +5 -0
- package/dist/utils/createFilterUtilities.d.ts +52 -0
- package/dist/utils/createFilterUtilities.js +126 -0
- package/dist/utils/parse-and-cache.d.ts +31 -0
- package/dist/utils/parse-and-cache.js +48 -0
- package/dist/utils/rendererKeys.d.ts +1 -1
- package/dist/utils/token-cache.d.ts +178 -0
- package/dist/utils/token-cache.js +238 -0
- package/dist/utils/token-cleanup.js +6 -1
- package/dist/utils/unsupportedHtmlRenderers.d.ts +4 -4
- package/dist/utils/unsupportedHtmlRenderers.js +8 -43
- package/dist/utils/unsupportedRenderers.d.ts +8 -8
- package/dist/utils/unsupportedRenderers.js +11 -48
- package/package.json +44 -35
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Unsupported } from '../renderers/index.js';
|
|
2
2
|
import { defaultRenderers } from './markdown-parser.js';
|
|
3
3
|
import { rendererKeysInternal } from './rendererKeys.js';
|
|
4
|
-
|
|
4
|
+
import { createFilterUtilities } from './createFilterUtilities.js';
|
|
5
|
+
// Create filter utilities using the generic factory
|
|
6
|
+
const filterUtils = createFilterUtilities(rendererKeysInternal, Unsupported, defaultRenderers);
|
|
5
7
|
/**
|
|
6
8
|
* Builds a map where every markdown renderer (excluding the special `html` map)
|
|
7
9
|
* is set to the `Unsupported` component.
|
|
8
10
|
*
|
|
9
11
|
* @function buildUnsupportedRenderers
|
|
10
|
-
* @returns {
|
|
12
|
+
* @returns {Omit<Renderers, 'html'>} A map with all non‑HTML renderers set to `Unsupported`.
|
|
11
13
|
* @example
|
|
12
14
|
* import { buildUnsupportedRenderers } from '@humanspeak/svelte-markdown'
|
|
13
15
|
* const renderers = {
|
|
@@ -15,23 +17,17 @@ const allRendererKeys = rendererKeysInternal;
|
|
|
15
17
|
* html: {} // customize HTML separately
|
|
16
18
|
* }
|
|
17
19
|
*/
|
|
18
|
-
export const buildUnsupportedRenderers =
|
|
19
|
-
const result = {};
|
|
20
|
-
for (const key of allRendererKeys) {
|
|
21
|
-
result[key] = Unsupported;
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
20
|
+
export const buildUnsupportedRenderers = filterUtils.buildUnsupported;
|
|
25
21
|
/**
|
|
26
22
|
* Produces a renderer map that allows only the specified markdown renderers (excluding `html`).
|
|
27
23
|
* All non‑listed renderer keys are set to `Unsupported`.
|
|
28
|
-
* Each entry can be either a renderer key (to use the library
|
|
24
|
+
* Each entry can be either a renderer key (to use the library's default component),
|
|
29
25
|
* or a tuple `[key, component]` to specify a custom component for that key.
|
|
30
26
|
*
|
|
31
27
|
* @function allowRenderersOnly
|
|
32
28
|
* @param {Array<RendererKey | [RendererKey, RendererComponent]>} allowed
|
|
33
29
|
* Renderer keys to allow, or tuples for custom component overrides.
|
|
34
|
-
* @returns {
|
|
30
|
+
* @returns {Omit<Renderers, 'html'>} A renderer map with only the provided keys enabled.
|
|
35
31
|
* @example
|
|
36
32
|
* // Allow only paragraph and link with defaults
|
|
37
33
|
* const renderers = allowRenderersOnly(['paragraph', 'link'])
|
|
@@ -40,25 +36,10 @@ export const buildUnsupportedRenderers = () => {
|
|
|
40
36
|
* // Allow paragraph with a custom component
|
|
41
37
|
* const renderers = allowRenderersOnly([['paragraph', MyParagraph]])
|
|
42
38
|
*/
|
|
43
|
-
export const allowRenderersOnly =
|
|
44
|
-
const result = buildUnsupportedRenderers();
|
|
45
|
-
for (const entry of allowed) {
|
|
46
|
-
if (Array.isArray(entry)) {
|
|
47
|
-
const [key, component] = entry;
|
|
48
|
-
if (allRendererKeys.includes(key))
|
|
49
|
-
result[key] = component;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const key = entry;
|
|
53
|
-
if (allRendererKeys.includes(key))
|
|
54
|
-
result[key] = defaultRenderers[key];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
};
|
|
39
|
+
export const allowRenderersOnly = filterUtils.allowOnly;
|
|
59
40
|
/**
|
|
60
41
|
* Produces a renderer map that excludes only the specified markdown renderer keys (excluding `html`).
|
|
61
|
-
* Excluded keys are mapped to `Unsupported`, while all other keys use the library
|
|
42
|
+
* Excluded keys are mapped to `Unsupported`, while all other keys use the library's default components.
|
|
62
43
|
* Optionally override specific non‑excluded keys with custom components via `[key, component]` tuples.
|
|
63
44
|
*
|
|
64
45
|
* Exclusions take precedence over overrides.
|
|
@@ -68,7 +49,7 @@ export const allowRenderersOnly = (allowed) => {
|
|
|
68
49
|
* Renderer keys to exclude (set to `Unsupported`).
|
|
69
50
|
* @param {Array<[RendererKey, RendererComponent]>} [overrides]
|
|
70
51
|
* Optional tuples mapping non‑excluded keys to custom components.
|
|
71
|
-
* @returns {
|
|
52
|
+
* @returns {Omit<Renderers, 'html'>} A renderer map with only the provided keys excluded.
|
|
72
53
|
* @example
|
|
73
54
|
* // Disable just paragraph and link, keep others as defaults
|
|
74
55
|
* const renderers = excludeRenderersOnly(['paragraph', 'link'])
|
|
@@ -77,22 +58,4 @@ export const allowRenderersOnly = (allowed) => {
|
|
|
77
58
|
* // Disable link; override paragraph to a custom component
|
|
78
59
|
* const renderers = excludeRenderersOnly(['link'], [['paragraph', MyParagraph]])
|
|
79
60
|
*/
|
|
80
|
-
export const excludeRenderersOnly =
|
|
81
|
-
const result = {};
|
|
82
|
-
for (const key of allRendererKeys) {
|
|
83
|
-
result[key] = defaultRenderers[key];
|
|
84
|
-
}
|
|
85
|
-
for (const key of excluded) {
|
|
86
|
-
if (allRendererKeys.includes(key))
|
|
87
|
-
result[key] = Unsupported;
|
|
88
|
-
}
|
|
89
|
-
if (overrides) {
|
|
90
|
-
for (const [key, component] of overrides) {
|
|
91
|
-
if (excluded.includes(key))
|
|
92
|
-
continue;
|
|
93
|
-
if (allRendererKeys.includes(key))
|
|
94
|
-
result[key] = component;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return result;
|
|
98
|
-
};
|
|
61
|
+
export const excludeRenderersOnly = filterUtils.excludeOnly;
|
package/package.json
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-markdown",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.14",
|
|
4
|
+
"description": "Fast, customizable markdown renderer for Svelte with built-in caching, TypeScript support, and Svelte 5 runes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
7
|
+
"svelte5",
|
|
8
|
+
"sveltekit",
|
|
7
9
|
"markdown",
|
|
8
10
|
"renderer",
|
|
9
11
|
"parser",
|
|
12
|
+
"fast",
|
|
13
|
+
"performance",
|
|
14
|
+
"cache",
|
|
15
|
+
"caching",
|
|
10
16
|
"marked",
|
|
11
17
|
"component",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
18
|
+
"typescript",
|
|
19
|
+
"runes",
|
|
14
20
|
"md",
|
|
15
21
|
"documentation",
|
|
16
22
|
"html",
|
|
17
23
|
"converter",
|
|
18
|
-
"formatting"
|
|
24
|
+
"formatting",
|
|
25
|
+
"customizable",
|
|
26
|
+
"extensible"
|
|
19
27
|
],
|
|
20
28
|
"homepage": "https://markdown.svelte.page",
|
|
21
29
|
"bugs": {
|
|
@@ -55,51 +63,52 @@
|
|
|
55
63
|
}
|
|
56
64
|
},
|
|
57
65
|
"dependencies": {
|
|
66
|
+
"@humanspeak/memory-cache": "^1.0.2",
|
|
58
67
|
"github-slugger": "^2.0.0",
|
|
59
68
|
"htmlparser2": "^10.0.0",
|
|
60
|
-
"marked": "^
|
|
69
|
+
"marked": "^17.0.1"
|
|
61
70
|
},
|
|
62
71
|
"devDependencies": {
|
|
63
|
-
"@eslint/compat": "^
|
|
64
|
-
"@eslint/js": "^9.
|
|
65
|
-
"@playwright/test": "^1.
|
|
66
|
-
"@sveltejs/adapter-auto": "^
|
|
67
|
-
"@sveltejs/kit": "^2.
|
|
68
|
-
"@sveltejs/package": "^2.5.
|
|
69
|
-
"@sveltejs/vite-plugin-svelte": "^6.2.
|
|
70
|
-
"@testing-library/jest-dom": "^6.
|
|
71
|
-
"@testing-library/svelte": "^5.
|
|
72
|
+
"@eslint/compat": "^2.0.0",
|
|
73
|
+
"@eslint/js": "^9.39.2",
|
|
74
|
+
"@playwright/test": "^1.57.0",
|
|
75
|
+
"@sveltejs/adapter-auto": "^7.0.0",
|
|
76
|
+
"@sveltejs/kit": "^2.49.3",
|
|
77
|
+
"@sveltejs/package": "^2.5.7",
|
|
78
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.2",
|
|
79
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
80
|
+
"@testing-library/svelte": "^5.3.1",
|
|
72
81
|
"@testing-library/user-event": "^14.6.1",
|
|
73
|
-
"@types/node": "^
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
75
|
-
"@typescript-eslint/parser": "^8.
|
|
76
|
-
"@vitest/coverage-v8": "^
|
|
82
|
+
"@types/node": "^25.0.3",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
84
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
85
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
77
86
|
"concurrently": "^9.2.1",
|
|
78
|
-
"eslint": "^9.
|
|
87
|
+
"eslint": "^9.39.2",
|
|
79
88
|
"eslint-config-prettier": "^10.1.8",
|
|
80
89
|
"eslint-plugin-import": "^2.32.0",
|
|
81
|
-
"eslint-plugin-svelte": "^3.
|
|
82
|
-
"eslint-plugin-unused-imports": "^4.
|
|
83
|
-
"globals": "^
|
|
90
|
+
"eslint-plugin-svelte": "^3.13.1",
|
|
91
|
+
"eslint-plugin-unused-imports": "^4.3.0",
|
|
92
|
+
"globals": "^17.0.0",
|
|
84
93
|
"husky": "^9.1.7",
|
|
85
|
-
"jsdom": "^27.
|
|
86
|
-
"prettier": "^3.
|
|
94
|
+
"jsdom": "^27.4.0",
|
|
95
|
+
"prettier": "^3.7.4",
|
|
87
96
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
88
|
-
"prettier-plugin-svelte": "^3.4.
|
|
89
|
-
"prettier-plugin-tailwindcss": "^0.
|
|
90
|
-
"publint": "^0.3.
|
|
91
|
-
"svelte": "^5.
|
|
92
|
-
"svelte-check": "^4.3.
|
|
93
|
-
"typescript": "^5.9.
|
|
94
|
-
"typescript-eslint": "^8.
|
|
95
|
-
"vite": "^7.1
|
|
96
|
-
"vitest": "^
|
|
97
|
+
"prettier-plugin-svelte": "^3.4.1",
|
|
98
|
+
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
99
|
+
"publint": "^0.3.16",
|
|
100
|
+
"svelte": "^5.46.1",
|
|
101
|
+
"svelte-check": "^4.3.5",
|
|
102
|
+
"typescript": "^5.9.3",
|
|
103
|
+
"typescript-eslint": "^8.52.0",
|
|
104
|
+
"vite": "^7.3.1",
|
|
105
|
+
"vitest": "^4.0.16"
|
|
97
106
|
},
|
|
98
107
|
"peerDependencies": {
|
|
99
108
|
"svelte": "^5.0.0"
|
|
100
109
|
},
|
|
101
110
|
"volta": {
|
|
102
|
-
"node": "
|
|
111
|
+
"node": "24.12.0"
|
|
103
112
|
},
|
|
104
113
|
"publishConfig": {
|
|
105
114
|
"access": "public"
|