diff --git a/README.md b/README.md index 937d92b..a994198 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ An [Obsidian](https://obsidian.md) plugin that transforms selected text into Uni - **Unicode Italic** β€” converts letters to sans-serif italic (π˜ˆπ˜‰π˜Š / 𝘒𝘣𝘀) - **Unicode Bold Italic** β€” converts letters to sans-serif bold italic (𝘼𝘽𝘾 / π™–π™—π™˜) - **Remove Unicode Formatting** β€” converts any formatted Unicode characters back to plain ASCII +- **Convert List Bullets to Em Dash** β€” replaces leading `* ` bullet markers with `β€” ` on each selected line - Non-mapped characters (punctuation, spaces, emoji, etc.) are passed through unchanged ## Usage @@ -19,6 +20,7 @@ An [Obsidian](https://obsidian.md) plugin that transforms selected text into Uni - **Format as Unicode Italic** - **Format as Unicode Bold Italic** - **Remove Unicode Formatting** β€” reverses any of the above back to plain ASCII + - **Convert List Bullets to Em Dash** β€” replaces `* ` prefixes with `β€” ` The selected text is replaced in place. @@ -49,8 +51,8 @@ npm run lint # ESLint check | File | Purpose | |------|---------| | `src/unicode-maps.ts` | Builds character lookup maps from Unicode code point ranges | -| `src/formatter.ts` | `transformText(text, style)` and `cleanText(text)` β€” character mapping functions | -| `src/commands.ts` | Registers the four editor commands with the Obsidian plugin API | +| `src/formatter.ts` | `transformText(text, style)`, `cleanText(text)`, and `bulletToEmdash(text)` β€” text transformation functions | +| `src/commands.ts` | Registers the five editor commands with the Obsidian plugin API | | `src/main.ts` | Plugin entry point β€” calls `registerCommands` on load | ### Unicode blocks used diff --git a/src/commands.ts b/src/commands.ts index 17b2c14..72313d4 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,5 +1,5 @@ import { Plugin } from "obsidian"; -import { transformText, cleanText, FormatStyle } from "./formatter"; +import { transformText, cleanText, bulletToEmdash, FormatStyle } from "./formatter"; function addFormatCommand(plugin: Plugin, style: FormatStyle, name: string) { plugin.addCommand({ @@ -28,4 +28,14 @@ export function registerCommands(plugin: Plugin): void { } }, }); + plugin.addCommand({ + id: "unicode-formatter:bullet-to-emdash", + name: "Convert List Bullets to Em Dash", + editorCallback: (editor) => { + const selection = editor.getSelection(); + if (selection) { + editor.replaceSelection(bulletToEmdash(selection)); + } + }, + }); } diff --git a/src/formatter.ts b/src/formatter.ts index 5b6f1c0..e4e2b71 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -16,3 +16,9 @@ export function transformText(text: string, style: FormatStyle): string { export function cleanText(text: string): string { return [...text].map(ch => UNICODE_TO_ASCII_MAP.get(ch) ?? ch).join(""); } + +export function bulletToEmdash(text: string): string { + return text.split("\n").map(line => + line.startsWith("* ") ? "β€” " + line.slice(2) : line + ).join("\n"); +}