pull/254/head
Zef Hemel 2022-12-29 12:53:42 +01:00
parent a203f368c2
commit f78a0abbbe
2 changed files with 10 additions and 1 deletions

View File

@ -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");
}

View File

@ -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;