Add numbered list conversion commands (slash and parentheses styles)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,8 @@ An [Obsidian](https://obsidian.md) plugin that transforms selected text into Uni
|
||||
- **Remove Unicode Formatting** — converts any formatted Unicode characters back to plain ASCII
|
||||
- **Convert List Bullets to Arrow** — prefixes every selected line with `→ `, stripping any leading `* ` marker first
|
||||
- **Convert List Bullets to Em Dash** — prefixes every selected line with `— `, stripping any leading `* ` marker first
|
||||
- **Convert List to Numbered (Slash)** — numbers every selected line as `1/ item`, `2/ item`, ..., stripping any leading `* ` marker first
|
||||
- **Convert List to Numbered (Parentheses)** — numbers every selected line as `(1) item`, `(2) item`, ..., stripping any leading `* ` marker first
|
||||
- Non-mapped characters (punctuation, spaces, emoji, etc.) are passed through unchanged
|
||||
|
||||
## Usage
|
||||
@@ -23,6 +25,8 @@ An [Obsidian](https://obsidian.md) plugin that transforms selected text into Uni
|
||||
- **Remove Unicode Formatting** — reverses any of the above back to plain ASCII
|
||||
- **Convert List Bullets to Arrow** — prefixes every line with `→ ` (strips `* ` if present)
|
||||
- **Convert List Bullets to Em Dash** — prefixes every line with `— ` (strips `* ` if present)
|
||||
- **Convert List to Numbered (Slash)** — numbers every line as `1/ item`, `2/ item`, ... (strips `* ` if present)
|
||||
- **Convert List to Numbered (Parentheses)** — numbers every line as `(1) item`, `(2) item`, ... (strips `* ` if present)
|
||||
|
||||
The selected text is replaced in place.
|
||||
|
||||
@@ -54,7 +58,7 @@ npm run lint # ESLint check
|
||||
|------|---------|
|
||||
| `src/unicode-maps.ts` | Builds character lookup maps from Unicode code point ranges |
|
||||
| `src/formatter.ts` | `transformText(text, style)`, `cleanText(text)`, and `bulletToEmdash(text)` — text transformation functions |
|
||||
| `src/commands.ts` | Registers the six editor commands with the Obsidian plugin API |
|
||||
| `src/commands.ts` | Registers the eight editor commands with the Obsidian plugin API |
|
||||
| `src/main.ts` | Plugin entry point — calls `registerCommands` on load |
|
||||
|
||||
### Unicode blocks used
|
||||
|
||||
+21
-1
@@ -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));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user