MarkdownInlineTokens.svelte 1.37 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
<script lang="ts">
	import type { Token } from 'marked';
Timothy J. Baek's avatar
Timothy J. Baek committed
3
	import { revertSanitizedResponseContent, unescapeHtml } from '$lib/utils';
Timothy J. Baek's avatar
fix  
Timothy J. Baek committed
4
	import { onMount } from 'svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
5
	import Image from '$lib/components/common/Image.svelte';
Timothy J. Baek's avatar
Timothy J. Baek committed
6
7
8

	import KatexRenderer from './KatexRenderer.svelte';

Timothy J. Baek's avatar
Timothy J. Baek committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	export let id: string;
	export let tokens: Token[];
</script>

{#each tokens as token}
	{#if token.type === 'escape'}
		{unescapeHtml(token.text)}
	{:else if token.type === 'html'}
		{@html token.text}
	{:else if token.type === 'link'}
		<a href={token.href} target="_blank" rel="nofollow" title={token.title}>{token.text}</a>
	{:else if token.type === 'image'}
		<Image src={token.href} alt={token.text} />
	{:else if token.type === 'strong'}
		<strong>
			<svelte:self id={`${id}-strong`} tokens={token.tokens} />
		</strong>
	{:else if token.type === 'em'}
		<em>
			<svelte:self id={`${id}-em`} tokens={token.tokens} />
		</em>
	{:else if token.type === 'codespan'}
Timothy J. Baek's avatar
Timothy J. Baek committed
31
		<code class="codespan">{revertSanitizedResponseContent(token.raw)}</code>
Timothy J. Baek's avatar
Timothy J. Baek committed
32
33
34
35
36
37
	{:else if token.type === 'br'}
		<br />
	{:else if token.type === 'del'}
		<del>
			<svelte:self id={`${id}-del`} tokens={token.tokens} />
		</del>
Timothy J. Baek's avatar
Timothy J. Baek committed
38
39
	{:else if token.type === 'inlineKatex'}
		{#if token.text}
Timothy J. Baek's avatar
Timothy J. Baek committed
40
			<KatexRenderer content={revertSanitizedResponseContent(token.text)} displayMode={false} />
Timothy J. Baek's avatar
Timothy J. Baek committed
41
		{/if}
Timothy J. Baek's avatar
Timothy J. Baek committed
42
	{:else if token.type === 'text'}
Timothy J. Baek's avatar
Timothy J. Baek committed
43
		{token.raw}
Timothy J. Baek's avatar
Timothy J. Baek committed
44
45
	{/if}
{/each}