HTMLRenderer.svelte 750 B

123456789101112131415161718192021222324252627282930
  1. <script lang="ts">
  2. import Image from '$lib/components/common/Image.svelte';
  3. import CodeBlock from './CodeBlock.svelte';
  4. /* The html content of the tag */
  5. export let html; //: string;
  6. let parsedHTML = [html];
  7. export let images;
  8. export let codes;
  9. // all images are in {{IMAGE_0}}, {{IMAGE_1}}.... format
  10. // all codes are in {{CODE_0}}, {{CODE_1}}.... format
  11. const rules = [];
  12. rules.forEach((rule) => {
  13. parsedHTML = parsedHTML.map((substr) => substr.split(rule.regex)).flat();
  14. });
  15. </script>
  16. {#each parsedHTML as part}
  17. {@const match = rules.find((rule) => rule.regex.test(part))}
  18. {#if match}
  19. <svelte:component this={match.component} {...match.props}>
  20. {@html part}
  21. </svelte:component>
  22. {:else}
  23. {@html part}
  24. {/if}
  25. {/each}