svelte-streamdown 1.0.8 → 2.0.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 +155 -140
- package/dist/Block.svelte +17 -41
- package/dist/Elements/Alert.svelte +1 -2
- package/dist/Elements/Code.svelte +3 -5
- package/dist/Elements/Code.svelte.d.ts +0 -2
- package/dist/Elements/Element.svelte +170 -42
- package/dist/Elements/FootnoteRef.svelte +126 -0
- package/dist/Elements/FootnoteRef.svelte.d.ts +7 -0
- package/dist/Elements/Image.svelte +4 -4
- package/dist/Elements/{A.svelte → Link.svelte} +4 -4
- package/dist/Elements/{A.svelte.d.ts → Link.svelte.d.ts} +3 -3
- package/dist/Elements/Math.svelte +13 -24
- package/dist/Elements/Math.svelte.d.ts +0 -2
- package/dist/Elements/Mermaid.svelte +105 -115
- package/dist/Elements/Mermaid.svelte.d.ts +0 -2
- package/dist/Elements/Table.svelte +1 -1
- package/dist/Elements/index.d.ts +5 -24
- package/dist/Elements/index.js +5 -24
- package/dist/Streamdown.d.ts +52 -10
- package/dist/Streamdown.js +19 -1
- package/dist/Streamdown.svelte +2 -34
- package/dist/Streamdown.svelte.d.ts +1 -14
- package/dist/marked/index.d.ts +6 -10
- package/dist/marked/index.js +29 -17
- package/dist/marked/marked-alert.d.ts +2 -2
- package/dist/marked/marked-alert.js +11 -24
- package/dist/marked/marked-footnotes.d.ts +1 -0
- package/dist/marked/marked-footnotes.js +27 -8
- package/dist/marked/marked-list.d.ts +36 -0
- package/dist/marked/marked-list.js +232 -0
- package/dist/marked/marked-math.js +1 -4
- package/dist/marked/marked-subsup.d.ts +28 -0
- package/dist/marked/marked-subsup.js +45 -0
- package/dist/marked/marked-table.d.ts +59 -0
- package/dist/marked/marked-table.js +495 -0
- package/dist/theme.d.ts +54 -30
- package/dist/theme.js +51 -35
- package/dist/utils/panzoom.svelte.d.ts +17 -18
- package/dist/utils/panzoom.svelte.js +0 -2
- package/dist/utils/parse-incomplete-markdown.js +157 -0
- package/dist/utils/useClickOutside.svelte.d.ts +8 -0
- package/dist/utils/useClickOutside.svelte.js +41 -0
- package/dist/utils/useKeyDown.svelte.d.ts +5 -0
- package/dist/utils/useKeyDown.svelte.js +23 -0
- package/package.json +2 -1
- package/dist/Elements/Blockquote.svelte +0 -28
- package/dist/Elements/Blockquote.svelte.d.ts +0 -9
- package/dist/Elements/Del.svelte +0 -28
- package/dist/Elements/Del.svelte.d.ts +0 -9
- package/dist/Elements/Em.svelte +0 -28
- package/dist/Elements/Em.svelte.d.ts +0 -9
- package/dist/Elements/Heading.svelte +0 -25
- package/dist/Elements/Heading.svelte.d.ts +0 -9
- package/dist/Elements/Hr.svelte +0 -26
- package/dist/Elements/Hr.svelte.d.ts +0 -9
- package/dist/Elements/InlineCode.svelte +0 -28
- package/dist/Elements/InlineCode.svelte.d.ts +0 -9
- package/dist/Elements/Li.svelte +0 -28
- package/dist/Elements/Li.svelte.d.ts +0 -9
- package/dist/Elements/Ol.svelte +0 -30
- package/dist/Elements/Ol.svelte.d.ts +0 -9
- package/dist/Elements/P.svelte +0 -28
- package/dist/Elements/P.svelte.d.ts +0 -9
- package/dist/Elements/Strong.svelte +0 -28
- package/dist/Elements/Strong.svelte.d.ts +0 -9
- package/dist/Elements/Sub.svelte +0 -27
- package/dist/Elements/Sub.svelte.d.ts +0 -8
- package/dist/Elements/Sup.svelte +0 -28
- package/dist/Elements/Sup.svelte.d.ts +0 -8
- package/dist/Elements/Tbody.svelte +0 -24
- package/dist/Elements/Tbody.svelte.d.ts +0 -7
- package/dist/Elements/Td.svelte +0 -28
- package/dist/Elements/Td.svelte.d.ts +0 -9
- package/dist/Elements/Th.svelte +0 -28
- package/dist/Elements/Th.svelte.d.ts +0 -9
- package/dist/Elements/Thead.svelte +0 -27
- package/dist/Elements/Thead.svelte.d.ts +0 -9
- package/dist/Elements/Tr.svelte +0 -27
- package/dist/Elements/Tr.svelte.d.ts +0 -9
- package/dist/Elements/Ul.svelte +0 -28
- package/dist/Elements/Ul.svelte.d.ts +0 -9
- /package/dist/{hightlighter.svelte.d.ts → utils/hightlighter.svelte.d.ts} +0 -0
- /package/dist/{hightlighter.svelte.js → utils/hightlighter.svelte.js} +0 -0
|
@@ -1,80 +1,208 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import
|
|
4
|
-
import Blockquote from './Blockquote.svelte';
|
|
3
|
+
import Link from './Link.svelte';
|
|
5
4
|
import Code from './Code.svelte';
|
|
6
|
-
import Hr from './Hr.svelte';
|
|
7
5
|
import Image from './Image.svelte';
|
|
8
|
-
import Li from './Li.svelte';
|
|
9
|
-
import Ol from './Ol.svelte';
|
|
10
|
-
import P from './P.svelte';
|
|
11
|
-
import Strong from './Strong.svelte';
|
|
12
|
-
import Sub from './Sub.svelte';
|
|
13
|
-
import Sup from './Sup.svelte';
|
|
14
|
-
import Table from './Table.svelte';
|
|
15
|
-
import Tbody from './Tbody.svelte';
|
|
16
|
-
import Td from './Td.svelte';
|
|
17
|
-
import Th from './Th.svelte';
|
|
18
|
-
import Thead from './Thead.svelte';
|
|
19
|
-
import Tr from './Tr.svelte';
|
|
20
|
-
import Ul from './Ul.svelte';
|
|
21
|
-
import InlineCode from './InlineCode.svelte';
|
|
22
6
|
import Mermaid from './Mermaid.svelte';
|
|
23
7
|
import Math from './Math.svelte';
|
|
24
|
-
import Em from './Em.svelte';
|
|
25
|
-
import Del from './Del.svelte';
|
|
26
8
|
import Alert from './Alert.svelte';
|
|
27
9
|
import type { StreamdownToken } from '../marked/index.js';
|
|
28
|
-
import
|
|
10
|
+
import Slot from './Slot.svelte';
|
|
11
|
+
import { useStreamdown } from '../Streamdown.js';
|
|
12
|
+
import FootnoteRef from './FootnoteRef.svelte';
|
|
29
13
|
let { token, children }: { token: StreamdownToken; children: Snippet } = $props();
|
|
14
|
+
const id = $props.id();
|
|
15
|
+
const streamdown = useStreamdown();
|
|
30
16
|
</script>
|
|
31
17
|
|
|
32
18
|
{#if token.type === 'heading'}
|
|
33
|
-
|
|
19
|
+
{@const level = `h${token.depth}` as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'}
|
|
20
|
+
{@const className = streamdown.theme[level].base}
|
|
21
|
+
<Slot
|
|
22
|
+
props={{
|
|
23
|
+
children,
|
|
24
|
+
token
|
|
25
|
+
}}
|
|
26
|
+
render={streamdown.snippets.heading}
|
|
27
|
+
>
|
|
28
|
+
<svelte:element this={level} class={className}>
|
|
29
|
+
{@render children()}
|
|
30
|
+
</svelte:element>
|
|
31
|
+
</Slot>
|
|
34
32
|
{:else if token.type === 'paragraph'}
|
|
35
|
-
<
|
|
33
|
+
<Slot props={{ children, token }} render={streamdown.snippets.paragraph}>
|
|
34
|
+
<p class={streamdown.theme.paragraph.base}>
|
|
35
|
+
{@render children()}
|
|
36
|
+
</p>
|
|
37
|
+
</Slot>
|
|
36
38
|
{:else if token.type === 'blockquote'}
|
|
37
|
-
<
|
|
39
|
+
<Slot props={{ children, token }} render={streamdown.snippets.blockquote}>
|
|
40
|
+
<blockquote class={streamdown.theme.blockquote.base}>
|
|
41
|
+
{@render children()}
|
|
42
|
+
</blockquote>
|
|
43
|
+
</Slot>
|
|
38
44
|
{:else if token.type === 'code' && token.lang === 'mermaid'}
|
|
39
|
-
<
|
|
45
|
+
<Slot props={{ children, token }} render={streamdown.snippets.code}>
|
|
46
|
+
<Mermaid {token} />
|
|
47
|
+
</Slot>
|
|
40
48
|
{:else if token.type === 'code'}
|
|
41
|
-
<
|
|
49
|
+
<Slot props={{ children, token }} render={streamdown.snippets.code}>
|
|
50
|
+
<Code {token} />
|
|
51
|
+
</Slot>
|
|
42
52
|
{:else if token.type === 'codespan'}
|
|
43
|
-
<
|
|
53
|
+
<Slot props={{ children, token }} render={streamdown.snippets.codespan}>
|
|
54
|
+
<code class={streamdown.theme.codespan.base}>
|
|
55
|
+
{token.text}
|
|
56
|
+
</code>
|
|
57
|
+
</Slot>
|
|
44
58
|
{:else if token.type === 'list'}
|
|
45
59
|
{#if token.ordered}
|
|
46
|
-
<
|
|
60
|
+
<Slot props={{ children, token }} render={streamdown.snippets.ol}>
|
|
61
|
+
<ol style:list-style-type={token.listType} class={streamdown.theme.ol.base}>
|
|
62
|
+
{@render children()}
|
|
63
|
+
</ol>
|
|
64
|
+
</Slot>
|
|
47
65
|
{:else}
|
|
48
|
-
<
|
|
66
|
+
<Slot props={{ children, token }} render={streamdown.snippets.ul}>
|
|
67
|
+
<ul class={streamdown.theme.ul.base}>
|
|
68
|
+
{@render children()}
|
|
69
|
+
</ul>
|
|
70
|
+
</Slot>
|
|
49
71
|
{/if}
|
|
50
72
|
{:else if token.type === 'list_item'}
|
|
51
|
-
<
|
|
73
|
+
<Slot props={{ children, token }} render={streamdown.snippets.li}>
|
|
74
|
+
<li
|
|
75
|
+
style:list-style-type={token.task ? 'none' : undefined}
|
|
76
|
+
{...token.value && !token.task ? { value: token.value } : {}}
|
|
77
|
+
class={streamdown.theme.li.base}
|
|
78
|
+
>
|
|
79
|
+
{#if token.task}
|
|
80
|
+
<input
|
|
81
|
+
disabled
|
|
82
|
+
type="checkbox"
|
|
83
|
+
checked={token.checked}
|
|
84
|
+
class={streamdown.theme.li.checkbox}
|
|
85
|
+
/>
|
|
86
|
+
{/if}
|
|
87
|
+
{@render children()}
|
|
88
|
+
</li>
|
|
89
|
+
</Slot>
|
|
52
90
|
{:else if token.type === 'table'}
|
|
53
|
-
<
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
91
|
+
<Slot props={{ token, children }} render={streamdown.snippets.table}>
|
|
92
|
+
<div class={streamdown.theme.table.base}>
|
|
93
|
+
<table class={streamdown.theme.table.table}>
|
|
94
|
+
{@render children()}
|
|
95
|
+
</table>
|
|
96
|
+
</div>
|
|
97
|
+
</Slot>
|
|
98
|
+
{:else if token.type === 'thead'}
|
|
99
|
+
<Slot props={{ token, children }} render={streamdown.snippets.thead}>
|
|
100
|
+
<thead class={streamdown.theme.thead.base}>
|
|
101
|
+
{@render children?.()}
|
|
102
|
+
</thead>
|
|
103
|
+
</Slot>
|
|
104
|
+
{:else if token.type === 'tbody'}
|
|
105
|
+
<Slot props={{ token, children }} render={streamdown.snippets.tbody}>
|
|
106
|
+
<tbody class={streamdown.theme.tbody.base}>
|
|
107
|
+
{@render children?.()}
|
|
108
|
+
</tbody>
|
|
109
|
+
</Slot>
|
|
110
|
+
{:else if token.type === 'tfoot'}
|
|
111
|
+
<Slot props={{ token, children }} render={streamdown.snippets.tfoot}>
|
|
112
|
+
<tfoot class={streamdown.theme.tfoot.base}>
|
|
113
|
+
{@render children?.()}
|
|
114
|
+
</tfoot>
|
|
115
|
+
</Slot>
|
|
116
|
+
{:else if token.type === 'tr'}
|
|
117
|
+
<Slot props={{ token, children }} render={streamdown.snippets.tr}>
|
|
118
|
+
<tr class={streamdown.theme.tr.base}>
|
|
119
|
+
{@render children?.()}
|
|
120
|
+
</tr>
|
|
121
|
+
</Slot>
|
|
122
|
+
{:else if token.type === 'td'}
|
|
123
|
+
{#if token.rowspan > 0}
|
|
124
|
+
<Slot props={{ children, token }} render={streamdown.snippets.td}>
|
|
125
|
+
<td
|
|
126
|
+
class={streamdown.theme.td.base}
|
|
127
|
+
{...token.colspan > 1 ? { colspan: token.colspan } : {}}
|
|
128
|
+
{...token.rowspan > 1 ? { rowspan: token.rowspan } : {}}
|
|
129
|
+
{...token.align && ['left', 'center', 'right', 'justify', 'char'].includes(token.align)
|
|
130
|
+
? { align: token.align as 'left' | 'center' | 'right' | 'justify' | 'char' }
|
|
131
|
+
: { align: 'left' }}
|
|
132
|
+
>
|
|
133
|
+
{@render children?.()}
|
|
134
|
+
</td>
|
|
135
|
+
</Slot>
|
|
136
|
+
{/if}
|
|
137
|
+
{:else if token.type === 'th'}
|
|
138
|
+
{#if token.rowspan > 0}
|
|
139
|
+
<Slot props={{ children, token }} render={streamdown.snippets.th}>
|
|
140
|
+
<th
|
|
141
|
+
class={streamdown.theme.th.base}
|
|
142
|
+
{...token.colspan > 1 ? { colspan: token.colspan } : {}}
|
|
143
|
+
{...token.rowspan > 1 ? { rowspan: token.rowspan } : {}}
|
|
144
|
+
{...token.align && ['left', 'center', 'right', 'justify', 'char'].includes(token.align)
|
|
145
|
+
? { align: token.align as 'left' | 'center' | 'right' | 'justify' | 'char' }
|
|
146
|
+
: { align: 'left' }}
|
|
147
|
+
>
|
|
148
|
+
{@render children?.()}
|
|
149
|
+
</th>
|
|
150
|
+
</Slot>
|
|
151
|
+
{/if}
|
|
60
152
|
{:else if token.type === 'image'}
|
|
61
153
|
<Image {token} {children} />
|
|
62
154
|
{:else if token.type === 'link'}
|
|
63
|
-
<
|
|
155
|
+
<Link {token} {children} />
|
|
156
|
+
{:else if token.type === 'sub'}
|
|
157
|
+
<Slot props={{ children, token }} render={streamdown.snippets.sub}>
|
|
158
|
+
<sub class={streamdown.theme.sub.base}>
|
|
159
|
+
{@render children()}
|
|
160
|
+
</sub>
|
|
161
|
+
</Slot>
|
|
162
|
+
{:else if token.type === 'sup'}
|
|
163
|
+
<Slot props={{ children, token }} render={streamdown.snippets.sup}>
|
|
164
|
+
<sup class={streamdown.theme.sup.base}>
|
|
165
|
+
{@render children()}
|
|
166
|
+
</sup>
|
|
167
|
+
</Slot>
|
|
64
168
|
{:else if token.type === 'strong'}
|
|
65
|
-
<
|
|
169
|
+
<Slot props={{ children, token }} render={streamdown.snippets.strong}>
|
|
170
|
+
<strong class={streamdown.theme.strong.base}>
|
|
171
|
+
{@render children()}
|
|
172
|
+
</strong>
|
|
173
|
+
</Slot>
|
|
66
174
|
{:else if token.type === 'em'}
|
|
67
|
-
<
|
|
175
|
+
<Slot props={{ children, token }} render={streamdown.snippets.em}>
|
|
176
|
+
<em class={streamdown.theme.em.base}>
|
|
177
|
+
{@render children()}
|
|
178
|
+
</em>
|
|
179
|
+
</Slot>
|
|
68
180
|
{:else if token.type === 'del'}
|
|
69
|
-
<
|
|
181
|
+
<Slot props={{ children, token }} render={streamdown.snippets.del}>
|
|
182
|
+
<del class={streamdown.theme.del.base}>
|
|
183
|
+
{@render children()}
|
|
184
|
+
</del>
|
|
185
|
+
</Slot>
|
|
70
186
|
{:else if token.type === 'hr'}
|
|
71
|
-
<
|
|
187
|
+
<Slot props={{ children, token }} render={streamdown.snippets.hr}>
|
|
188
|
+
<hr class={streamdown.theme.hr.base} />
|
|
189
|
+
</Slot>
|
|
72
190
|
{:else if token.type === 'br'}
|
|
73
191
|
<br />
|
|
74
192
|
{:else if token.type === 'math'}
|
|
75
|
-
<
|
|
193
|
+
<Slot
|
|
194
|
+
props={{
|
|
195
|
+
children,
|
|
196
|
+
token
|
|
197
|
+
}}
|
|
198
|
+
render={streamdown.snippets.math}
|
|
199
|
+
>
|
|
200
|
+
<Math {token} />
|
|
201
|
+
</Slot>
|
|
76
202
|
{:else if token.type === 'alert'}
|
|
77
203
|
<Alert {token} {children} />
|
|
204
|
+
{:else if token.type === 'footnoteRef'}
|
|
205
|
+
<FootnoteRef {token} />
|
|
78
206
|
{:else}
|
|
79
207
|
<!-- For tokens we don't handle specifically, render children or fallback -->
|
|
80
208
|
{@render children?.()}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../Streamdown.js';
|
|
3
|
+
import Slot from './Slot.svelte';
|
|
4
|
+
import type { FootnoteRef } from '../marked/marked-footnotes.js';
|
|
5
|
+
import {
|
|
6
|
+
autoPlacement,
|
|
7
|
+
computePosition,
|
|
8
|
+
autoUpdate,
|
|
9
|
+
hide,
|
|
10
|
+
offset,
|
|
11
|
+
shift
|
|
12
|
+
} from '@floating-ui/dom';
|
|
13
|
+
import { useClickOutside } from '../utils/useClickOutside.svelte.js';
|
|
14
|
+
import { scale } from 'svelte/transition';
|
|
15
|
+
import Block from '../Block.svelte';
|
|
16
|
+
import { useKeyDown } from '../utils/useKeyDown.svelte.js';
|
|
17
|
+
|
|
18
|
+
const streamdown = useStreamdown();
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
token
|
|
22
|
+
}: {
|
|
23
|
+
token: FootnoteRef;
|
|
24
|
+
} = $props();
|
|
25
|
+
|
|
26
|
+
const id = $props.id();
|
|
27
|
+
let isOpen = $state(false);
|
|
28
|
+
|
|
29
|
+
let reference = $state<HTMLButtonElement>();
|
|
30
|
+
let content = $state<HTMLDialogElement>();
|
|
31
|
+
|
|
32
|
+
const clickOutside = useClickOutside({
|
|
33
|
+
get isActive() {
|
|
34
|
+
return isOpen;
|
|
35
|
+
},
|
|
36
|
+
callback: () => {
|
|
37
|
+
isOpen = false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
useKeyDown({
|
|
42
|
+
keys: ['Escape'],
|
|
43
|
+
get isActive() {
|
|
44
|
+
return isOpen;
|
|
45
|
+
},
|
|
46
|
+
callback: () => {
|
|
47
|
+
isOpen = false;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const place = async (node: HTMLElement) => {
|
|
52
|
+
const middleware = [
|
|
53
|
+
hide(),
|
|
54
|
+
offset(0),
|
|
55
|
+
,
|
|
56
|
+
shift({
|
|
57
|
+
mainAxis: true
|
|
58
|
+
}),
|
|
59
|
+
autoPlacement({
|
|
60
|
+
allowedPlacements: ['top', 'top-end', 'top-start', 'bottom', 'bottom-end', 'bottom-start']
|
|
61
|
+
})
|
|
62
|
+
];
|
|
63
|
+
const { x, y, strategy, placement, middlewareData } = await computePosition(reference!, node, {
|
|
64
|
+
strategy: 'fixed',
|
|
65
|
+
middleware
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
Object.assign(node.style, {
|
|
69
|
+
position: strategy,
|
|
70
|
+
left: `${x}px`,
|
|
71
|
+
top: `${y}px`
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const popoverAttachment = (node: HTMLDialogElement) => {
|
|
76
|
+
content = node;
|
|
77
|
+
void place(node);
|
|
78
|
+
const off = autoUpdate(reference!, node, () => place(node));
|
|
79
|
+
return () => {
|
|
80
|
+
off();
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
{#if isOpen}
|
|
86
|
+
<Slot
|
|
87
|
+
props={{
|
|
88
|
+
token,
|
|
89
|
+
isOpen
|
|
90
|
+
}}
|
|
91
|
+
render={streamdown.snippets.footnotePopover}
|
|
92
|
+
>
|
|
93
|
+
<dialog
|
|
94
|
+
id={'footnote-popover-' + id}
|
|
95
|
+
aria-modal="false"
|
|
96
|
+
transition:scale|global={{ start: 0.95, duration: 100 }}
|
|
97
|
+
{@attach clickOutside.attachment}
|
|
98
|
+
{@attach popoverAttachment}
|
|
99
|
+
open
|
|
100
|
+
class={`${streamdown.theme.footnotePopover.base}`}
|
|
101
|
+
>
|
|
102
|
+
{#each token.content.lines as line}
|
|
103
|
+
<Block block={line} />
|
|
104
|
+
{/each}
|
|
105
|
+
</dialog>
|
|
106
|
+
</Slot>
|
|
107
|
+
{/if}
|
|
108
|
+
|
|
109
|
+
<Slot
|
|
110
|
+
props={{
|
|
111
|
+
token
|
|
112
|
+
}}
|
|
113
|
+
render={streamdown.snippets.footnoteRef}
|
|
114
|
+
>
|
|
115
|
+
<button
|
|
116
|
+
bind:this={reference}
|
|
117
|
+
class={streamdown.theme.footnoteRef.base}
|
|
118
|
+
onclick={() => (isOpen = !isOpen)}
|
|
119
|
+
aria-expanded={isOpen}
|
|
120
|
+
aria-haspopup="dialog"
|
|
121
|
+
aria-controls={'footnote-popover-' + id}
|
|
122
|
+
{@attach clickOutside.attachment}
|
|
123
|
+
>
|
|
124
|
+
{token.label.replace('^', '')}
|
|
125
|
+
</button>
|
|
126
|
+
</Slot>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FootnoteRef } from '../marked/marked-footnotes.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: FootnoteRef;
|
|
4
|
+
};
|
|
5
|
+
declare const FootnoteRef: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type FootnoteRef = ReturnType<typeof FootnoteRef>;
|
|
7
|
+
export default FootnoteRef;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { useStreamdown } from '../Streamdown.
|
|
2
|
+
import { useStreamdown } from '../Streamdown.js';
|
|
3
3
|
import { transformUrl } from '../utils/url.js';
|
|
4
4
|
import Slot from './Slot.svelte';
|
|
5
5
|
import type { Tokens } from 'marked';
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
children,
|
|
29
29
|
token
|
|
30
30
|
}}
|
|
31
|
-
render={streamdown.snippets.
|
|
31
|
+
render={streamdown.snippets.image}
|
|
32
32
|
>
|
|
33
|
-
<div class={streamdown.theme.
|
|
34
|
-
<img class={streamdown.theme.
|
|
33
|
+
<div class={streamdown.theme.image.base}>
|
|
34
|
+
<img class={streamdown.theme.image.image} src={transformedUrl} alt={token.text} />
|
|
35
35
|
</div>
|
|
36
36
|
</Slot>
|
|
37
37
|
{:else}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { useStreamdown } from '../Streamdown.
|
|
2
|
+
import { useStreamdown } from '../Streamdown.js';
|
|
3
3
|
import { transformUrl } from '../utils/url.js';
|
|
4
4
|
import Slot from './Slot.svelte';
|
|
5
5
|
import type { Tokens } from 'marked';
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
children,
|
|
31
31
|
token
|
|
32
32
|
}}
|
|
33
|
-
render={streamdown.snippets.
|
|
33
|
+
render={streamdown.snippets.link}
|
|
34
34
|
>
|
|
35
35
|
<a
|
|
36
|
-
class={streamdown.theme.
|
|
36
|
+
class={streamdown.theme.link.base}
|
|
37
37
|
href={transformedUrl}
|
|
38
38
|
target="_blank"
|
|
39
39
|
rel="noopener noreferrer"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
</Slot>
|
|
44
44
|
{:else}
|
|
45
45
|
<span
|
|
46
|
-
class={streamdown.theme.
|
|
46
|
+
class={streamdown.theme.link.blocked}
|
|
47
47
|
title={token.title ? `Blocked URL: ${token.href}` : undefined}
|
|
48
48
|
>
|
|
49
49
|
{@render children()} [blocked]
|
|
@@ -4,6 +4,6 @@ type $$ComponentProps = {
|
|
|
4
4
|
children: Snippet;
|
|
5
5
|
token: Tokens.Link;
|
|
6
6
|
};
|
|
7
|
-
declare const
|
|
8
|
-
type
|
|
9
|
-
export default
|
|
7
|
+
declare const Link: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type Link = ReturnType<typeof Link>;
|
|
9
|
+
export default Link;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, untrack } from 'svelte';
|
|
3
|
-
import { useStreamdown } from '../Streamdown.
|
|
3
|
+
import { useStreamdown } from '../Streamdown.js';
|
|
4
4
|
import Slot from './Slot.svelte';
|
|
5
5
|
import type { MathToken } from '../marked/index.js';
|
|
6
6
|
import type { Snippet } from 'svelte';
|
|
@@ -10,17 +10,13 @@
|
|
|
10
10
|
const streamdown = useStreamdown();
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
|
-
children,
|
|
14
13
|
token
|
|
15
14
|
}: {
|
|
16
|
-
children: Snippet;
|
|
17
15
|
token: MathToken;
|
|
18
16
|
} = $props();
|
|
19
17
|
|
|
20
18
|
const isInline = $derived(token.isInline);
|
|
21
19
|
|
|
22
|
-
console.log({ token });
|
|
23
|
-
|
|
24
20
|
let katexInstance = $state<typeof import('katex') | null>(null);
|
|
25
21
|
|
|
26
22
|
onMount(() => {
|
|
@@ -42,6 +38,7 @@
|
|
|
42
38
|
: streamdown.katexConfig || {})
|
|
43
39
|
};
|
|
44
40
|
const code = token.text;
|
|
41
|
+
|
|
45
42
|
try {
|
|
46
43
|
return katexInstance.renderToString(code, config);
|
|
47
44
|
} catch (error) {
|
|
@@ -52,24 +49,16 @@
|
|
|
52
49
|
});
|
|
53
50
|
</script>
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{@html html}
|
|
65
|
-
</span>
|
|
66
|
-
{:else}
|
|
67
|
-
<div class="h-fit w-full">
|
|
68
|
-
<div class="overflow-x-auto">
|
|
69
|
-
<div bind:this={inner} class={streamdown.theme.math.base}>
|
|
70
|
-
{@html html}
|
|
71
|
-
</div>
|
|
52
|
+
{#if isInline}
|
|
53
|
+
<span bind:this={inner} class={streamdown.theme.math.inline}>
|
|
54
|
+
{@html html}
|
|
55
|
+
</span>
|
|
56
|
+
{:else}
|
|
57
|
+
<div class="h-fit w-full">
|
|
58
|
+
<div class="overflow-x-auto">
|
|
59
|
+
<div bind:this={inner} class={streamdown.theme.math.block}>
|
|
60
|
+
{@html html}
|
|
72
61
|
</div>
|
|
73
62
|
</div>
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
</div>
|
|
64
|
+
{/if}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { MathToken } from '../marked/index.js';
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
2
|
import 'katex/dist/katex.min.css';
|
|
4
3
|
type $$ComponentProps = {
|
|
5
|
-
children: Snippet;
|
|
6
4
|
token: MathToken;
|
|
7
5
|
};
|
|
8
6
|
declare const Math: import("svelte").Component<$$ComponentProps, {}, "">;
|