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:
@@ -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
|
||||
|
||||
+11
-1
@@ -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));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user