@humanspeak/svelte-markdown 0.7.21 → 0.8.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/dist/Parser.svelte +8 -7
- package/dist/Parser.svelte.d.ts +2 -2
- package/dist/SvelteMarkdown.svelte +5 -6
- package/dist/index.d.ts +3 -3
- package/dist/renderers/Heading.svelte +1 -1
- package/dist/renderers/Heading.svelte.d.ts +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/utils/markdown-parser.d.ts +2 -45
- package/dist/utils/markdown-parser.js +5 -12
- package/package.json +17 -17
package/dist/Parser.svelte
CHANGED
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
RendererComponent
|
|
54
54
|
} from './utils/markdown-parser.js'
|
|
55
55
|
|
|
56
|
-
interface Props {
|
|
56
|
+
interface Props<T extends Renderers = Renderers> {
|
|
57
57
|
type?: string
|
|
58
58
|
tokens?: Token[] | TokensList
|
|
59
59
|
header?: Tokens.TableCell[]
|
|
60
60
|
rows?: Tokens.TableCell[][]
|
|
61
61
|
ordered?: boolean
|
|
62
|
-
renderers:
|
|
62
|
+
renderers: T
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const {
|
|
@@ -116,8 +116,9 @@
|
|
|
116
116
|
}}
|
|
117
117
|
{@const { tag, ...localRest } = token}
|
|
118
118
|
{@const htmlTag = tag as keyof typeof Html}
|
|
119
|
-
{#if htmlTag in renderers.html}
|
|
120
|
-
{@const HtmlComponent =
|
|
119
|
+
{#if renderers.html && htmlTag in renderers.html}
|
|
120
|
+
{@const HtmlComponent =
|
|
121
|
+
renderers.html[htmlTag as keyof typeof renderers.html]}
|
|
121
122
|
<HtmlComponent {...token}>
|
|
122
123
|
{#if token.tokens?.length}
|
|
123
124
|
<Parser
|
|
@@ -167,8 +168,8 @@
|
|
|
167
168
|
{:else if type === 'html'}
|
|
168
169
|
{@const { tag, ...localRest } = rest}
|
|
169
170
|
{@const htmlTag = rest.tag as keyof typeof Html}
|
|
170
|
-
{#if htmlTag in renderers.html}
|
|
171
|
-
{@const HtmlComponent = renderers.html[htmlTag]}
|
|
171
|
+
{#if renderers.html && htmlTag in renderers.html}
|
|
172
|
+
{@const HtmlComponent = renderers.html[htmlTag as keyof typeof renderers.html]}
|
|
172
173
|
{@const tokens = (rest.tokens as Token[]) ?? ([] as Token[])}
|
|
173
174
|
<HtmlComponent {...rest}>
|
|
174
175
|
{#if tokens.length}
|
|
@@ -189,7 +190,7 @@
|
|
|
189
190
|
/>
|
|
190
191
|
{/if}
|
|
191
192
|
{:else}
|
|
192
|
-
{@const GeneralComponent = renderers[type as keyof
|
|
193
|
+
{@const GeneralComponent = renderers[type as keyof typeof renderers] as RendererComponent}
|
|
193
194
|
<GeneralComponent {...rest}>
|
|
194
195
|
{#if tokens}
|
|
195
196
|
{@const { text: _text, raw: _raw, ...parserRest } = rest}
|
package/dist/Parser.svelte.d.ts
CHANGED
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
*/
|
|
44
44
|
import Parser from './Parser.svelte';
|
|
45
45
|
import type { Renderers, Token, TokensList, Tokens } from './utils/markdown-parser.js';
|
|
46
|
-
interface Props {
|
|
46
|
+
interface Props<T extends Renderers = Renderers> {
|
|
47
47
|
type?: string;
|
|
48
48
|
tokens?: Token[] | TokensList;
|
|
49
49
|
header?: Tokens.TableCell[];
|
|
50
50
|
rows?: Tokens.TableCell[][];
|
|
51
51
|
ordered?: boolean;
|
|
52
|
-
renderers:
|
|
52
|
+
renderers: T;
|
|
53
53
|
}
|
|
54
54
|
type $$ComponentProps = Props & {
|
|
55
55
|
[key: string]: unknown;
|
|
@@ -46,23 +46,22 @@
|
|
|
46
46
|
* - Provides parsed callback for external token access
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
+
import Parser from './Parser.svelte'
|
|
50
|
+
import { type SvelteMarkdownProps } from './types.js'
|
|
49
51
|
import {
|
|
50
|
-
Lexer,
|
|
51
52
|
defaultOptions,
|
|
52
53
|
defaultRenderers,
|
|
54
|
+
Lexer,
|
|
53
55
|
Slugger,
|
|
54
56
|
type Token,
|
|
55
|
-
type TokensList
|
|
56
|
-
type SvelteMarkdownOptions
|
|
57
|
+
type TokensList
|
|
57
58
|
} from './utils/markdown-parser.js'
|
|
58
|
-
import Parser from './Parser.svelte'
|
|
59
59
|
import { shrinkHtmlTokens } from './utils/token-cleanup.js'
|
|
60
|
-
import { type SvelteMarkdownProps } from './types.js'
|
|
61
60
|
|
|
62
61
|
const {
|
|
63
62
|
source = [],
|
|
64
63
|
renderers = {},
|
|
65
|
-
options = {}
|
|
64
|
+
options = {},
|
|
66
65
|
isInline = false,
|
|
67
66
|
parsed = () => {},
|
|
68
67
|
...rest
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RendererComponent, Renderers, Token, TokensList } from './utils/markdown-parser.js';
|
|
2
2
|
import SvelteMarkdown from './SvelteMarkdown.svelte';
|
|
3
|
-
import type { SvelteMarkdownProps } from './types.js';
|
|
3
|
+
import type { SvelteMarkdownOptions, SvelteMarkdownProps } from './types.js';
|
|
4
4
|
export default SvelteMarkdown;
|
|
5
|
-
export type { SvelteMarkdownOptions, SvelteMarkdownProps, Token, TokensList };
|
|
5
|
+
export type { RendererComponent, Renderers, SvelteMarkdownOptions, SvelteMarkdownProps, Token, TokensList };
|
package/dist/types.d.ts
CHANGED
|
@@ -18,11 +18,15 @@
|
|
|
18
18
|
* @packageDocumentation
|
|
19
19
|
*/
|
|
20
20
|
import type { Token, TokensList } from 'marked';
|
|
21
|
-
import type {
|
|
22
|
-
export type SvelteMarkdownProps = {
|
|
21
|
+
import type { MarkedOptions, Renderers } from './utils/markdown-parser.js';
|
|
22
|
+
export type SvelteMarkdownProps<T extends Renderers = Renderers> = {
|
|
23
23
|
source: Token[] | string;
|
|
24
|
-
renderers?: Partial<
|
|
24
|
+
renderers?: Partial<T>;
|
|
25
25
|
options?: Partial<SvelteMarkdownOptions>;
|
|
26
26
|
isInline?: boolean;
|
|
27
27
|
parsed?: (tokens: Token[] | TokensList) => void;
|
|
28
28
|
};
|
|
29
|
+
export interface SvelteMarkdownOptions extends MarkedOptions {
|
|
30
|
+
headerIds?: boolean;
|
|
31
|
+
headerPrefix?: string;
|
|
32
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { default as Slugger } from 'github-slugger';
|
|
2
|
-
export { Lexer, type Token, type Tokens, type TokensList } from 'marked';
|
|
2
|
+
export { Lexer, type MarkedOptions, type Token, type Tokens, type TokensList } from 'marked';
|
|
3
3
|
import type { Component } from 'svelte';
|
|
4
4
|
import { type HtmlRenderers } from '../renderers/html/index.js';
|
|
5
|
+
import type { SvelteMarkdownOptions } from '../types.js';
|
|
5
6
|
/**
|
|
6
7
|
* Represents a Svelte component that can be used as a renderer.
|
|
7
8
|
* Allows for flexible component types while maintaining type safety.
|
|
@@ -60,50 +61,6 @@ export type Renderers = {
|
|
|
60
61
|
* @const {Renderers}
|
|
61
62
|
*/
|
|
62
63
|
export declare const defaultRenderers: Renderers;
|
|
63
|
-
/**
|
|
64
|
-
* Configuration options for SvelteMarkdown parser.
|
|
65
|
-
* Extends marked options with additional Svelte-specific configurations.
|
|
66
|
-
*
|
|
67
|
-
* @interface SvelteMarkdownOptions
|
|
68
|
-
*
|
|
69
|
-
* @property {string|null} baseUrl - Base URL for relative links
|
|
70
|
-
* @property {boolean} breaks - Enable line breaks in output
|
|
71
|
-
* @property {boolean} gfm - Enable GitHub Flavored Markdown
|
|
72
|
-
* @property {boolean} headerIds - Auto-generate header IDs
|
|
73
|
-
* @property {string} headerPrefix - Prefix for header IDs
|
|
74
|
-
* @property {Function|null} highlight - Syntax highlighting function
|
|
75
|
-
* @property {string} langPrefix - Prefix for code block language classes
|
|
76
|
-
* @property {boolean} mangle - Encode email addresses
|
|
77
|
-
* @property {boolean} pedantic - Conform to original markdown spec
|
|
78
|
-
* @property {Object|null} renderer - Custom renderer
|
|
79
|
-
* @property {boolean} sanitize - Sanitize HTML input
|
|
80
|
-
* @property {Function|null} sanitizer - Custom sanitizer function
|
|
81
|
-
* @property {boolean} silent - Suppress error output
|
|
82
|
-
* @property {boolean} smartLists - Use smarter list behavior
|
|
83
|
-
* @property {boolean} smartypants - Use smart punctuation
|
|
84
|
-
* @property {Object|null} tokenizer - Custom tokenizer
|
|
85
|
-
* @property {boolean} xhtml - Generate XHTML-compliant tags
|
|
86
|
-
*/
|
|
87
|
-
export type SvelteMarkdownOptions = {
|
|
88
|
-
baseUrl: string | null;
|
|
89
|
-
breaks: boolean;
|
|
90
|
-
gfm: boolean;
|
|
91
|
-
headerIds: boolean;
|
|
92
|
-
tables: boolean;
|
|
93
|
-
headerPrefix: string;
|
|
94
|
-
highlight: null;
|
|
95
|
-
langPrefix: string;
|
|
96
|
-
mangle: boolean;
|
|
97
|
-
pedantic: boolean;
|
|
98
|
-
renderer: null;
|
|
99
|
-
sanitize: boolean;
|
|
100
|
-
sanitizer: null;
|
|
101
|
-
silent: boolean;
|
|
102
|
-
smartLists: boolean;
|
|
103
|
-
smartypants: boolean;
|
|
104
|
-
tokenizer: null;
|
|
105
|
-
xhtml: boolean;
|
|
106
|
-
};
|
|
107
64
|
/**
|
|
108
65
|
* Default configuration options for the markdown parser.
|
|
109
66
|
* Provides sensible defaults while allowing for customization.
|
|
@@ -53,22 +53,15 @@ export const defaultRenderers = {
|
|
|
53
53
|
* @const {SvelteMarkdownOptions}
|
|
54
54
|
*/
|
|
55
55
|
export const defaultOptions = {
|
|
56
|
-
|
|
56
|
+
async: false,
|
|
57
57
|
breaks: false,
|
|
58
58
|
gfm: true,
|
|
59
|
-
tables: true,
|
|
60
|
-
headerIds: true,
|
|
61
|
-
headerPrefix: '',
|
|
62
|
-
highlight: null,
|
|
63
|
-
langPrefix: 'language-',
|
|
64
|
-
mangle: true,
|
|
65
59
|
pedantic: false,
|
|
66
60
|
renderer: null,
|
|
67
|
-
sanitize: false,
|
|
68
|
-
sanitizer: null,
|
|
69
61
|
silent: false,
|
|
70
|
-
smartLists: false,
|
|
71
|
-
smartypants: false,
|
|
72
62
|
tokenizer: null,
|
|
73
|
-
|
|
63
|
+
walkTokens: null,
|
|
64
|
+
// Custom options
|
|
65
|
+
headerIds: true,
|
|
66
|
+
headerPrefix: ''
|
|
74
67
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A powerful, customizable markdown renderer for Svelte with TypeScript support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -75,24 +75,24 @@
|
|
|
75
75
|
"marked": "^15.0.7"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@eslint/compat": "^1.2.
|
|
79
|
-
"@eslint/js": "^9.
|
|
78
|
+
"@eslint/compat": "^1.2.8",
|
|
79
|
+
"@eslint/js": "^9.24.0",
|
|
80
80
|
"@playwright/test": "^1.51.1",
|
|
81
|
-
"@sveltejs/adapter-auto": "^
|
|
82
|
-
"@sveltejs/kit": "^2.20.
|
|
81
|
+
"@sveltejs/adapter-auto": "^6.0.0",
|
|
82
|
+
"@sveltejs/kit": "^2.20.4",
|
|
83
83
|
"@sveltejs/package": "^2.3.10",
|
|
84
84
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
85
85
|
"@testing-library/jest-dom": "^6.6.3",
|
|
86
86
|
"@testing-library/svelte": "^5.2.7",
|
|
87
87
|
"@testing-library/user-event": "^14.6.1",
|
|
88
|
-
"@types/node": "^22.
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
90
|
-
"@typescript-eslint/parser": "^8.
|
|
91
|
-
"@vitest/coverage-v8": "^3.
|
|
92
|
-
"eslint": "^9.
|
|
88
|
+
"@types/node": "^22.14.0",
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "^8.29.0",
|
|
90
|
+
"@typescript-eslint/parser": "^8.29.0",
|
|
91
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
92
|
+
"eslint": "^9.24.0",
|
|
93
93
|
"eslint-config-prettier": "^10.1.1",
|
|
94
94
|
"eslint-plugin-import": "^2.31.0",
|
|
95
|
-
"eslint-plugin-svelte": "^3.
|
|
95
|
+
"eslint-plugin-svelte": "^3.5.1",
|
|
96
96
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
97
97
|
"globals": "^16.0.0",
|
|
98
98
|
"jsdom": "^26.0.0",
|
|
@@ -100,13 +100,13 @@
|
|
|
100
100
|
"prettier-plugin-organize-imports": "^4.1.0",
|
|
101
101
|
"prettier-plugin-svelte": "^3.3.3",
|
|
102
102
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
103
|
-
"publint": "^0.3.
|
|
104
|
-
"svelte": "^5.25.
|
|
103
|
+
"publint": "^0.3.10",
|
|
104
|
+
"svelte": "^5.25.7",
|
|
105
105
|
"svelte-check": "^4.1.5",
|
|
106
|
-
"typescript": "^5.8.
|
|
107
|
-
"typescript-eslint": "^8.
|
|
108
|
-
"vite": "^6.2.
|
|
109
|
-
"vitest": "^3.
|
|
106
|
+
"typescript": "^5.8.3",
|
|
107
|
+
"typescript-eslint": "^8.29.0",
|
|
108
|
+
"vite": "^6.2.5",
|
|
109
|
+
"vitest": "^3.1.1"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
112
|
"svelte": "^5.0.0"
|