diff --git a/plugs/core/navigate.ts b/plugs/core/navigate.ts index c2ff18b..641bd29 100644 --- a/plugs/core/navigate.ts +++ b/plugs/core/navigate.ts @@ -2,6 +2,7 @@ import type { ClickEvent } from "$sb/app_event.ts"; import { editor, markdown, system } from "$sb/silverbullet-syscall/mod.ts"; import { addParentPointers, + findNodeOfType, findParentMatching, nodeAtPos, ParseTree, @@ -74,7 +75,11 @@ async function actionClickOrActionEnter( break; case "Image": case "Link": { - const url = patchUrl(mdTree.children![4].children![0].text!); + const urlNode = findNodeOfType(mdTree, "URL"); + if (!urlNode) { + return; + } + const url = patchUrl(urlNode.children![0].text!); if (url.length <= 1) { return editor.flashNotification("Empty link, ignoring", "error"); } diff --git a/web/cm_plugins/link.ts b/web/cm_plugins/link.ts index cd9f876..cd489b9 100644 --- a/web/cm_plugins/link.ts +++ b/web/cm_plugins/link.ts @@ -25,6 +25,10 @@ export function linkPlugin(editor: Editor) { const text = state.sliceDoc(from, to); // Links are of the form [hell](https://example.com) const [anchorPart, linkPart] = text.split("]("); // Not pretty + if (anchorPart.substring(1).trim() === "") { + // Empty link text, let's not do live preview (because it would make it disappear) + return; + } if (!linkPart) { // Invalid link return;