Skip to content

Commit f53cb43

Browse files
committed
Merge remote-tracking branch 'origin/standalone' into standalone_mobile_nav
2 parents 885b0b9 + e135e3a commit f53cb43

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

apps/client-standalone/src/test_setup.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { fileURLToPath } from "node:url";
44

55
import { initializeCore, options } from "@triliumnext/core";
66
import schemaSql from "@triliumnext/core/src/assets/schema.sql?raw";
7-
import HappyDomHtmlParser from "happy-dom/lib/html-parser/HTMLParser.js";
87
import serverEnTranslations from "../../server/src/assets/translations/en/server.json";
98
import { beforeAll } from "vitest";
109

@@ -71,23 +70,17 @@ WebAssembly.instantiateStreaming = (async (source, importObject) => {
7170
// Per HTML5 parsing spec, a single U+000A LINE FEED immediately after a <pre>,
7271
// <listing>, or <textarea> start tag must be ignored ("newlines at the start
7372
// of pre blocks are ignored as an authoring convenience"). Real browsers and
74-
// domino (which the server runtime uses via turnish) both implement this;
75-
// happy-dom (as of 20.8.9) does not — it keeps the LF as a text node.
76-
//
77-
// That difference makes turnish's markdown export produce different output
78-
// under happy-dom vs. production, breaking markdown.spec.ts > "exports jQuery
79-
// code in table properly". Patch HTMLParser.parse to pre-process the string.
73+
// domino (which turnish uses in Node) both implement this; happy-dom does not.
74+
// Patch at the DOMParser boundary since turnish prefers DOMParser when it's
75+
// available — patching via module-level HTMLParser import hits a different
76+
// happy-dom copy than the vitest env loaded.
8077
const LEADING_LF_IN_PRE_RE = /(<(?:pre|listing|textarea)\b[^>]*>)(\r\n|\r|\n)/gi;
81-
const originalHtmlParserParse = (HappyDomHtmlParser as unknown as {
82-
prototype: { parse(html: string, rootNode?: unknown): unknown };
83-
}).prototype.parse;
84-
(HappyDomHtmlParser as unknown as {
85-
prototype: { parse(html: string, rootNode?: unknown): unknown };
86-
}).prototype.parse = function (html: string, rootNode?: unknown) {
87-
const patched = typeof html === "string"
88-
? html.replace(LEADING_LF_IN_PRE_RE, "$1")
89-
: html;
90-
return originalHtmlParserParse.call(this, patched, rootNode);
78+
const originalParseFromString = DOMParser.prototype.parseFromString;
79+
DOMParser.prototype.parseFromString = function (source: string, type: DOMParserSupportedType) {
80+
const patched = typeof source === "string"
81+
? source.replace(LEADING_LF_IN_PRE_RE, "$1")
82+
: source;
83+
return originalParseFromString.call(this, patched, type);
9184
};
9285

9386
// =============================================================================

packages/trilium-core/src/services/import/enex.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type BNote from "../../becca/entities/bnote.js";
88
import { getContext } from "../context.js";
99
import sql_init from "../sql_init.js";
1010
import TaskContext from "../task_context.js";
11+
import { decodeUtf8 } from "../utils/binary.js";
1112
import enex from "./enex.js";
1213

1314
const scriptDir = dirname(fileURLToPath(import.meta.url));
@@ -61,15 +62,15 @@ describe("importEnex", () => {
6162
const txt = attachments.find(a => a.title === "attachments1.txt");
6263
expect(txt).toBeTruthy();
6364
expect(txt!.mime).toBe("text/plain");
64-
expect(txt!.getContent().toString()).toBe("111");
65+
expect(decodeUtf8(txt!.getContent())).toBe("111");
6566

6667
const bin = attachments.find(a => a.title === "attachments2");
6768
expect(bin).toBeTruthy();
6869
expect(bin!.mime).toBe("application/octet-stream");
69-
expect(bin!.getContent().toString()).toBe("222");
70+
expect(decodeUtf8(bin!.getContent())).toBe("222");
7071

7172
// The note content should contain reference links to the attachments
72-
const content = test1!.getContent().toString();
73+
const content = decodeUtf8(test1!.getContent());
7374
expect(content).toContain(`class="reference-link" href="#root/${test1!.noteId}?viewMode=attachments&amp;attachmentId=${txt!.attachmentId}"`);
7475
expect(content).toContain(`class="reference-link" href="#root/${test1!.noteId}?viewMode=attachments&amp;attachmentId=${bin!.attachmentId}"`);
7576
});

0 commit comments

Comments
 (0)