Add link command
This commit is contained in:
parent
a29ea35937
commit
86823918cc
@ -215,6 +215,12 @@ functions:
|
||||
path: ./text.ts:numberListifySelection
|
||||
command:
|
||||
name: "Text: Number Listify Selection"
|
||||
linkSelection:
|
||||
path: ./text.ts:linkSelection
|
||||
command:
|
||||
name: "Text: Link Selection"
|
||||
key: "Ctrl-Shift-k"
|
||||
mac: "Cmd-Shift-k"
|
||||
bold:
|
||||
path: ./text.ts:wrapSelection
|
||||
command:
|
||||
|
@ -56,6 +56,23 @@ export async function numberListifySelection() {
|
||||
await replaceRange(from, selection.to, text);
|
||||
}
|
||||
|
||||
export async function linkSelection() {
|
||||
const text = await getText();
|
||||
const selection = await getSelection();
|
||||
const textSelection = text.slice(selection.from, selection.to);
|
||||
let linkedText = `[]()`;
|
||||
if (textSelection.length > 0) {
|
||||
try {
|
||||
new URL(textSelection);
|
||||
linkedText = `[](${textSelection})`;
|
||||
} catch {
|
||||
linkedText = `[${textSelection}]()`;
|
||||
|
||||
}
|
||||
}
|
||||
await replaceRange(selection.from, selection.to, linkedText)
|
||||
}
|
||||
|
||||
export function wrapSelection(cmdDef: any) {
|
||||
return insertMarker(cmdDef.wrapper);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user