Skip to content

Commit

Permalink
Improve sanitization of model output (huggingface#1341)
Browse files Browse the repository at this point in the history
* Improve sanitization of model output

* make it compatible with SSR

* fix formatting issues
  • Loading branch information
nsarrazin authored Jul 16, 2024
1 parent aac1ebf commit b6c54e3
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 15 deletions.
265 changes: 256 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.30.4",
"@tailwindcss/typography": "^0.5.9",
"@types/dompurify": "^3.0.5",
"@types/express": "^4.17.21",
"@types/js-yaml": "^4.0.9",
"@types/jsdom": "^21.1.1",
Expand All @@ -31,9 +32,11 @@
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.x",
"@typescript-eslint/parser": "^6.x",
"dompurify": "^3.1.6",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
"isomorphic-dompurify": "^2.13.0",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"prettier": "^2.8.0",
Expand Down
6 changes: 4 additions & 2 deletions src/lib/components/CodeBlock.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { afterUpdate } from "svelte";
import CopyToClipBoardBtn from "./CopyToClipBoardBtn.svelte";
import DOMPurify from "isomorphic-dompurify";
export let code = "";
export let lang = "";
Expand All @@ -19,8 +20,9 @@
<!-- eslint-disable svelte/no-at-html-tags -->
<pre
class="scrollbar-custom overflow-auto px-5 scrollbar-thumb-gray-500 hover:scrollbar-thumb-gray-400 dark:scrollbar-thumb-white/10 dark:hover:scrollbar-thumb-white/20"><code
class="language-{lang}">{@html highlightedCode || code.replaceAll("<", "&lt;")}</code
></pre>
class="language-{lang}"
>{@html DOMPurify.sanitize(highlightedCode || code.replaceAll("<", "&lt;"))}
</code></pre>
<CopyToClipBoardBtn
classNames="absolute top-2 right-2 invisible opacity-0 group-hover:visible group-hover:opacity-100"
value={code}
Expand Down
Loading

0 comments on commit b6c54e3

Please sign in to comment.