mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 21:44:31 +01:00
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
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:
parent
ae58b4af35
commit
bbcc670655
@ -11,18 +11,18 @@ export default function renderDoc(note: FNote) {
|
||||
if (docName) {
|
||||
// find doc based on language
|
||||
const url = getUrl(docName, getCurrentLanguage());
|
||||
$content.load(url, (response, status) => {
|
||||
$content.load(url, async (response, status) => {
|
||||
// fallback to english doc if no translation available
|
||||
if (status === "error") {
|
||||
const fallbackUrl = getUrl(docName, "en");
|
||||
$content.load(fallbackUrl, () => {
|
||||
processContent(fallbackUrl, $content)
|
||||
$content.load(fallbackUrl, async () => {
|
||||
await processContent(fallbackUrl, $content)
|
||||
resolve($content);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
processContent(url, $content);
|
||||
await processContent(url, $content);
|
||||
resolve($content);
|
||||
});
|
||||
} 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("/"));
|
||||
|
||||
// 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);
|
||||
|
||||
// Apply reference links.
|
||||
applyReferenceLinks($content[0]);
|
||||
await applyReferenceLinks($content[0]);
|
||||
}
|
||||
|
||||
function getUrl(docNameValue: string, language: string) {
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
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");
|
||||
for (const referenceLink of referenceLinks) {
|
||||
try {
|
||||
link.loadReferenceLinkTitle($(referenceLink));
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
await link.loadReferenceLinkTitle($(referenceLink));
|
||||
|
||||
// Wrap in a <span> to match the design while in CKEditor.
|
||||
const spanEl = document.createElement("span");
|
||||
spanEl.replaceChildren(...referenceLink.childNodes);
|
||||
referenceLink.replaceChildren(spanEl);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user