Skip to content

Commit 1e3008a

Browse files
committed
add HTML compat for text, sanitise HTML
1 parent b0c8480 commit 1e3008a

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

bun.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"typescript": "~5.8.3"
1111
},
1212
"dependencies": {
13+
"dompurify": "^3.2.6",
1314
"jszip": "^3.10.1",
1415
"typescript-event-target": "^1.1.1",
1516
"vite": "^7.1.0"

src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import JSZip from "jszip";
2+
import DOMPurify from "dompurify";
23
import type { Datapack } from "./datapack";
34
import { DatapackModifierInstance, type DatapackChangeMethod, type DatapackChangeValue } from "./datapack_changes";
45

@@ -114,8 +115,11 @@ export class ConfigClass {
114115

115116
const widgetText = clone.querySelector(".widget-text") as HTMLElement | null;
116117
const inputElement = clone.querySelector(".widget-input") as HTMLInputElement | null;
117-
118-
if ("text" in element && widgetText) widgetText.innerText = element.text;
118+
119+
if ("text" in element && widgetText) {
120+
const sanitized_html = DOMPurify.sanitize(element.text);
121+
widgetText.innerHTML = sanitized_html;
122+
}
119123

120124
if (type === "switch") {
121125
(clone.querySelector(".widget-switch-input") as HTMLInputElement).checked = !(

style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,21 @@ input[type="range"]::-moz-range-thumb {
280280
color: inherit;
281281
font-family: inherit;
282282
}
283+
.text-widget {
284+
padding-top: 0.25em;
285+
padding-bottom: 0.25em;
286+
line-height: 1.25;
287+
}
288+
.heading-widget {
289+
padding-top: 0.25em;
290+
padding-bottom: 0.25em;
291+
line-height: 1.25;
292+
}
293+
.title-widget {
294+
padding-top: 0.25em;
295+
padding-bottom: 0.25em;
296+
line-height: 1.25;
297+
}
283298

284299
footer {
285300
p {

0 commit comments

Comments
 (0)