MarkdownInlineTokens.svelte 1.1 KB

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