Commit 3a478b4 1 parent a669241 commit 3a478b4 Copy full SHA for 3a478b4
File tree 3 files changed +12
-8
lines changed
3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 4
4
import { Lexer } from ' marked' ;
5
5
6
6
interface Props {
7
- content: string ;
7
+ content: string | undefined ;
8
8
}
9
9
10
10
let { content }: Props = $props ();
11
11
12
- const lexer = new Lexer (options );
13
- const tokens = lexer .lex (content );
12
+ const tokens = $derived .by (() => {
13
+ const lexer = new Lexer (options );
14
+ return lexer .lex (content ?? ' ' );
15
+ });
14
16
</script >
15
17
16
18
<div class =" markdown-content" >
17
- <MarkdownContent type ="init" {tokens } />
19
+ {#if tokens }
20
+ <MarkdownContent type ="init" {tokens } />
21
+ {/if }
18
22
</div >
19
23
20
24
<style >
Original file line number Diff line number Diff line change 19
19
| Tokens .List ;
20
20
21
21
const { type, ... rest }: Props = $props ();
22
-
23
- const CurrentComponent = renderers [type ] as Component <Props >;
24
22
</script >
25
23
26
24
{#if (! type || type === ' init' ) && ' tokens' in rest && rest .tokens }
27
25
{#each rest .tokens as token }
28
26
<svelte:self {...token } />
29
27
{/each }
30
28
{:else if renderers [type ]}
29
+ {@const CurrentComponent = renderers [type ] as Component <Props >}
31
30
{#if type === ' list' }
32
31
{@const listItems = (rest as Extract <Props , { type: ' list' }>).items }
33
32
<CurrentComponent {...rest }>
39
38
{/each }
40
39
</CurrentComponent >
41
40
{:else }
42
- <CurrentComponent this ={ renderers [ type ]} {...rest }>
41
+ <CurrentComponent {...rest }>
43
42
{#if ' tokens' in rest && rest .tokens }
44
43
<svelte:self tokens ={rest .tokens } />
45
44
{:else if ' raw' in rest }
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ export const renderers = {
22
22
list_item : ListItem ,
23
23
heading : Heading ,
24
24
paragraph : Paragraph ,
25
- init : null
25
+ init : null ,
26
+ space : null
26
27
} ;
27
28
28
29
export const options = {
You can’t perform that action at this time.
0 commit comments