Update editor, themes, menus, backgrounds, and release tooling
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { markdownLanguage } from "@codemirror/lang-markdown";
|
||||
|
||||
export type DocumentLink = { from: number; to: number; kind: "md" | "wiki"; target: string };
|
||||
export type DocumentLink = { from: number; to: number; targetFrom: number; targetTo: number; kind: "md" | "wiki"; target: string };
|
||||
|
||||
/** Source ranges survive the change from formatted text to editable Markdown. */
|
||||
export function documentLinks(source: string): DocumentLink[] {
|
||||
@@ -15,13 +15,17 @@ export function documentLinks(source: string): DocumentLink[] {
|
||||
const url = node.node.getChild("URL");
|
||||
if (!url) return;
|
||||
const target = source.slice(url.from, url.to).replace(/^<|>$/g, "").replace(/\\([\\()])/g, "$1");
|
||||
links.push({ from: node.from, to: node.to, kind: "md", target });
|
||||
const angled = source[url.from] === "<";
|
||||
links.push({ from: node.from, to: node.to, targetFrom: url.from + Number(angled), targetTo: url.to - Number(angled), kind: "md", target });
|
||||
return false;
|
||||
} });
|
||||
const occupied = (from: number, to: number) => [...literal, ...links].some(range => from < range.to && to > range.from);
|
||||
for (const match of source.matchAll(/\[\[([^\]\n]+)\]\]/g)) {
|
||||
if (occupied(match.index, match.index + match[0].length)) continue;
|
||||
links.push({ from: match.index, to: match.index + match[0].length, kind: "wiki", target: match[1].split("|")[0].trim() });
|
||||
if (source[match.index - 1] === "!") continue;
|
||||
const raw = match[1].split(/\\?\|/)[0], target = raw.trim();
|
||||
const targetFrom = match.index + 2 + raw.length - raw.trimStart().length;
|
||||
links.push({ from: match.index, to: match.index + match[0].length, targetFrom, targetTo: targetFrom + target.length, kind: "wiki", target });
|
||||
}
|
||||
for (const match of source.matchAll(/(?:https?:\/\/|mailto:)[^\s<>]+/g)) {
|
||||
if (occupied(match.index, match.index + match[0].length)) continue;
|
||||
@@ -29,7 +33,7 @@ export function documentLinks(source: string): DocumentLink[] {
|
||||
const open = (match[0].match(/\(/g) || []).length, close = (match[0].match(/\)/g) || []).length;
|
||||
return suffix.slice(0, Math.max(0, suffix.length - Math.max(0, close - open)));
|
||||
});
|
||||
links.push({ from: match.index, to: match.index + target.length, kind: "md", target });
|
||||
links.push({ from: match.index, to: match.index + target.length, targetFrom: match.index, targetTo: match.index + target.length, kind: "md", target });
|
||||
}
|
||||
return links.sort((a, b) => a.from - b.from);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user