添加 DOMPurify 安全检查
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-11-11 14:31:35 +08:00
parent 0f4f53ef6f
commit 2a5650a8ef
3 changed files with 113 additions and 3 deletions

View File

@ -6,10 +6,11 @@ import "./main.css";
import Prism from "prismjs";
import { onMount } from "svelte";
import DOMPurify from "isomorphic-dompurify";
let version = 0;
let content = `
let content_unsafe = `
# This is a header
This is a paragraph $E = mc^2$
* This is a list
@ -22,6 +23,14 @@ This is a paragraph $E = mc^2$
|-------------|---------|
| With two | columns |
`;
let content: string = '';
$: content = (() => {
let c = DOMPurify.sanitize(content_unsafe, {})
// console.log(c)
return c
})()
let source = "";
import { tick } from "svelte";
@ -109,7 +118,7 @@ onMount(async () => {
</script>
<textarea name="content" id="content" bind:value={content}></textarea>
<textarea name="content" id="content" bind:value={content_unsafe}></textarea>
<button id="button" on:click={updateSource}>Render</button>
<svelte:head>