Skip to content

Commit bbcc670

Browse files
committed
feat(client/link): render reference links same as in editor
1 parent ae58b4a commit bbcc670

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

apps/client/src/services/doc_renderer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ export default function renderDoc(note: FNote) {
1111
if (docName) {
1212
// find doc based on language
1313
const url = getUrl(docName, getCurrentLanguage());
14-
$content.load(url, (response, status) => {
14+
$content.load(url, async (response, status) => {
1515
// fallback to english doc if no translation available
1616
if (status === "error") {
1717
const fallbackUrl = getUrl(docName, "en");
18-
$content.load(fallbackUrl, () => {
19-
processContent(fallbackUrl, $content)
18+
$content.load(fallbackUrl, async () => {
19+
await processContent(fallbackUrl, $content)
2020
resolve($content);
2121
});
2222
return;
2323
}
2424

25-
processContent(url, $content);
25+
await processContent(url, $content);
2626
resolve($content);
2727
});
2828
} else {
@@ -33,7 +33,7 @@ export default function renderDoc(note: FNote) {
3333
});
3434
}
3535

36-
function processContent(url: string, $content: JQuery<HTMLElement>) {
36+
async function processContent(url: string, $content: JQuery<HTMLElement>) {
3737
const dir = url.substring(0, url.lastIndexOf("/"));
3838

3939
// 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>) {
4545
formatCodeBlocks($content);
4646

4747
// Apply reference links.
48-
applyReferenceLinks($content[0]);
48+
await applyReferenceLinks($content[0]);
4949
}
5050

5151
function getUrl(docNameValue: string, language: string) {
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import link from "../../../services/link";
22

3-
export function applyReferenceLinks(container: HTMLDivElement | HTMLElement) {
3+
export async function applyReferenceLinks(container: HTMLDivElement | HTMLElement) {
44
const referenceLinks = container.querySelectorAll<HTMLDivElement>("a.reference-link");
55
for (const referenceLink of referenceLinks) {
6-
try {
7-
link.loadReferenceLinkTitle($(referenceLink));
8-
} catch (e) {
9-
continue;
10-
}
6+
await link.loadReferenceLinkTitle($(referenceLink));
7+
8+
// Wrap in a <span> to match the design while in CKEditor.
9+
const spanEl = document.createElement("span");
10+
spanEl.replaceChildren(...referenceLink.childNodes);
11+
referenceLink.replaceChildren(spanEl);
1112
}
1213
}

0 commit comments

Comments
 (0)