1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-26 00:09:38 +02:00

feat: Add file type validation and sanitize markdown input in adventure components

This commit is contained in:
Sean Morley 2025-03-15 12:29:12 -04:00
parent 50a732b4d7
commit 7fbcf170d0
6 changed files with 84 additions and 8 deletions

View file

@ -1,6 +1,7 @@
<script lang="ts">
import { marked } from 'marked'; // Import the markdown parser
import { t } from 'svelte-i18n';
import DOMPurify from 'dompurify'; // Import DOMPurify to sanitize HTML
export let text: string | null | undefined = ''; // Markdown text
export let editor_height: string = 'h-64'; // Editor height
@ -8,7 +9,7 @@
// Function to parse markdown to HTML
const renderMarkdown = (markdown: string) => {
return marked(markdown);
return marked(markdown) as string;
};
// References for scroll syncing
@ -61,7 +62,7 @@
class="prose overflow-auto h-96 max-w-full w-full p-4 border border-base-300 rounded-lg bg-base-300"
bind:this={previewRef}
>
{@html renderMarkdown(text || '')}
{@html DOMPurify.sanitize(renderMarkdown(text || ''))}
</article>
{/if}
</div>