Skip to content

Commit ae58b4a

Browse files
committed
feat(help): render reference links with icon
1 parent fbc2ffa commit ae58b4a

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

apps/client/src/services/doc_renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type FNote from "../entities/fnote.js";
2+
import { applyReferenceLinks } from "../widgets/type_widgets/text/read_only_helper.js";
23
import { getCurrentLanguage } from "./i18n.js";
34
import { formatCodeBlocks } from "./syntax_highlight.js";
45

@@ -42,6 +43,9 @@ function processContent(url: string, $content: JQuery<HTMLElement>) {
4243
});
4344

4445
formatCodeBlocks($content);
46+
47+
// Apply reference links.
48+
applyReferenceLinks($content[0]);
4549
}
4650

4751
function getUrl(docNameValue: string, language: string) {

apps/client/src/widgets/type_widgets/Doc.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import { useTriliumEvent } from "../react/hooks";
77
import { refToJQuerySelector } from "../react/react_utils";
88

99
export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
10-
const [ html, setHtml ] = useState<string>();
1110
const initialized = useRef<Promise<void> | null>(null);
1211
const containerRef = useRef<HTMLDivElement>(null);
1312

1413
useEffect(() => {
1514
if (!note) return;
1615

1716
initialized.current = renderDoc(note).then($content => {
18-
setHtml($content.html());
17+
containerRef.current?.replaceChildren(...$content);
1918
});
2019
}, [ note ]);
2120

@@ -26,10 +25,9 @@ export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
2625
});
2726

2827
return (
29-
<RawHtmlBlock
30-
containerRef={containerRef}
28+
<div
29+
ref={containerRef}
3130
className={`note-detail-doc-content ck-content ${viewScope?.viewMode === "contextual-help" ? "contextual-help" : ""}`}
32-
html={html}
3331
/>
3432
);
3533
}

apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import link from "../../../services/link";
1717
import { formatCodeBlocks } from "../../../services/syntax_highlight";
1818
import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
1919
import appContext from "../../../components/app_context";
20+
import { applyReferenceLinks } from "./read_only_helper";
2021

2122
export default function ReadOnlyText({ note, noteContext, ntxId }: TypeWidgetProps) {
2223
const blob = useNoteBlob(note);
@@ -122,10 +123,3 @@ function applyMath(container: HTMLDivElement) {
122123
renderMathInElement(equation, { trust: true });
123124
}
124125
}
125-
126-
function applyReferenceLinks(container: HTMLDivElement) {
127-
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
128-
for (const referenceLink of referenceLinks) {
129-
link.loadReferenceLinkTitle($(referenceLink));
130-
}
131-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import link from "../../../services/link";
2+
3+
export function applyReferenceLinks(container: HTMLDivElement | HTMLElement) {
4+
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
5+
for (const referenceLink of referenceLinks) {
6+
try {
7+
link.loadReferenceLinkTitle($(referenceLink));
8+
} catch (e) {
9+
continue;
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)