feat(client/link): render reference links same as in editor
Some checks are pending
Checks / main (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Dev / Test development (push) Waiting to run
Dev / Build Docker image (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile) (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile.alpine) (push) Blocked by required conditions
/ Check Docker build (Dockerfile) (push) Waiting to run
/ Check Docker build (Dockerfile.alpine) (push) Waiting to run
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.alpine, ubuntu-latest, linux/amd64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v7) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v8) (push) Blocked by required conditions
/ Merge manifest lists (push) Blocked by required conditions
playwright / E2E tests on linux-arm64 (push) Waiting to run
playwright / E2E tests on linux-x64 (push) Waiting to run

This commit is contained in:
Elian Doran 2025-11-16 11:01:32 +02:00
parent ae58b4af35
commit bbcc670655
No known key found for this signature in database
2 changed files with 13 additions and 12 deletions

View File

@ -11,18 +11,18 @@ export default function renderDoc(note: FNote) {
if (docName) { if (docName) {
// find doc based on language // find doc based on language
const url = getUrl(docName, getCurrentLanguage()); const url = getUrl(docName, getCurrentLanguage());
$content.load(url, (response, status) => { $content.load(url, async (response, status) => {
// fallback to english doc if no translation available // fallback to english doc if no translation available
if (status === "error") { if (status === "error") {
const fallbackUrl = getUrl(docName, "en"); const fallbackUrl = getUrl(docName, "en");
$content.load(fallbackUrl, () => { $content.load(fallbackUrl, async () => {
processContent(fallbackUrl, $content) await processContent(fallbackUrl, $content)
resolve($content); resolve($content);
}); });
return; return;
} }
processContent(url, $content); await processContent(url, $content);
resolve($content); resolve($content);
}); });
} else { } else {
@ -33,7 +33,7 @@ export default function renderDoc(note: FNote) {
}); });
} }
function processContent(url: string, $content: JQuery<HTMLElement>) { async function processContent(url: string, $content: JQuery<HTMLElement>) {
const dir = url.substring(0, url.lastIndexOf("/")); const dir = url.substring(0, url.lastIndexOf("/"));
// Images are relative to the docnote but that will not work when rendered in the application since the path breaks. // Images are relative to the docnote but that will not work when rendered in the application since the path breaks.
@ -45,7 +45,7 @@ function processContent(url: string, $content: JQuery<HTMLElement>) {
formatCodeBlocks($content); formatCodeBlocks($content);
// Apply reference links. // Apply reference links.
applyReferenceLinks($content[0]); await applyReferenceLinks($content[0]);
} }
function getUrl(docNameValue: string, language: string) { function getUrl(docNameValue: string, language: string) {

View File

@ -1,12 +1,13 @@
import link from "../../../services/link"; import link from "../../../services/link";
export function applyReferenceLinks(container: HTMLDivElement | HTMLElement) { export async function applyReferenceLinks(container: HTMLDivElement | HTMLElement) {
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link"); const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
for (const referenceLink of referenceLinks) { for (const referenceLink of referenceLinks) {
try { await link.loadReferenceLinkTitle($(referenceLink));
link.loadReferenceLinkTitle($(referenceLink));
} catch (e) { // Wrap in a <span> to match the design while in CKEditor.
continue; const spanEl = document.createElement("span");
} spanEl.replaceChildren(...referenceLink.childNodes);
referenceLink.replaceChildren(spanEl);
} }
} }