mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 05:54:31 +01:00
feat(help): render reference links with icon
This commit is contained in:
parent
fbc2ffac59
commit
ae58b4af35
@ -1,4 +1,5 @@
|
|||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
|
import { applyReferenceLinks } from "../widgets/type_widgets/text/read_only_helper.js";
|
||||||
import { getCurrentLanguage } from "./i18n.js";
|
import { getCurrentLanguage } from "./i18n.js";
|
||||||
import { formatCodeBlocks } from "./syntax_highlight.js";
|
import { formatCodeBlocks } from "./syntax_highlight.js";
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ function processContent(url: string, $content: JQuery<HTMLElement>) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
formatCodeBlocks($content);
|
formatCodeBlocks($content);
|
||||||
|
|
||||||
|
// Apply reference links.
|
||||||
|
applyReferenceLinks($content[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUrl(docNameValue: string, language: string) {
|
function getUrl(docNameValue: string, language: string) {
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { useTriliumEvent } from "../react/hooks";
|
|||||||
import { refToJQuerySelector } from "../react/react_utils";
|
import { refToJQuerySelector } from "../react/react_utils";
|
||||||
|
|
||||||
export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
|
export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
|
||||||
const [ html, setHtml ] = useState<string>();
|
|
||||||
const initialized = useRef<Promise<void> | null>(null);
|
const initialized = useRef<Promise<void> | null>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
|
|||||||
if (!note) return;
|
if (!note) return;
|
||||||
|
|
||||||
initialized.current = renderDoc(note).then($content => {
|
initialized.current = renderDoc(note).then($content => {
|
||||||
setHtml($content.html());
|
containerRef.current?.replaceChildren(...$content);
|
||||||
});
|
});
|
||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
@ -26,10 +25,9 @@ export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RawHtmlBlock
|
<div
|
||||||
containerRef={containerRef}
|
ref={containerRef}
|
||||||
className={`note-detail-doc-content ck-content ${viewScope?.viewMode === "contextual-help" ? "contextual-help" : ""}`}
|
className={`note-detail-doc-content ck-content ${viewScope?.viewMode === "contextual-help" ? "contextual-help" : ""}`}
|
||||||
html={html}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import link from "../../../services/link";
|
|||||||
import { formatCodeBlocks } from "../../../services/syntax_highlight";
|
import { formatCodeBlocks } from "../../../services/syntax_highlight";
|
||||||
import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
|
import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
|
||||||
import appContext from "../../../components/app_context";
|
import appContext from "../../../components/app_context";
|
||||||
|
import { applyReferenceLinks } from "./read_only_helper";
|
||||||
|
|
||||||
export default function ReadOnlyText({ note, noteContext, ntxId }: TypeWidgetProps) {
|
export default function ReadOnlyText({ note, noteContext, ntxId }: TypeWidgetProps) {
|
||||||
const blob = useNoteBlob(note);
|
const blob = useNoteBlob(note);
|
||||||
@ -122,10 +123,3 @@ function applyMath(container: HTMLDivElement) {
|
|||||||
renderMathInElement(equation, { trust: true });
|
renderMathInElement(equation, { trust: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyReferenceLinks(container: HTMLDivElement) {
|
|
||||||
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
|
|
||||||
for (const referenceLink of referenceLinks) {
|
|
||||||
link.loadReferenceLinkTitle($(referenceLink));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
import link from "../../../services/link";
|
||||||
|
|
||||||
|
export function applyReferenceLinks(container: HTMLDivElement | HTMLElement) {
|
||||||
|
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
|
||||||
|
for (const referenceLink of referenceLinks) {
|
||||||
|
try {
|
||||||
|
link.loadReferenceLinkTitle($(referenceLink));
|
||||||
|
} catch (e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user