From 928ef5919091814a7452a24f5e2cb5945ef6296b Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 18 Jul 2022 16:44:43 +0200 Subject: [PATCH] Add inline command links {[Command Name]} syntax --- packages/plugs/core/core.plug.yaml | 14 ++++++++++++++ packages/plugs/core/navigate.ts | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/plugs/core/core.plug.yaml b/packages/plugs/core/core.plug.yaml index bbad1a58..20867533 100644 --- a/packages/plugs/core/core.plug.yaml +++ b/packages/plugs/core/core.plug.yaml @@ -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" diff --git a/packages/plugs/core/navigate.ts b/packages/plugs/core/navigate.ts index 9e52f7c5..2f6f5239 100644 --- a/packages/plugs/core/navigate.ts +++ b/packages/plugs/core/navigate.ts @@ -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; } }