From 028fd5627d872182eb7ca92d69de91124fc4f701 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 15 Jun 2026 20:26:42 +0000 Subject: [PATCH] Wrap selection in a plain spoiler callout, not a code block The code fence broke markdown rendering inside the spoiler. Wrap now emits a collapsible `> [!spoiler]-` callout with the selection as continuation lines, preserving inner markdown. Unwrap still strips the old fenced format for backwards compatibility. Co-Authored-By: Claude Opus 4.8 (1M context) --- main.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.ts b/main.ts index 278f93a..a9db790 100644 --- a/main.ts +++ b/main.ts @@ -17,26 +17,28 @@ export function isSpoiler(text: string): boolean { } /** - * Wraps arbitrary text in a collapsible spoiler callout containing a fenced - * code block: + * Wraps arbitrary text in a collapsible spoiler callout. Each line of the + * selection becomes a callout continuation line, so the markdown inside the + * spoiler is preserved: * * ``` * > [!spoiler]- - * >``` - * >selected text - * >``` + * > selected text * ``` */ export function wrapSpoiler(text: string): string { - const body = text.split("\n").map((line) => ">" + line).join("\n"); - return ["> [!spoiler]-", ">```", body, ">```"].join("\n"); + const body = text + .split("\n") + .map((line) => (line === "" ? ">" : "> " + line)) + .join("\n"); + return "> [!spoiler]-\n" + body; } /** * Reverses {@link wrapSpoiler}: strips the callout markers, drops the - * `[!spoiler]` header and the surrounding code fence, and returns the inner - * content. Falls back to simply removing the callout markers if the body is not - * a fenced code block. + * `[!spoiler]` header and returns the inner content. For backwards + * compatibility it also strips a surrounding fenced code block if one is + * present (the format used by earlier versions). */ export function unwrapSpoiler(text: string): string { // Remove the callout marker (`> ` or `>`) from every line.