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
+11 -1
View File
@@ -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));
}
},
});
}
+6
View File
@@ -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");
}