Add inline command links {[Command Name]} syntax

pull/36/head
Zef Hemel 2022-07-18 16:44:43 +02:00
parent d5ebab0358
commit 928ef59190
2 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,20 @@ syntax:
color: "#0330cb"
textDecoration: underline
cursor: pointer
CommandLink:
firstCharacters:
- "{"
regex: "\\{\\[[^\\]]+\\]\\}"
styles:
#color: "#1e62a0"
backgroundColor: "#e3dfdf"
cursor: pointer
borderTop: 1px solid silver
borderLeft: 1px solid silver
borderBottom: 1px solid gray
borderRight: 1px solid gray
borderRadius: 4px
padding: 0 4px
functions:
clearPageIndex:
path: "./page.ts:clearPageIndex"

View File

@ -7,6 +7,7 @@ import {
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
import { nodeAtPos, ParseTree } from "@silverbulletmd/common/tree";
import { invokeCommand } from "@silverbulletmd/plugos-silverbullet-syscall/system";
async function actionClickOrActionEnter(mdTree: ParseTree | null) {
if (!mdTree) {
@ -29,6 +30,13 @@ async function actionClickOrActionEnter(mdTree: ParseTree | null) {
case "Link":
await openUrl(mdTree.children![4].children![0].text!);
break;
case "CommandLink":
let command = mdTree
.children![0].text!.substring(2, mdTree.children![0].text!.length - 2)
.trim();
console.log("Got command link", command);
await invokeCommand(command);
break;
}
}