// XxxEditor.parse() and XxxEditor.serialize(): the HTML that the editor keeps and writes "use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); const { load } = require("./helpers"); const window = load(["publish/editor.js"], ""); const { parse, serialize } = window.XxxEditor; // The HTML that the editor writes for *html* function clean(html) { const holder = window.document.createElement("div"); holder.appendChild(parse(html)); return serialize(holder); } test("simple paragraphs stay the same", () => { assert.equal(clean("
One
\nTwo bold it u x2 H2O
"), "One
\nTwo bold it u x2 H2O
"); }); test("b and i become strong and em", () => { assert.equal(clean("b i
"), "b i
"); }); test("scripts, styles and frames are dropped with their contents", () => { assert.equal(clean("ab
"), "ab
"); }); test("event handlers and unknown attributes are dropped", () => { assert.equal(clean('a
a
"); }); test("unknown tags keep their contents", () => { assert.equal(clean("red plain
"), "red plain
"); }); test("headings become paragraphs", () => { assert.equal(clean("Title
"); }); test("only safe links are kept", () => { assert.equal(clean(''), ''); assert.equal(clean(''), ''); assert.equal(clean(''), ""); assert.equal(clean(''), ""); assert.equal(clean(''), ""); }); test("only alignment and indent styles are kept", () => { assert.equal(clean('c
'), 'c
'); assert.equal(clean('i
'), 'i
'); assert.equal(clean('x
'), "x
"); assert.equal(clean('x
'), "x
"); assert.equal(clean('x
'), 'x
'); }); test("the align attribute is kept only with a real alignment", () => { assert.equal(clean('c
'), 'c
'); assert.equal(clean('c
'), "c
"); }); test("text is escaped", () => { assert.equal(clean("a < b & c > d \"q\"
"), "a < b & c > d \"q\"
"); }); test("line breaks, rules and no-break spaces are written as TinyMCE wrote them", () => { assert.equal(clean("one
two
a b
"), "one
two
a b
"); }); test("an empty paragraph is written as ", () => { assert.equal(clean("a
b
"), "a
\n\n
\n
b
"); }); test("a trailing line break in a block is dropped", () => { assert.equal(clean("a
a
"); }); test("an editor with no words gives an empty story", () => { assert.equal(clean(""), ""); assert.equal(clean("
"), ""); assert.equal(clean(""), "q
\n"); assert.equal(clean("q
\n
a
\n\nb
"), "a
\nb
"); }); test("parse does not run anything", () => { window.hacked = false; parse('