MarkdownInlineTokens.svelte 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <script lang="ts">
  2. import type { Token } from 'marked';
  3. import { unescapeHtml } from '$lib/utils';
  4. import { onMount } from 'svelte';
  5. import { revertSanitizedResponseContent } from '$lib/utils/index.js';
  6. import Image from '$lib/components/common/Image.svelte';
  7. export let id: string;
  8. export let tokens: Token[];
  9. onMount(() => {
  10. console.log('MarkdownInlineTokens', id, tokens, top);
  11. });
  12. </script>
  13. {#each tokens as token}
  14. {#if token.type === 'escape'}
  15. {unescapeHtml(token.text)}
  16. {:else if token.type === 'html'}
  17. {@html token.text}
  18. {:else if token.type === 'link'}
  19. <a href={token.href} target="_blank" rel="nofollow" title={token.title}>{token.text}</a>
  20. {:else if token.type === 'image'}
  21. <Image src={token.href} alt={token.text} />
  22. {:else if token.type === 'strong'}
  23. <strong>
  24. <svelte:self id={`${id}-strong`} tokens={token.tokens} />
  25. </strong>
  26. {:else if token.type === 'em'}
  27. <em>
  28. <svelte:self id={`${id}-em`} tokens={token.tokens} />
  29. </em>
  30. {:else if token.type === 'codespan'}
  31. <code class="codespan">{unescapeHtml(token.text.replaceAll('&amp;', '&'))}</code>
  32. {:else if token.type === 'br'}
  33. <br />
  34. {:else if token.type === 'del'}
  35. <del>
  36. <svelte:self id={`${id}-del`} tokens={token.tokens} />
  37. </del>
  38. {:else if token.type === 'text'}
  39. {unescapeHtml(token.text)}
  40. {/if}
  41. {/each}