Remove xmlserializer dependency

jsdom can be counted on to do that for us, these days, in a more standards-complaint way. A notable change is that void elements get serialized like <br /> instead of <br/>.
This commit is contained in:
Domenic Denicola 2020-10-22 19:09:43 -04:00
commit e13ca0de74
4 changed files with 37 additions and 43 deletions

View file

@ -2,7 +2,6 @@
const path = require("path"); const path = require("path");
const fs = require("fs").promises; const fs = require("fs").promises;
const throat = require("throat"); const throat = require("throat");
const serializeToXML = require("xmlserializer").serializeToString;
const { JSDOM } = require("jsdom"); const { JSDOM } = require("jsdom");
const substitutions = require("./substitutions.json"); const substitutions = require("./substitutions.json");
@ -139,7 +138,8 @@ function getBodyXML(chapter, contentEl) {
bodyEl.appendChild(contentEl.firstChild); bodyEl.appendChild(contentEl.firstChild);
} }
let xml = serializeToXML(bodyEl); const xmlSerializer = new contentEl.ownerDocument.defaultView.XMLSerializer();
let xml = xmlSerializer.serializeToString(bodyEl);
// Fix recurring strange pattern of extra <br> in <p>...<em>...<br>\n</em></p> // Fix recurring strange pattern of extra <br> in <p>...<em>...<br>\n</em></p>
xml = xml.replace(/<br \/>\s*<\/em><\/p>/g, "</em></p>"); xml = xml.replace(/<br \/>\s*<\/em><\/p>/g, "</em></p>");

5
npm-shrinkwrap.json generated
View file

@ -2060,11 +2060,6 @@
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="
}, },
"xmlserializer": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/xmlserializer/-/xmlserializer-0.6.1.tgz",
"integrity": "sha512-FNb0eEqqUUbnuvxuHqNuKH8qCGKqxu+558Zi8UzOoQk8Z9LdvpONK+v7m3gpKVHrk5Aq+0nNLsKxu/6OYh7Umw=="
},
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",

View file

@ -28,7 +28,6 @@
"jsdom": "^16.2.2", "jsdom": "^16.2.2",
"requisition": "^1.5.0", "requisition": "^1.5.0",
"throat": "^5.0.0", "throat": "^5.0.0",
"xmlserializer": "^0.6.1",
"yargs": "^15.3.1" "yargs": "^15.3.1"
}, },
"devDependencies": { "devDependencies": {