svelte-streamdown 1.0.6 → 1.0.7
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/Block.svelte +64 -20
- package/dist/Elements/A.svelte +17 -14
- package/dist/Elements/A.svelte.d.ts +7 -2
- package/dist/Elements/Alert.svelte +12 -28
- package/dist/Elements/Alert.svelte.d.ts +7 -2
- package/dist/Elements/Blockquote.svelte +11 -9
- package/dist/Elements/Blockquote.svelte.d.ts +7 -2
- package/dist/Elements/Code.svelte +13 -11
- package/dist/Elements/Code.svelte.d.ts +7 -2
- package/dist/Elements/Del.svelte +11 -7
- package/dist/Elements/Del.svelte.d.ts +7 -2
- package/dist/Elements/Element.svelte +50 -99
- package/dist/Elements/Element.svelte.d.ts +2 -5
- package/dist/Elements/Em.svelte +11 -6
- package/dist/Elements/Em.svelte.d.ts +7 -2
- package/dist/Elements/Heading.svelte +25 -0
- package/dist/Elements/Heading.svelte.d.ts +9 -0
- package/dist/Elements/Hr.svelte +12 -6
- package/dist/Elements/Hr.svelte.d.ts +7 -2
- package/dist/Elements/Image.svelte +17 -17
- package/dist/Elements/Image.svelte.d.ts +7 -2
- package/dist/Elements/InlineCode.svelte +12 -7
- package/dist/Elements/InlineCode.svelte.d.ts +7 -2
- package/dist/Elements/Li.svelte +11 -6
- package/dist/Elements/Li.svelte.d.ts +7 -2
- package/dist/Elements/Math.svelte +19 -9
- package/dist/Elements/Math.svelte.d.ts +7 -2
- package/dist/Elements/Mermaid.svelte +13 -9
- package/dist/Elements/Mermaid.svelte.d.ts +7 -2
- package/dist/Elements/Ol.svelte +13 -6
- package/dist/Elements/Ol.svelte.d.ts +7 -2
- package/dist/Elements/P.svelte +11 -6
- package/dist/Elements/P.svelte.d.ts +7 -2
- package/dist/Elements/Strong.svelte +11 -6
- package/dist/Elements/Strong.svelte.d.ts +7 -2
- package/dist/Elements/Sub.svelte +10 -6
- package/dist/Elements/Sub.svelte.d.ts +6 -2
- package/dist/Elements/Sup.svelte +10 -5
- package/dist/Elements/Sup.svelte.d.ts +6 -2
- package/dist/Elements/Table.svelte +12 -7
- package/dist/Elements/Table.svelte.d.ts +7 -2
- package/dist/Elements/Tbody.svelte +8 -7
- package/dist/Elements/Tbody.svelte.d.ts +5 -2
- package/dist/Elements/Td.svelte +12 -7
- package/dist/Elements/Td.svelte.d.ts +7 -2
- package/dist/Elements/Th.svelte +11 -6
- package/dist/Elements/Th.svelte.d.ts +7 -2
- package/dist/Elements/Thead.svelte +13 -9
- package/dist/Elements/Thead.svelte.d.ts +7 -2
- package/dist/Elements/Tr.svelte +13 -9
- package/dist/Elements/Tr.svelte.d.ts +7 -2
- package/dist/Elements/Ul.svelte +11 -6
- package/dist/Elements/Ul.svelte.d.ts +7 -2
- package/dist/Elements/index.d.ts +1 -6
- package/dist/Elements/index.js +1 -6
- package/dist/Streamdown.d.ts +16 -24
- package/dist/Streamdown.svelte +7 -39
- package/dist/Streamdown.svelte.d.ts +1 -1
- package/dist/hightlighter.svelte.js +0 -1
- package/dist/marked/index.d.ts +16 -0
- package/dist/marked/index.js +34 -0
- package/dist/marked/marked-alert.d.ts +19 -0
- package/dist/marked/marked-alert.js +54 -0
- package/dist/marked/marked-footnotes.d.ts +28 -0
- package/dist/marked/marked-footnotes.js +75 -0
- package/dist/marked/marked-math.d.ts +10 -0
- package/dist/marked/marked-math.js +60 -0
- package/dist/theme.d.ts +3 -3
- package/dist/theme.js +5 -5
- package/package.json +2 -14
- package/dist/Elements/H1.svelte +0 -23
- package/dist/Elements/H1.svelte.d.ts +0 -4
- package/dist/Elements/H2.svelte +0 -23
- package/dist/Elements/H2.svelte.d.ts +0 -4
- package/dist/Elements/H3.svelte +0 -23
- package/dist/Elements/H3.svelte.d.ts +0 -4
- package/dist/Elements/H4.svelte +0 -23
- package/dist/Elements/H4.svelte.d.ts +0 -4
- package/dist/Elements/H5.svelte +0 -23
- package/dist/Elements/H5.svelte.d.ts +0 -4
- package/dist/Elements/H6.svelte +0 -23
- package/dist/Elements/H6.svelte.d.ts +0 -4
- package/dist/Elements/element.d.ts +0 -8
- package/dist/Elements/element.js +0 -1
- package/dist/utils/alerts.d.ts +0 -12
- package/dist/utils/alerts.js +0 -207
- package/dist/utils/parse-blocks.d.ts +0 -1
- package/dist/utils/parse-blocks.js +0 -40
- package/dist/utils/parse.d.ts +0 -3
- package/dist/utils/parse.js +0 -131
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
6
5
|
|
|
7
6
|
const streamdown = useStreamdown();
|
|
8
7
|
|
|
9
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
children
|
|
10
|
+
}: {
|
|
11
|
+
children: Snippet;
|
|
12
|
+
} = $props();
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
<Slot
|
|
13
16
|
props={{
|
|
14
|
-
children
|
|
15
|
-
node,
|
|
16
|
-
...props
|
|
17
|
+
children
|
|
17
18
|
}}
|
|
18
19
|
render={streamdown.snippets.tbody}
|
|
19
20
|
>
|
|
20
|
-
<tbody
|
|
21
|
+
<tbody class={streamdown.theme.tbody.base}>
|
|
21
22
|
{@render children()}
|
|
22
23
|
</tbody>
|
|
23
24
|
</Slot>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
children: Snippet;
|
|
4
|
+
};
|
|
5
|
+
declare const Tbody: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
6
|
type Tbody = ReturnType<typeof Tbody>;
|
|
4
7
|
export default Tbody;
|
package/dist/Elements/Td.svelte
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
4
|
+
import type { TableCell } from '../marked/index.js';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
6
|
|
|
7
7
|
const streamdown = useStreamdown();
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
token
|
|
12
|
+
}: {
|
|
13
|
+
children: Snippet;
|
|
14
|
+
token: TableCell;
|
|
15
|
+
} = $props();
|
|
10
16
|
</script>
|
|
11
17
|
|
|
12
18
|
<Slot
|
|
13
19
|
props={{
|
|
14
20
|
children,
|
|
15
|
-
|
|
16
|
-
...props
|
|
21
|
+
token
|
|
17
22
|
}}
|
|
18
23
|
render={streamdown.snippets.td}
|
|
19
24
|
>
|
|
20
|
-
<td
|
|
21
|
-
{@render children()}
|
|
25
|
+
<td class={streamdown.theme.td.base}>
|
|
26
|
+
{@render children?.()}
|
|
22
27
|
</td>
|
|
23
28
|
</Slot>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { TableCell } from '../marked/index.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
token: TableCell;
|
|
6
|
+
};
|
|
7
|
+
declare const Td: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
8
|
type Td = ReturnType<typeof Td>;
|
|
4
9
|
export default Td;
|
package/dist/Elements/Th.svelte
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
4
|
+
import type { Tokens } from 'marked';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
6
|
|
|
7
7
|
const streamdown = useStreamdown();
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
cell
|
|
12
|
+
}: {
|
|
13
|
+
children: Snippet;
|
|
14
|
+
cell: Tokens.TableCell;
|
|
15
|
+
} = $props();
|
|
10
16
|
</script>
|
|
11
17
|
|
|
12
18
|
<Slot
|
|
13
19
|
props={{
|
|
14
20
|
children,
|
|
15
|
-
|
|
16
|
-
...props
|
|
21
|
+
cell
|
|
17
22
|
}}
|
|
18
23
|
render={streamdown.snippets.th}
|
|
19
24
|
>
|
|
20
|
-
<th
|
|
25
|
+
<th class={streamdown.theme.th.base}>
|
|
21
26
|
{@render children()}
|
|
22
27
|
</th>
|
|
23
28
|
</Slot>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
cell: Tokens.TableCell;
|
|
6
|
+
};
|
|
7
|
+
declare const Th: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
8
|
type Th = ReturnType<typeof Th>;
|
|
4
9
|
export default Th;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
6
|
-
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
import type { TableRow } from '../marked/index.js';
|
|
7
6
|
const streamdown = useStreamdown();
|
|
8
7
|
|
|
9
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
token,
|
|
10
|
+
children
|
|
11
|
+
}: {
|
|
12
|
+
token: TableRow;
|
|
13
|
+
children: Snippet;
|
|
14
|
+
} = $props();
|
|
10
15
|
</script>
|
|
11
16
|
|
|
12
17
|
<Slot
|
|
13
18
|
props={{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...props
|
|
19
|
+
token,
|
|
20
|
+
children
|
|
17
21
|
}}
|
|
18
22
|
render={streamdown.snippets.thead}
|
|
19
23
|
>
|
|
20
|
-
<thead
|
|
21
|
-
{@render children()}
|
|
24
|
+
<thead class={streamdown.theme.thead.base}>
|
|
25
|
+
{@render children?.()}
|
|
22
26
|
</thead>
|
|
23
27
|
</Slot>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { TableRow } from '../marked/index.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
token: TableRow;
|
|
5
|
+
children: Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const Thead: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
8
|
type Thead = ReturnType<typeof Thead>;
|
|
4
9
|
export default Thead;
|
package/dist/Elements/Tr.svelte
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
6
|
-
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
import type { TableRow } from '../marked/index.js';
|
|
7
6
|
const streamdown = useStreamdown();
|
|
8
7
|
|
|
9
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
token,
|
|
10
|
+
children
|
|
11
|
+
}: {
|
|
12
|
+
token: TableRow;
|
|
13
|
+
children: Snippet;
|
|
14
|
+
} = $props();
|
|
10
15
|
</script>
|
|
11
16
|
|
|
12
17
|
<Slot
|
|
13
18
|
props={{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...props
|
|
19
|
+
token,
|
|
20
|
+
children
|
|
17
21
|
}}
|
|
18
22
|
render={streamdown.snippets.tr}
|
|
19
23
|
>
|
|
20
|
-
<tr
|
|
21
|
-
{@render children()}
|
|
24
|
+
<tr class={streamdown.theme.tr}>
|
|
25
|
+
{@render children?.()}
|
|
22
26
|
</tr>
|
|
23
27
|
</Slot>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { TableRow } from '../marked/index.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
token: TableRow;
|
|
5
|
+
children: Snippet;
|
|
6
|
+
};
|
|
7
|
+
declare const Tr: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
8
|
type Tr = ReturnType<typeof Tr>;
|
|
4
9
|
export default Tr;
|
package/dist/Elements/Ul.svelte
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useStreamdown } from '../Streamdown.svelte';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import type { ElementProps } from './element.js';
|
|
5
3
|
import Slot from './Slot.svelte';
|
|
4
|
+
import type { Tokens } from 'marked';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
6
|
|
|
7
7
|
const streamdown = useStreamdown();
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
token
|
|
12
|
+
}: {
|
|
13
|
+
children: Snippet;
|
|
14
|
+
token: Tokens.List;
|
|
15
|
+
} = $props();
|
|
10
16
|
</script>
|
|
11
17
|
|
|
12
18
|
<Slot
|
|
13
19
|
props={{
|
|
14
20
|
children,
|
|
15
|
-
|
|
16
|
-
...props
|
|
21
|
+
token
|
|
17
22
|
}}
|
|
18
23
|
render={streamdown.snippets.ul}
|
|
19
24
|
>
|
|
20
|
-
<ul
|
|
25
|
+
<ul class={streamdown.theme.ul.base}>
|
|
21
26
|
{@render children()}
|
|
22
27
|
</ul>
|
|
23
28
|
</Slot>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
token: Tokens.List;
|
|
6
|
+
};
|
|
7
|
+
declare const Ul: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
3
8
|
type Ul = ReturnType<typeof Ul>;
|
|
4
9
|
export default Ul;
|
package/dist/Elements/index.d.ts
CHANGED
|
@@ -2,12 +2,7 @@ export { default as A } from './A.svelte';
|
|
|
2
2
|
export { default as Blockquote } from './Blockquote.svelte';
|
|
3
3
|
export { default as Code } from './Code.svelte';
|
|
4
4
|
export { default as CodeBlock } from './Code.svelte';
|
|
5
|
-
export { default as
|
|
6
|
-
export { default as H2 } from './H2.svelte';
|
|
7
|
-
export { default as H3 } from './H3.svelte';
|
|
8
|
-
export { default as H4 } from './H4.svelte';
|
|
9
|
-
export { default as H5 } from './H5.svelte';
|
|
10
|
-
export { default as H6 } from './H6.svelte';
|
|
5
|
+
export { default as Heading } from './Heading.svelte';
|
|
11
6
|
export { default as Hr } from './Hr.svelte';
|
|
12
7
|
export { default as Image } from './Image.svelte';
|
|
13
8
|
export { default as Li } from './Li.svelte';
|
package/dist/Elements/index.js
CHANGED
|
@@ -2,12 +2,7 @@ export { default as A } from './A.svelte';
|
|
|
2
2
|
export { default as Blockquote } from './Blockquote.svelte';
|
|
3
3
|
export { default as Code } from './Code.svelte';
|
|
4
4
|
export { default as CodeBlock } from './Code.svelte';
|
|
5
|
-
export { default as
|
|
6
|
-
export { default as H2 } from './H2.svelte';
|
|
7
|
-
export { default as H3 } from './H3.svelte';
|
|
8
|
-
export { default as H4 } from './H4.svelte';
|
|
9
|
-
export { default as H5 } from './H5.svelte';
|
|
10
|
-
export { default as H6 } from './H6.svelte';
|
|
5
|
+
export { default as Heading } from './Heading.svelte';
|
|
11
6
|
export { default as Hr } from './Hr.svelte';
|
|
12
7
|
export { default as Image } from './Image.svelte';
|
|
13
8
|
export { default as Li } from './Li.svelte';
|
package/dist/Streamdown.d.ts
CHANGED
|
@@ -1,40 +1,27 @@
|
|
|
1
1
|
import type { BundledTheme } from 'shiki';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import type { Element, Parents } from 'hast';
|
|
4
|
-
import type { PluggableList } from 'unified';
|
|
5
|
-
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
6
3
|
import type { Theme } from './theme.js';
|
|
7
4
|
import type { MermaidConfig } from 'mermaid';
|
|
8
5
|
import type { KatexOptions } from 'katex';
|
|
9
|
-
import type {
|
|
10
|
-
type
|
|
6
|
+
import type { StreamdownContext } from './Streamdown.svelte';
|
|
7
|
+
import type { StreamdownToken } from './marked/index.js';
|
|
8
|
+
type PredefinedElements = 'a' | 'heading' | 'paragraph' | 'code' | 'inlineCode' | 'img' | 'ul' | 'ol' | 'li' | 'hr' | 'alert' | 'strong' | 'blockquote' | 'table' | 'thead' | 'tbody' | 'tr' | 'th' | 'td' | 'sup' | 'sub' | 'pre' | 'mermaid' | 'math' | 'inlineMath' | 'em' | 'del';
|
|
11
9
|
export type Snippets = {
|
|
12
|
-
[K in PredefinedElements]?: Snippet<[
|
|
10
|
+
[K in PredefinedElements]?: Snippet<[
|
|
11
|
+
{
|
|
12
|
+
children: Snippet;
|
|
13
|
+
token: StreamdownToken;
|
|
14
|
+
}
|
|
15
|
+
]>;
|
|
13
16
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Filter elements callback type
|
|
16
|
-
*/
|
|
17
|
-
export type AllowElement = (element: Readonly<Element>, index: number, parent: Readonly<Parents> | undefined) => boolean | null | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* URL transform callback type
|
|
20
|
-
*/
|
|
21
|
-
export type UrlTransform = (url: string, key: string, node: Readonly<Element>) => string | null | undefined;
|
|
22
17
|
export type StreamdownProps = {
|
|
18
|
+
streamdown?: StreamdownContext;
|
|
23
19
|
content: string;
|
|
24
20
|
class?: string;
|
|
25
21
|
parseIncompleteMarkdown?: boolean;
|
|
26
22
|
defaultOrigin?: string;
|
|
27
23
|
allowedLinkPrefixes?: string[];
|
|
28
24
|
allowedImagePrefixes?: string[];
|
|
29
|
-
remarkPlugins?: PluggableList;
|
|
30
|
-
remarkRehypeOptions?: RemarkRehypeOptions;
|
|
31
|
-
rehypePlugins?: PluggableList;
|
|
32
|
-
allowElement?: AllowElement | null;
|
|
33
|
-
allowedElements?: readonly string[] | null;
|
|
34
|
-
disallowedElements?: readonly string[] | null;
|
|
35
|
-
skipHtml?: boolean;
|
|
36
|
-
unwrapDisallowed?: boolean;
|
|
37
|
-
urlTransform?: UrlTransform | null;
|
|
38
25
|
theme?: Partial<Theme>;
|
|
39
26
|
baseTheme?: 'tailwind' | 'shadcn';
|
|
40
27
|
mergeTheme?: boolean;
|
|
@@ -51,6 +38,11 @@ export type StreamdownProps = {
|
|
|
51
38
|
important?: string;
|
|
52
39
|
};
|
|
53
40
|
};
|
|
54
|
-
customElements?: Record<string, Snippet<[
|
|
41
|
+
customElements?: Record<string, Snippet<[
|
|
42
|
+
{
|
|
43
|
+
children: Snippet;
|
|
44
|
+
token: StreamdownToken;
|
|
45
|
+
}
|
|
46
|
+
]>>;
|
|
55
47
|
} & Partial<Snippets>;
|
|
56
48
|
export {};
|
package/dist/Streamdown.svelte
CHANGED
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
import Block from './Block.svelte';
|
|
27
27
|
import type { Snippets, StreamdownProps } from './Streamdown.js';
|
|
28
28
|
import { bind } from './utils/bind.js';
|
|
29
|
-
import { parseMarkdownIntoBlocks } from './utils/parse-blocks.js';
|
|
30
29
|
import 'katex/dist/katex.min.css';
|
|
31
30
|
import { mergeTheme, type Theme, shadcnTheme } from './theme.js';
|
|
32
31
|
import type { BundledTheme } from 'shiki';
|
|
32
|
+
import { parseBlocks } from './marked/index.js';
|
|
33
33
|
|
|
34
34
|
let {
|
|
35
35
|
content = '',
|
|
@@ -40,15 +40,6 @@
|
|
|
40
40
|
defaultOrigin,
|
|
41
41
|
allowedLinkPrefixes = ['*'],
|
|
42
42
|
allowedImagePrefixes = ['*'],
|
|
43
|
-
allowElement,
|
|
44
|
-
allowedElements,
|
|
45
|
-
disallowedElements,
|
|
46
|
-
skipHtml,
|
|
47
|
-
unwrapDisallowed,
|
|
48
|
-
urlTransform,
|
|
49
|
-
remarkPlugins,
|
|
50
|
-
remarkRehypeOptions,
|
|
51
|
-
rehypePlugins,
|
|
52
43
|
theme,
|
|
53
44
|
mermaidConfig,
|
|
54
45
|
katexConfig,
|
|
@@ -56,10 +47,13 @@
|
|
|
56
47
|
baseTheme,
|
|
57
48
|
mergeTheme: shouldMergeTheme = true,
|
|
58
49
|
customElements,
|
|
50
|
+
streamdown = $bindable(),
|
|
59
51
|
...snippets
|
|
60
52
|
}: StreamdownProps = $props();
|
|
61
53
|
|
|
62
|
-
|
|
54
|
+
console.log('render');
|
|
55
|
+
|
|
56
|
+
streamdown = new StreamdownContext({
|
|
63
57
|
get content() {
|
|
64
58
|
return content;
|
|
65
59
|
},
|
|
@@ -75,33 +69,6 @@
|
|
|
75
69
|
get allowedImagePrefixes() {
|
|
76
70
|
return allowedImagePrefixes;
|
|
77
71
|
},
|
|
78
|
-
get allowElement() {
|
|
79
|
-
return allowElement;
|
|
80
|
-
},
|
|
81
|
-
get allowedElements() {
|
|
82
|
-
return allowedElements;
|
|
83
|
-
},
|
|
84
|
-
get disallowedElements() {
|
|
85
|
-
return disallowedElements;
|
|
86
|
-
},
|
|
87
|
-
get skipHtml() {
|
|
88
|
-
return skipHtml;
|
|
89
|
-
},
|
|
90
|
-
get unwrapDisallowed() {
|
|
91
|
-
return unwrapDisallowed;
|
|
92
|
-
},
|
|
93
|
-
get urlTransform() {
|
|
94
|
-
return urlTransform;
|
|
95
|
-
},
|
|
96
|
-
get remarkPlugins() {
|
|
97
|
-
return remarkPlugins;
|
|
98
|
-
},
|
|
99
|
-
get remarkRehypeOptions() {
|
|
100
|
-
return remarkRehypeOptions;
|
|
101
|
-
},
|
|
102
|
-
get rehypePlugins() {
|
|
103
|
-
return rehypePlugins;
|
|
104
|
-
},
|
|
105
72
|
get shikiTheme() {
|
|
106
73
|
return shikiTheme || 'github-light';
|
|
107
74
|
},
|
|
@@ -132,9 +99,10 @@
|
|
|
132
99
|
return shikiPreloadThemes;
|
|
133
100
|
}
|
|
134
101
|
});
|
|
102
|
+
|
|
135
103
|
const id = $props.id();
|
|
136
104
|
|
|
137
|
-
const blocks = $derived(
|
|
105
|
+
const blocks = $derived(parseBlocks(content));
|
|
138
106
|
</script>
|
|
139
107
|
|
|
140
108
|
{#each blocks as block, index (`${id}-block-${index}`)}
|
|
@@ -13,6 +13,6 @@ import type { Snippets, StreamdownProps } from './Streamdown.js';
|
|
|
13
13
|
import 'katex/dist/katex.min.css';
|
|
14
14
|
import { type Theme } from './theme.js';
|
|
15
15
|
import type { BundledTheme } from 'shiki';
|
|
16
|
-
declare const Streamdown: import("svelte").Component<StreamdownProps, {}, "">;
|
|
16
|
+
declare const Streamdown: import("svelte").Component<StreamdownProps, {}, "streamdown">;
|
|
17
17
|
type Streamdown = ReturnType<typeof Streamdown>;
|
|
18
18
|
export default Streamdown;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {} from 'shiki';
|
|
2
2
|
import { untrack } from 'svelte';
|
|
3
3
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
|
4
|
-
import { StreamdownContext, useStreamdown } from './Streamdown.svelte';
|
|
5
4
|
// Remove background styles from <pre> tags (inline style)
|
|
6
5
|
const removePreBackground = (html) => {
|
|
7
6
|
return html.replace(/<pre[^>]*style="[^"]*background[^";]*;?[^"]*"[^>]*>/g, (match) => match.replace(/style="[^"]*background[^";]*;?[^"]*"/, ''));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type MarkedToken, type Tokens } from 'marked';
|
|
2
|
+
import { type AlertToken } from './marked-alert.js';
|
|
3
|
+
import { type FootnoteToken } from './marked-footnotes.js';
|
|
4
|
+
import { type MathToken } from './marked-math.js';
|
|
5
|
+
export type StreamdownToken = MarkedToken | MathToken | AlertToken | FootnoteToken | TableRow | TableCell;
|
|
6
|
+
export type TableCell = Tokens.TableCell & {
|
|
7
|
+
type: 'tableCell';
|
|
8
|
+
};
|
|
9
|
+
export type TableRow = {
|
|
10
|
+
type: 'tableRow';
|
|
11
|
+
tokens: TableCell[];
|
|
12
|
+
isHeader: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const lex: (markdown: string) => StreamdownToken[];
|
|
15
|
+
export declare const parseBlocks: (markdown: string) => string[];
|
|
16
|
+
export type { MathToken, AlertToken, FootnoteToken };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Lexer, marked } from 'marked';
|
|
2
|
+
import markedAlert, {} from './marked-alert.js';
|
|
3
|
+
import markedFootnote, {} from './marked-footnotes.js';
|
|
4
|
+
import { markedMath } from './marked-math.js';
|
|
5
|
+
export const lex = (markdown) => {
|
|
6
|
+
return marked
|
|
7
|
+
.use({
|
|
8
|
+
gfm: true
|
|
9
|
+
})
|
|
10
|
+
.use(markedAlert())
|
|
11
|
+
.use(markedFootnote())
|
|
12
|
+
.use(markedMath())
|
|
13
|
+
.lexer(markdown)
|
|
14
|
+
.filter((token) => token.type !== 'space' && token.type !== 'footnote');
|
|
15
|
+
};
|
|
16
|
+
export const parseBlocks = (markdown) => {
|
|
17
|
+
const lexer = new Lexer({
|
|
18
|
+
gfm: true,
|
|
19
|
+
extensions: {
|
|
20
|
+
childTokens: {},
|
|
21
|
+
renderers: {},
|
|
22
|
+
block: [markedFootnote().extensions[0].tokenizer]
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return lexer.blockTokens(markdown, []).reduce((acc, block) => {
|
|
26
|
+
if (block.type === 'space' || block.type === 'footnote') {
|
|
27
|
+
return acc;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
acc.push(block.raw);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []);
|
|
34
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Token } from 'marked';
|
|
2
|
+
import type { TokenizerExtensionFunction } from 'marked';
|
|
3
|
+
type variantType = 'note' | 'tip' | 'important' | 'warning' | 'caution';
|
|
4
|
+
export declare function createSyntaxPattern(type: variantType): string;
|
|
5
|
+
export default function markedAlert(): {
|
|
6
|
+
extensions: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
level: 'block' | 'inline';
|
|
9
|
+
tokenizer: TokenizerExtensionFunction;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export declare function processAlertToken(token: Token): void;
|
|
13
|
+
export type AlertToken = {
|
|
14
|
+
type: 'alert';
|
|
15
|
+
variant: variantType;
|
|
16
|
+
raw: string;
|
|
17
|
+
text: string;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Lexer } from 'marked';
|
|
2
|
+
const variants = ['note', 'tip', 'important', 'warning', 'caution'];
|
|
3
|
+
export function createSyntaxPattern(type) {
|
|
4
|
+
return `^(?:\\[!${type.toUpperCase()}])\\s*?\n*`;
|
|
5
|
+
}
|
|
6
|
+
export default function markedAlert() {
|
|
7
|
+
const defaultLexer = new Lexer({ gfm: true });
|
|
8
|
+
const defaultTokenizer = defaultLexer.options.tokenizer;
|
|
9
|
+
return {
|
|
10
|
+
extensions: [
|
|
11
|
+
{
|
|
12
|
+
name: 'alert',
|
|
13
|
+
level: 'block',
|
|
14
|
+
tokenizer(src, tokens) {
|
|
15
|
+
const cap = defaultTokenizer.rules.block.blockquote.exec(src);
|
|
16
|
+
if (cap) {
|
|
17
|
+
const blockquoteToken = defaultTokenizer.blockquote(src);
|
|
18
|
+
blockquoteToken && processAlertToken(blockquoteToken);
|
|
19
|
+
return blockquoteToken;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function processAlertToken(token) {
|
|
27
|
+
const matchedVariant = variants.find((type) => new RegExp(createSyntaxPattern(type)).test(('text' in token && token.text) || ''));
|
|
28
|
+
if (!matchedVariant)
|
|
29
|
+
return;
|
|
30
|
+
const typeRegexp = new RegExp(createSyntaxPattern(matchedVariant));
|
|
31
|
+
// Transform the token into an alert token
|
|
32
|
+
Object.assign(token, {
|
|
33
|
+
type: 'alert',
|
|
34
|
+
variant: matchedVariant
|
|
35
|
+
});
|
|
36
|
+
const firstLine = ('tokens' in token && token.tokens?.[0]);
|
|
37
|
+
const firstLineText = firstLine.raw?.replace(typeRegexp, '').trim();
|
|
38
|
+
firstLine.text = firstLineText;
|
|
39
|
+
if (firstLineText) {
|
|
40
|
+
const patternToken = firstLine.tokens[0];
|
|
41
|
+
if (patternToken) {
|
|
42
|
+
Object.assign(patternToken, {
|
|
43
|
+
raw: patternToken.raw.replace(typeRegexp, ''),
|
|
44
|
+
text: patternToken.text.replace(typeRegexp, '')
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (firstLine.tokens[1]?.type === 'br') {
|
|
48
|
+
firstLine.tokens.splice(1, 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if ('tokens' in token && token.tokens) {
|
|
52
|
+
token.tokens?.shift();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TokenizerExtensionFunction } from 'marked';
|
|
2
|
+
import { type StreamdownToken } from './index.js';
|
|
3
|
+
export default function markedFootnote(): {
|
|
4
|
+
extensions: {
|
|
5
|
+
name: string;
|
|
6
|
+
level: 'block' | 'inline';
|
|
7
|
+
tokenizer: TokenizerExtensionFunction;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a single footnote.
|
|
12
|
+
*/
|
|
13
|
+
export type Footnote = {
|
|
14
|
+
type: 'footnote';
|
|
15
|
+
raw: string;
|
|
16
|
+
label: string;
|
|
17
|
+
tokens: StreamdownToken[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Represents a reference to a footnote.
|
|
21
|
+
*/
|
|
22
|
+
export type FootnoteRef = {
|
|
23
|
+
type: 'footnoteRef';
|
|
24
|
+
raw: string;
|
|
25
|
+
label: string;
|
|
26
|
+
content: Footnote;
|
|
27
|
+
};
|
|
28
|
+
export type FootnoteToken = Footnote | FootnoteRef;
|