mirror of
https://github.com/zadam/trilium.git
synced 2026-05-06 10:46:57 +02:00
chore: address requested changes
This commit is contained in:
@@ -50,13 +50,10 @@ export default function AddLinkDialog() {
|
||||
setLinkTitle(title);
|
||||
}
|
||||
|
||||
function resetExternalLink() {
|
||||
if (linkType === "external-link") {
|
||||
setLinkType("reference-link");
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const resetExternalLink = () =>
|
||||
setLinkType((prev) => prev === "external-link" ? "reference-link" : prev);
|
||||
|
||||
if (!suggestion) {
|
||||
resetExternalLink();
|
||||
setBookmarks([]);
|
||||
@@ -64,11 +61,14 @@ export default function AddLinkDialog() {
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
if (suggestion.notePath) {
|
||||
const noteId = tree.getNoteIdFromUrl(suggestion.notePath);
|
||||
if (noteId) {
|
||||
setDefaultLinkTitle(noteId);
|
||||
froca.getNote(noteId).then((note) => {
|
||||
if (cancelled) return;
|
||||
const bkms = note?.getLabels("internalBookmark").map((l) => l.value) ?? [];
|
||||
setBookmarks(bkms);
|
||||
setSelectedBookmark("");
|
||||
@@ -81,6 +81,8 @@ export default function AddLinkDialog() {
|
||||
setLinkTitle(suggestion.externalLink);
|
||||
setLinkType("external-link");
|
||||
}
|
||||
|
||||
return () => { cancelled = true; };
|
||||
}, [suggestion]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -480,7 +480,7 @@ export function findBookmarks(content: string): string[] {
|
||||
|
||||
function saveBookmarks(note: BNote, content: string) {
|
||||
const foundBookmarks = findBookmarks(content);
|
||||
const existingBookmarks = note.getLabels("internalBookmark");
|
||||
const existingBookmarks = note.getOwnedLabels("internalBookmark");
|
||||
|
||||
for (const bookmarkId of foundBookmarks) {
|
||||
const existing = existingBookmarks.find((l) => l.value === bookmarkId);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ButtonView, Plugin, isWidget } from "ckeditor5";
|
||||
import { ButtonView, Plugin } from "ckeditor5";
|
||||
import copyIcon from "../icons/copy.svg?raw";
|
||||
import { escapeHtml } from "../utils";
|
||||
|
||||
/**
|
||||
* Adds a "Copy anchor link" button to the bookmark/anchor widget toolbar.
|
||||
@@ -32,7 +33,7 @@ export default class CopyAnchorLinkButton extends Plugin {
|
||||
if (noteId && bookmarkId) {
|
||||
const href = `#root/${noteId}?bookmark=${encodeURIComponent(bookmarkId)}`;
|
||||
const title = glob.getReferenceLinkTitleSync(href);
|
||||
const html = `<a class="reference-link" href="${href}">${title}</a>`;
|
||||
const html = `<a class="reference-link" href="${escapeHtml(href)}">${escapeHtml(title)}</a>`;
|
||||
navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
"text/html": new Blob([html], { type: "text/html" }),
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import type { DifferItemAttribute, Editor, ModelDocumentFragment, ModelElement, ModelNode } from "ckeditor5";
|
||||
|
||||
export function escapeHtml(str: string): string {
|
||||
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
}
|
||||
|
||||
function hasHeadingAncestor(node: ModelElement | ModelNode | ModelDocumentFragment | null): boolean {
|
||||
let current: ModelElement | ModelNode | ModelDocumentFragment | null = node;
|
||||
while (current) {
|
||||
|
||||
@@ -106,7 +106,7 @@ function handleH1(content: string, title: string): string {
|
||||
});
|
||||
}
|
||||
|
||||
function extractCodeBlocks(text: string): { processedText: string; placeholderMap: Map<string, string> } {
|
||||
export function extractCodeBlocks(text: string): { processedText: string; placeholderMap: Map<string, string> } {
|
||||
const codeMap = new Map<string, string>();
|
||||
let id = 0;
|
||||
const timestamp = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user