diff --git a/README.md b/README.md index 312d27f..875bcac 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ to reveal the hidden contents. ### From a release (recommended) -1. Download `obsidian-spoiler-plugin_v0.2.zip` from the +1. Download `obsidian-spoiler-plugin_v0.2.1.zip` from the [latest release](https://github.com/PatruusBarba/ObsidianSpoilerPlugin/releases/latest). 2. Unzip it into your vault's plugins folder so you end up with `/.obsidian/plugins/obsidian-spoiler-plugin/` containing `main.js` and diff --git a/main.ts b/main.ts index a9db790..e1b32fd 100644 --- a/main.ts +++ b/main.ts @@ -4,8 +4,6 @@ import { Editor, MarkdownView, Notice, Plugin } from "obsidian"; const SPOILER_HEADER = /^>\s*\[!spoiler\]-?/i; /** Matches the header line once the leading callout marker (`> `) is stripped. */ const SPOILER_HEADER_STRIPPED = /^\[!spoiler\]-?/i; -/** Matches a fenced code block delimiter (``` optionally followed by a language). */ -const CODE_FENCE = /^```/; /** * Returns true when the given selection already is a spoiler callout, i.e. its @@ -35,10 +33,10 @@ export function wrapSpoiler(text: string): string { } /** - * Reverses {@link wrapSpoiler}: strips the callout markers, drops the - * `[!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). + * Reverses {@link wrapSpoiler}: removes the callout marker (`> `) from every + * line and drops the `[!spoiler]` header, returning the inner content exactly + * as it was before wrapping. The content itself is never altered, so a + * selection that contains code fences (```) round-trips unchanged. */ export function unwrapSpoiler(text: string): string { // Remove the callout marker (`> ` or `>`) from every line. @@ -52,27 +50,8 @@ export function unwrapSpoiler(text: string): string { break; } } - let body = lines.slice(start); - // If the body is wrapped in a fenced code block, strip the fences. - const first = body.findIndex((line) => line.trim() !== ""); - let last = -1; - for (let i = body.length - 1; i >= 0; i--) { - if (body[i].trim() !== "") { - last = i; - break; - } - } - if ( - first !== -1 && - last > first && - CODE_FENCE.test(body[first].trim()) && - CODE_FENCE.test(body[last].trim()) - ) { - body = body.slice(first + 1, last); - } - - return body.join("\n"); + return lines.slice(start).join("\n"); } export default class SpoilerPlugin extends Plugin { diff --git a/manifest.json b/manifest.json index 9d7502e..2db3cd3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-spoiler-plugin", "name": "Spoiler", - "version": "0.2.0", + "version": "0.2.1", "minAppVersion": "0.15.0", "description": "Wrap selected text in a collapsible spoiler callout, or unwrap an existing spoiler, from a ribbon button.", "author": "PatruusBarba", diff --git a/package.json b/package.json index b442368..881b8dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-spoiler-plugin", - "version": "0.2.0", + "version": "0.2.1", "description": "Wrap selected text in a collapsible spoiler callout, or unwrap an existing spoiler, from a ribbon button.", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index dcf50a9..dfef3b6 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { "1.0.0": "0.15.0", - "0.2.0": "0.15.0" + "0.2.0": "0.15.0", + "0.2.1": "0.15.0" }