mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Sanitize markdown content
Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
+18
-1
@@ -1,11 +1,28 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { marked } from "marked";
|
||||
import sanitizeHtml from 'sanitize-html';
|
||||
|
||||
export let content: string;
|
||||
|
||||
let container: HTMLElement;
|
||||
|
||||
const sanitize = (content: string): string => {
|
||||
return sanitizeHtml(marked.parse(content), {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
|
||||
"img",
|
||||
"audio",
|
||||
"video",
|
||||
]),
|
||||
allowedAttributes: {
|
||||
...sanitizeHtml.defaults.allowedAttributes,
|
||||
video: ["src"],
|
||||
audio: ["src"],
|
||||
},
|
||||
disallowedTagsMode: "escape",
|
||||
});
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
// Don't underline <a> tags that contain images.
|
||||
let elems = container.querySelectorAll("a");
|
||||
@@ -162,6 +179,6 @@
|
||||
|
||||
{#if content}
|
||||
<div class="markdown" bind:this={container}>
|
||||
{@html marked(content)}
|
||||
{@html marked(sanitize(content))}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user