// 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

\n

Two bold it u x2 H2O

"), "

One

\n

Two 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

"), "

Title

"); }); test("only safe links are kept", () => { assert.equal(clean('

x

'), '

x

'); assert.equal(clean('

m r h

'), '

m r h

'); assert.equal(clean('

x

'), "

x

"); assert.equal(clean('

x

'), "

x

"); assert.equal(clean('

x

'), "

x

"); }); 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

\n
\n

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("

 

​

"), ""); assert.equal(clean("
"), "
"); }); test("blockquotes and lists put their blocks on new lines", () => { assert.equal(clean("

q

"), "
\n

q

\n
"); assert.equal(clean("
  1. c
"), "\n
    \n
  1. c
  2. \n
"); }); test("whitespace between blocks is dropped", () => { assert.equal(clean("

a

\n\n

b

"), "

a

\n

b

"); }); test("parse does not run anything", () => { window.hacked = false; parse(''); assert.equal(window.hacked, false); });