Fixes #240
This commit is contained in:
parent
a203f368c2
commit
f78a0abbbe
@ -2,6 +2,7 @@ import type { ClickEvent } from "$sb/app_event.ts";
|
|||||||
import { editor, markdown, system } from "$sb/silverbullet-syscall/mod.ts";
|
import { editor, markdown, system } from "$sb/silverbullet-syscall/mod.ts";
|
||||||
import {
|
import {
|
||||||
addParentPointers,
|
addParentPointers,
|
||||||
|
findNodeOfType,
|
||||||
findParentMatching,
|
findParentMatching,
|
||||||
nodeAtPos,
|
nodeAtPos,
|
||||||
ParseTree,
|
ParseTree,
|
||||||
@ -74,7 +75,11 @@ async function actionClickOrActionEnter(
|
|||||||
break;
|
break;
|
||||||
case "Image":
|
case "Image":
|
||||||
case "Link": {
|
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) {
|
if (url.length <= 1) {
|
||||||
return editor.flashNotification("Empty link, ignoring", "error");
|
return editor.flashNotification("Empty link, ignoring", "error");
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,10 @@ export function linkPlugin(editor: Editor) {
|
|||||||
const text = state.sliceDoc(from, to);
|
const text = state.sliceDoc(from, to);
|
||||||
// Links are of the form [hell](https://example.com)
|
// Links are of the form [hell](https://example.com)
|
||||||
const [anchorPart, linkPart] = text.split("]("); // Not pretty
|
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) {
|
if (!linkPart) {
|
||||||
// Invalid link
|
// Invalid link
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user