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:
+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