mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +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({
|
const note = buildShareNote({
|
||||||
content,
|
content,
|
||||||
attachments: [ { id: "q14s2Id7V6pp" } ]
|
attachments: [ { id: "q14s2Id7V6pp", title: "5863845791835102555.mp4" } ]
|
||||||
});
|
});
|
||||||
const result = getContent(note);
|
const result = getContent(note);
|
||||||
expect(result.content).toStrictEqual(trimIndentation`\
|
expect(result.content).toStrictEqual(trimIndentation`\
|
||||||
<h1>Test</h1>
|
<h1>Test</h1>
|
||||||
<p>
|
<p>
|
||||||
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">
|
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">5863845791835102555.mp4</a>
|
||||||
5863845791835102555.mp4
|
|
||||||
</a>
|
|
||||||
|
|
||||||
</p>
|
</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 shaca from "./shaca/shaca.js";
|
||||||
import assetPath from "../services/asset_path.js";
|
import assetPath from "../services/asset_path.js";
|
||||||
import shareRoot from "./share_root.js";
|
import shareRoot from "./share_root.js";
|
||||||
@ -79,13 +79,13 @@ function renderText(result: Result, note: SNote) {
|
|||||||
const includedResult = getContent(note);
|
const includedResult = getContent(note);
|
||||||
if (typeof includedResult.content !== "string") continue;
|
if (typeof includedResult.content !== "string") continue;
|
||||||
|
|
||||||
const includedDocument = parse(includedResult.content).querySelector("body");
|
const includedDocument = parse(includedResult.content).childNodes;
|
||||||
if (includedDocument) {
|
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) {
|
if (!result.isEmpty) {
|
||||||
for (const linkEl of document.querySelectorAll("a")) {
|
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">`)) {
|
if (result.content.includes(`<span class="math-tex">`)) {
|
||||||
result.header += `
|
result.header += `
|
||||||
@ -134,7 +134,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string) {
|
|||||||
linkEl.classList.add(`attachment-link`);
|
linkEl.classList.add(`attachment-link`);
|
||||||
linkEl.classList.add(`role-${attachment.role}`);
|
linkEl.classList.add(`role-${attachment.role}`);
|
||||||
linkEl.childNodes.length = 0;
|
linkEl.childNodes.length = 0;
|
||||||
linkEl.append(attachment.title);
|
linkEl.appendChild(new TextNode(attachment.title));
|
||||||
} else {
|
} else {
|
||||||
linkEl.removeAttribute("href");
|
linkEl.removeAttribute("href");
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ export function renderCode(result: Result) {
|
|||||||
result.isEmpty = true;
|
result.isEmpty = true;
|
||||||
} else {
|
} else {
|
||||||
const preEl = new HTMLElement("pre", {});
|
const preEl = new HTMLElement("pre", {});
|
||||||
preEl.append(result.content);
|
preEl.appendChild(new TextNode(result.content));
|
||||||
result.content = preEl.outerHTML;
|
result.content = preEl.outerHTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user