Add numbered list conversion commands (slash and parentheses styles)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 15:46:13 +01:00
parent 91b70f8484
commit 6eedd47805
3 changed files with 44 additions and 2 deletions
+21 -1
View File
@@ -1,5 +1,5 @@
import { Plugin } from "obsidian";
import { transformText, cleanText, bulletToEmdash, bulletToArrow, FormatStyle } from "./formatter";
import { transformText, cleanText, bulletToEmdash, bulletToArrow, numberedListSlash, numberedListParens, FormatStyle } from "./formatter";
function addFormatCommand(plugin: Plugin, style: FormatStyle, name: string) {
plugin.addCommand({
@@ -48,4 +48,24 @@ export function registerCommands(plugin: Plugin): void {
}
},
});
plugin.addCommand({
id: "unicode-formatter:numbered-list-slash",
name: "Convert List to Numbered (Slash)",
editorCallback: (editor) => {
const selection = editor.getSelection();
if (selection) {
editor.replaceSelection(numberedListSlash(selection));
}
},
});
plugin.addCommand({
id: "unicode-formatter:numbered-list-parens",
name: "Convert List to Numbered (Parentheses)",
editorCallback: (editor) => {
const selection = editor.getSelection();
if (selection) {
editor.replaceSelection(numberedListParens(selection));
}
},
});
}
+18
View File
@@ -28,3 +28,21 @@ export function bulletToArrow(text: string): string {
line.startsWith("* ") ? "→ " + line.slice(2) : "→ " + line
).join("\n");
}
export function numberedListSlash(text: string): string {
let n = 0;
return text.split("\n").map(line => {
n++;
const content = line.startsWith("* ") ? line.slice(2) : line;
return `${n}/ ${content}`;
}).join("\n");
}
export function numberedListParens(text: string): string {
let n = 0;
return text.split("\n").map(line => {
n++;
const content = line.startsWith("* ") ? line.slice(2) : line;
return `(${n}) ${content}`;
}).join("\n");
}