Skip to content

Commit

Permalink
feat: Sanitized basic Markdown rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Junk committed Nov 9, 2023
1 parent 66550ff commit d584b3a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
20 changes: 19 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"type": "module",
"dependencies": {
"boxicons": "^2.1.4",
"chota": "^0.9.2"
"chota": "^0.9.2",
"dompurify": "^3.0.6",
"marked": "^9.1.5"
}
}
8 changes: 7 additions & 1 deletion src/lib/KeyValue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
-->

<script lang="ts">
import { marked } from "marked";
import DOMPurify from "dompurify";
export let keys: Array<String>;
export let values: any;
export let compact = false;
Expand All @@ -21,7 +23,11 @@
<table>
<tbody>
{#if key == "text" || key == "Text"}
<tr><td style={keyStyle}>{key}</td><td class="value">{values[index]}</td></tr>
<tr
><td style={keyStyle}>{key}</td><td class="value"
>{@html DOMPurify.sanitize(marked.parse(values[index]))}</td
></tr
>
{:else}
<tr><td style={keyStyle}>{key}</td><td class="value">{values[index]}</td></tr>
{/if}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/singleview/notes/Note.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import Collapsible from "$lib/Collapsible.svelte";
import KeyValue from "../../KeyValue.svelte";
import type { Note } from "$lib/singleview/docmodel/docmodeltypes";
import { marked } from "marked";
import DOMPurify from "dompurify";
export let note: Note;
let keys: string[] = [];
let values: string[] = [];
Expand All @@ -30,7 +32,7 @@
<p />
<h6>Text</h6>
<div class="text">
{note.text}
{@html DOMPurify.sanitize(marked.parse(note.text))}
</div>
</Collapsible>

Expand Down

0 comments on commit d584b3a

Please sign in to comment.