From 7c29fae1a7426b47a63f30b586d6e69c4949d2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 23 Sep 2026 17:43:55 +0200 Subject: [PATCH] Render checkboxes in markdown with appropriate styling --- src/components/Markdown.svelte | 46 ++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/components/Markdown.svelte b/src/components/Markdown.svelte index 1d32c8de9..f91c28f8c 100644 --- a/src/components/Markdown.svelte +++ b/src/components/Markdown.svelte @@ -3,7 +3,7 @@ import dompurify from "dompurify"; import { toDom } from "hast-util-to-dom"; - import { tick } from "svelte"; + import { mount, tick, unmount } from "svelte"; import { parseFrontmatter } from "@app/lib/frontmatter"; import { invoke } from "@app/lib/invoke"; @@ -11,6 +11,8 @@ import { highlight } from "@app/lib/syntax"; import { isCommit, scrollIntoView, twemoji } from "@app/lib/utils"; + import Icon from "@app/components/Icon.svelte"; + interface Props { rid?: string; content: string; @@ -46,12 +48,28 @@ // eslint-disable-next-line @typescript-eslint/no-unused-expressions content; + const icons: ReturnType[] = []; + void tick().then(() => { // Don't run this if the component hasn't mounted yet. if (container === null) { return; } + // Replace native task-list checkboxes with read-only styled boxes. + for (const i of container.querySelectorAll('input[type="checkbox"]')) { + i.parentElement?.classList.add("task-item"); + const box = document.createElement("span"); + box.classList.add("task-box"); + if (i.hasAttribute("checked")) { + box.classList.add("checked"); + icons.push( + mount(Icon, { target: box, props: { name: "checkmark" } }), + ); + } + i.replaceWith(box); + } + for (const e of container.querySelectorAll("a")) { try { const url = new URL(e.href); @@ -173,6 +191,12 @@ scrollIntoView(window.location.hash.substring(1)); } }); + + return () => { + for (const icon of icons) { + void unmount(icon); + } + }; }); @@ -270,12 +294,24 @@ } .markdown :global(li.task-item) { - display: flex; - align-items: center; - gap: 0.5rem; - margin-left: -1.2rem; + list-style-type: none; color: var(--color-text-secondary); } + .markdown :global(li.task-item .task-box) { + display: inline-flex; + align-items: center; + justify-content: center; + width: 1.25rem; + height: 1.25rem; + margin-right: 0.5rem; + vertical-align: middle; + border: 1px solid var(--color-border-mid); + border-radius: var(--border-radius-md); + background-color: var(--color-surface-base); + } + .markdown :global(li.task-item .task-box.checked) { + color: var(--color-text-brand); + } .markdown :global(li.task-item:not(:last-child)) { margin-bottom: 0.25rem; }