chore(react/type_widget): render reference links

This commit is contained in:
Elian Doran 2025-09-21 20:34:02 +03:00
parent ff941b2cb1
commit fb46e09428
No known key found for this signature in database
2 changed files with 12 additions and 15 deletions

View File

@ -13,6 +13,7 @@ import { getLocaleById } from "../../../services/i18n";
import { getMermaidConfig } from "../../../services/mermaid"; import { getMermaidConfig } from "../../../services/mermaid";
import { loadIncludedNote, refreshIncludedNote } from "./utils"; import { loadIncludedNote, refreshIncludedNote } from "./utils";
import { renderMathInElement } from "../../../services/math"; import { renderMathInElement } from "../../../services/math";
import link from "../../../services/link";
export default function ReadOnlyText({ note }: TypeWidgetProps) { export default function ReadOnlyText({ note }: TypeWidgetProps) {
const blob = useNoteBlob(note); const blob = useNoteBlob(note);
@ -27,6 +28,7 @@ export default function ReadOnlyText({ note }: TypeWidgetProps) {
applyInlineMermaid(container); applyInlineMermaid(container);
applyIncludedNotes(container); applyIncludedNotes(container);
applyMath(container); applyMath(container);
applyReferenceLinks(container);
}, [ blob ]); }, [ blob ]);
// React to included note changes. // React to included note changes.
@ -80,11 +82,11 @@ async function applyInlineMermaid(container: HTMLDivElement) {
} }
function applyIncludedNotes(container: HTMLDivElement) { function applyIncludedNotes(container: HTMLDivElement) {
const includedNotes = container.querySelectorAll("section.include-note"); const includedNotes = container.querySelectorAll<HTMLElement>("section.include-note");
for (const includedNote of includedNotes) { for (const includedNote of includedNotes) {
const noteId = (includedNote as HTMLElement).dataset.noteId; const noteId = includedNote.dataset.noteId;
if (!noteId) continue; if (!noteId) continue;
loadIncludedNote(noteId, $(includedNote as HTMLElement)); loadIncludedNote(noteId, $(includedNote));
} }
} }
@ -94,3 +96,10 @@ 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));
}
}

View File

@ -3,8 +3,6 @@ import { formatCodeBlocks } from "../../services/syntax_highlight.js";
import type FNote from "../../entities/fnote.js"; import type FNote from "../../entities/fnote.js";
import type { CommandListenerData, EventData } from "../../components/app_context.js"; import type { CommandListenerData, EventData } from "../../components/app_context.js";
import appContext from "../../components/app_context.js"; import appContext from "../../components/app_context.js";
import { getMermaidConfig } from "../../services/mermaid.js";
import { renderMathInElement } from "../../services/math.js";
export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
@ -27,16 +25,6 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
} }
async doRefresh(note: FNote) { async doRefresh(note: FNote) {
this.onLanguageChanged();
const blob = await note.getBlob();
this.$content.html(blob?.content ?? "");
this.$content.find("a.reference-link").each((_, el) => {
this.loadReferenceLinkTitle($(el));
});
await formatCodeBlocks(this.$content); await formatCodeBlocks(this.$content);
} }