mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
chore(server): fix share content renderer
This commit is contained in:
parent
4c6a742af7
commit
f718e87673
@ -47,15 +47,13 @@ describe("content_renderer", () => {
|
||||
`;
|
||||
const note = buildShareNote({
|
||||
content,
|
||||
attachments: [ { id: "q14s2Id7V6pp" } ]
|
||||
attachments: [ { id: "q14s2Id7V6pp", title: "5863845791835102555.mp4" } ]
|
||||
});
|
||||
const result = getContent(note);
|
||||
expect(result.content).toStrictEqual(trimIndentation`\
|
||||
<h1>Test</h1>
|
||||
<p>
|
||||
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">
|
||||
5863845791835102555.mp4
|
||||
</a>
|
||||
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">5863845791835102555.mp4</a>
|
||||
|
||||
</p>
|
||||
`);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { parse, HTMLElement } from "node-html-parser";
|
||||
import { parse, HTMLElement, TextNode } from "node-html-parser";
|
||||
import shaca from "./shaca/shaca.js";
|
||||
import assetPath from "../services/asset_path.js";
|
||||
import shareRoot from "./share_root.js";
|
||||
@ -79,13 +79,13 @@ function renderText(result: Result, note: SNote) {
|
||||
const includedResult = getContent(note);
|
||||
if (typeof includedResult.content !== "string") continue;
|
||||
|
||||
const includedDocument = parse(includedResult.content).querySelector("body");
|
||||
const includedDocument = parse(includedResult.content).childNodes;
|
||||
if (includedDocument) {
|
||||
includeNoteEl.replaceWith(includedDocument);
|
||||
includeNoteEl.replaceWith(...includedDocument);
|
||||
}
|
||||
}
|
||||
|
||||
result.isEmpty = document.querySelector("body")?.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0;
|
||||
result.isEmpty = document.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0;
|
||||
|
||||
if (!result.isEmpty) {
|
||||
for (const linkEl of document.querySelectorAll("a")) {
|
||||
@ -101,7 +101,7 @@ function renderText(result: Result, note: SNote) {
|
||||
}
|
||||
}
|
||||
|
||||
result.content = document.querySelector("body")?.innerHTML ?? "";
|
||||
result.content = document.innerHTML ?? "";
|
||||
|
||||
if (result.content.includes(`<span class="math-tex">`)) {
|
||||
result.header += `
|
||||
@ -134,7 +134,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string) {
|
||||
linkEl.classList.add(`attachment-link`);
|
||||
linkEl.classList.add(`role-${attachment.role}`);
|
||||
linkEl.childNodes.length = 0;
|
||||
linkEl.append(attachment.title);
|
||||
linkEl.appendChild(new TextNode(attachment.title));
|
||||
} else {
|
||||
linkEl.removeAttribute("href");
|
||||
}
|
||||
@ -168,7 +168,7 @@ export function renderCode(result: Result) {
|
||||
result.isEmpty = true;
|
||||
} else {
|
||||
const preEl = new HTMLElement("pre", {});
|
||||
preEl.append(result.content);
|
||||
preEl.appendChild(new TextNode(result.content));
|
||||
result.content = preEl.outerHTML;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user