2024-08-05 15:47:18 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import type { Token } from 'marked';
|
2024-08-08 22:01:38 +00:00
|
|
|
import { revertSanitizedResponseContent, unescapeHtml } from '$lib/utils';
|
2024-08-08 18:46:39 +00:00
|
|
|
import { onMount } from 'svelte';
|
2024-08-05 15:47:18 +00:00
|
|
|
import Image from '$lib/components/common/Image.svelte';
|
2024-08-08 22:01:38 +00:00
|
|
|
|
|
|
|
import KatexRenderer from './KatexRenderer.svelte';
|
|
|
|
|
2024-08-05 15:47:18 +00:00
|
|
|
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'}
|
2024-08-08 22:01:38 +00:00
|
|
|
<code class="codespan">{revertSanitizedResponseContent(token.raw)}</code>
|
2024-08-05 15:47:18 +00:00
|
|
|
{:else if token.type === 'br'}
|
|
|
|
<br />
|
|
|
|
{:else if token.type === 'del'}
|
|
|
|
<del>
|
|
|
|
<svelte:self id={`${id}-del`} tokens={token.tokens} />
|
|
|
|
</del>
|
2024-08-08 22:01:38 +00:00
|
|
|
{:else if token.type === 'inlineKatex'}
|
|
|
|
{#if token.text}
|
|
|
|
<KatexRenderer
|
|
|
|
content={revertSanitizedResponseContent(token.text)}
|
|
|
|
displayMode={token?.displayMode ?? false}
|
|
|
|
/>
|
|
|
|
{/if}
|
2024-08-05 15:47:18 +00:00
|
|
|
{:else if token.type === 'text'}
|
2024-08-08 22:01:38 +00:00
|
|
|
{token.raw}
|
2024-08-05 15:47:18 +00:00
|
|
|
{/if}
|
|
|
|
{/each}
|