Add "Convert List Bullets to Em Dash" command

Adds bulletToEmdash() to formatter.ts and registers the new
unicode-formatter:bullet-to-emdash command. Updates README accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 15:18:15 +01:00
parent 7a4e09f97c
commit 5befb3a0bc
3 changed files with 21 additions and 3 deletions
+4 -2
View File
@@ -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 Italic** — converts letters to sans-serif italic (𝘈𝘉𝘊 / 𝘢𝘣𝘤)
- **Unicode Bold Italic** — converts letters to sans-serif bold italic (𝘼𝘽𝘾 / 𝙖𝙗𝙘) - **Unicode Bold Italic** — converts letters to sans-serif bold italic (𝘼𝘽𝘾 / 𝙖𝙗𝙘)
- **Remove Unicode Formatting** — converts any formatted Unicode characters back to plain ASCII - **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 - Non-mapped characters (punctuation, spaces, emoji, etc.) are passed through unchanged
## Usage ## Usage
@@ -19,6 +20,7 @@ An [Obsidian](https://obsidian.md) plugin that transforms selected text into Uni
- **Format as Unicode Italic** - **Format as Unicode Italic**
- **Format as Unicode Bold Italic** - **Format as Unicode Bold Italic**
- **Remove Unicode Formatting** — reverses any of the above back to plain ASCII - **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. The selected text is replaced in place.
@@ -49,8 +51,8 @@ npm run lint # ESLint check
| File | Purpose | | File | Purpose |
|------|---------| |------|---------|
| `src/unicode-maps.ts` | Builds character lookup maps from Unicode code point ranges | | `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/formatter.ts` | `transformText(text, style)`, `cleanText(text)`, and `bulletToEmdash(text)` — text transformation functions |
| `src/commands.ts` | Registers the four editor commands with the Obsidian plugin API | | `src/commands.ts` | Registers the five editor commands with the Obsidian plugin API |
| `src/main.ts` | Plugin entry point — calls `registerCommands` on load | | `src/main.ts` | Plugin entry point — calls `registerCommands` on load |
### Unicode blocks used ### Unicode blocks used
+11 -1
View File
@@ -1,5 +1,5 @@
import { Plugin } from "obsidian"; 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) { function addFormatCommand(plugin: Plugin, style: FormatStyle, name: string) {
plugin.addCommand({ 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));
}
},
});
} }
+6
View File
@@ -16,3 +16,9 @@ export function transformText(text: string, style: FormatStyle): string {
export function cleanText(text: string): string { export function cleanText(text: string): string {
return [...text].map(ch => UNICODE_TO_ASCII_MAP.get(ch) ?? ch).join(""); 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");
}