diff --git a/web/cm_plugins/wiki_link.ts b/web/cm_plugins/wiki_link.ts index 710adf9e..7393d89d 100644 --- a/web/cm_plugins/wiki_link.ts +++ b/web/cm_plugins/wiki_link.ts @@ -40,15 +40,37 @@ export function cleanWikiLinkPlugin(editor: Editor) { if (type.name !== "WikiLink") { return; } - if (isCursorInRange(view.state, [from, to])) { - return; - } const text = view.state.sliceDoc(from, to); const match = pageLinkRegex.exec(text); if (!match) return; const [_fullMatch, page, pipePart, alias] = match; + const allPages = editor.space.listPages(); + let pageExists = false; + let cleanPage = page; + if (page.includes("@")) { + cleanPage = page.split("@")[0]; + } + for (const pageMeta of allPages) { + if (pageMeta.name === cleanPage) { + pageExists = true; + break; + } + } + + if (isCursorInRange(view.state, [from, to])) { + // Only attach a CSS class, then get out + if (!pageExists) { + widgets.push( + Decoration.mark({ + class: "sb-wiki-link-page-missing", + }).range(from + 2, from + page.length + 2), + ); + } + return; + } + // Hide the whole thing widgets.push( invisibleDecoration.range( @@ -68,8 +90,10 @@ export function cleanWikiLinkPlugin(editor: Editor) { Decoration.widget({ widget: new LinkWidget( linkText, - page, - "sb-wiki-link-page", + pageExists ? `Navigate to ${page}` : `Create ${page}`, + pageExists + ? "sb-wiki-link-page" + : "sb-wiki-link-page-missing", (e) => { if (e.altKey) { // Move cursor into the link diff --git a/web/styles/theme.scss b/web/styles/theme.scss index 06fd6d54..5f6e9d61 100644 --- a/web/styles/theme.scss +++ b/web/styles/theme.scss @@ -348,6 +348,15 @@ text-decoration: none; cursor: pointer; } +.sb-wiki-link-page-missing, .sb-wiki-link-page-missing > .sb-wiki-link-page { + color: #9e4705; + background-color: rgba(77, 141, 255, 0.07); + border-radius: 5px; + padding: 0 5px; + white-space: nowrap; + text-decoration: none; + cursor: pointer; +} .sb-wiki-link { cursor: pointer; diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 2e8c856b..2a9d3c06 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -7,6 +7,7 @@ release. * New page link aliasing syntax (Obsidian compatible) is here: `[[page link|alias]]` e.g. [[CHANGELOG|this is a link to this changelog]]. Also supported for command links: `{[Plugs: Add|add a plug]}` * Less "floppy" behavior when clicking links (regular, wiki and command): just navigates there right away. Note: use `Alt-click` to move the cursor inside of a link. +* Page reference to non-existing pages are now higlighted in a (red-ish) color * Added `invokeFunction` `silverbullet` CLI sub-command to run arbitrary plug functions from the CLI. ---