mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-20 22:00:43 +08:00
Revert HTML tag escaping
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -2,14 +2,13 @@
|
||||
import dompurify from "dompurify";
|
||||
import { marked } from "marked";
|
||||
|
||||
import { renderer, walkTokens } from "@app/lib/markdown";
|
||||
import { renderer } from "@app/lib/markdown";
|
||||
import { twemoji } from "@app/lib/utils";
|
||||
|
||||
export let content: string;
|
||||
export let fontSize: "tiny" | "small" | "medium" = "small";
|
||||
|
||||
marked.use({
|
||||
walkTokens,
|
||||
renderer,
|
||||
// TODO: Disables deprecated options, remove once removed from marked
|
||||
mangle: false,
|
||||
@@ -17,8 +16,7 @@
|
||||
});
|
||||
|
||||
const render = (content: string): string =>
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
dompurify.sanitize(marked.parseInline(content), { SANITIZE_DOM: false });
|
||||
dompurify.sanitize(marked.parseInline(content));
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import {
|
||||
markdownExtensions as extensions,
|
||||
renderer,
|
||||
walkTokens,
|
||||
} from "@app/lib/markdown";
|
||||
import { updateProjectRoute } from "@app/views/projects/router";
|
||||
|
||||
@@ -27,7 +26,6 @@
|
||||
);
|
||||
marked.use({
|
||||
extensions,
|
||||
walkTokens,
|
||||
renderer,
|
||||
// TODO: Disables deprecated options, remove once removed from marked
|
||||
mangle: false,
|
||||
@@ -37,8 +35,7 @@
|
||||
let container: HTMLElement;
|
||||
|
||||
const render = (content: string): string =>
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
dompurify.sanitize(marked.parse(content), { SANITIZE_DOM: false });
|
||||
dompurify.sanitize(marked.parse(content));
|
||||
|
||||
function navigateToMarkdownLink(event: any) {
|
||||
if (event.target.matches(".file-link")) {
|
||||
|
||||
+7
-13
@@ -1,9 +1,15 @@
|
||||
import dompurify from "dompurify";
|
||||
import emojis from "@app/lib/emojis";
|
||||
import katex from "katex";
|
||||
import { marked } from "marked";
|
||||
import { isUrl } from "@app/lib/utils";
|
||||
|
||||
const trustedHtmlTags = ["small", "dl", "dt", "dd", "code"];
|
||||
dompurify.setConfig({
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
SANITIZE_DOM: false,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
FORBID_TAGS: ["textarea", "style"],
|
||||
});
|
||||
|
||||
// TODO: Disables deprecated options, remove once removed from marked
|
||||
marked.use({ mangle: false, headerIds: false });
|
||||
@@ -120,18 +126,6 @@ const anchorMarkedExtension = {
|
||||
},
|
||||
};
|
||||
|
||||
export const walkTokens = (token: marked.Tokens.Generic) => {
|
||||
if (token.type !== "code" && token.type !== "codespan" && "text" in token) {
|
||||
if (trustedHtmlTags.some(tag => token.text.includes(tag))) {
|
||||
return;
|
||||
}
|
||||
token.text = token.text.replace(
|
||||
/<([^>]+)>/g,
|
||||
(_match: RegExpMatchArray, tagContent: string) => `<${tagContent}>`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const renderer = {
|
||||
// Overwrites the rendering of heading tokens.
|
||||
// Since there are possible non ASCII characters in headings,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
import DOMPurify from "dompurify";
|
||||
import dompurify from "dompurify";
|
||||
import ProjectLink from "@app/components/ProjectLink.svelte";
|
||||
import { formatNodeId, twemoji } from "@app/lib/utils";
|
||||
|
||||
@@ -110,6 +110,6 @@
|
||||
<Clipboard small text={projectId} />
|
||||
</div>
|
||||
<div class="description" use:twemoji>
|
||||
{@html DOMPurify.sanitize(linkifyDescription(projectDescription))}
|
||||
{@html dompurify.sanitize(linkifyDescription(projectDescription))}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
BIN
Binary file not shown.
@@ -182,13 +182,3 @@ test("relative image not able to being loaded", async ({ page }) => {
|
||||
});
|
||||
await expect(page).toHaveScreenshot({ fullPage: true });
|
||||
});
|
||||
|
||||
test("rendering of html tags", async ({ page }) => {
|
||||
await page.goto(`${markdownUrl}/tree/main/tag-rendering.md#html-tags`, {
|
||||
waitUntil: "networkidle",
|
||||
});
|
||||
await expect(
|
||||
page.locator("text=Rendering of html tags").first(),
|
||||
).toBeVisible();
|
||||
await expect(page).toHaveScreenshot({ fullPage: true });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user