From 8c170961cb79d5093cf0989e3bc429fd6d12092c Mon Sep 17 00:00:00 2001 From: jviide Date: Mon, 16 Jan 2023 20:04:27 +0200 Subject: [PATCH] feat: support all HTML elements allowed by Glitch (#1233) Closes https://github.com/elk-zone/elk/issues/1230 --- composables/content-parse.ts | 37 ++++++++++++++++--- tests/__snapshots__/content-rich.test.ts.snap | 2 +- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/composables/content-parse.ts b/composables/content-parse.ts index 1e45ab99..b113eaa1 100644 --- a/composables/content-parse.ts +++ b/composables/content-parse.ts @@ -35,12 +35,35 @@ const sanitizer = sanitize({ code: { class: filterClasses(/^language-\w+$/), }, - // other elements supported in glitch - h1: {}, - ol: {}, - ul: {}, - li: {}, + // Other elements supported in glitch, as seen in + // https://github.com/glitch-soc/mastodon/blob/13227e1dafd308dfe1a3effc3379b766274809b3/lib/sanitize_ext/sanitize_config.rb#L75 + abbr: { + title: keep, + }, + del: {}, + blockquote: { + cite: filterHref(), + }, + b: {}, + strong: {}, + u: {}, + sub: {}, + sup: {}, + i: {}, em: {}, + h1: {}, + h2: {}, + h3: {}, + h4: {}, + h5: {}, + ul: {}, + ol: { + start: keep, + reversed: keep, + }, + li: { + value: keep, + }, }) /** @@ -255,6 +278,10 @@ function filterClasses(allowed: RegExp) { } } +function keep(value: string | undefined) { + return value +} + function set(value: string) { return () => value } diff --git a/tests/__snapshots__/content-rich.test.ts.snap b/tests/__snapshots__/content-rich.test.ts.snap index 85001328..cd75bdac 100644 --- a/tests/__snapshots__/content-rich.test.ts.snap +++ b/tests/__snapshots__/content-rich.test.ts.snap @@ -92,7 +92,7 @@ exports[`content-rich > handles formatting from servers 1`] = `