diff --git a/lib/convert.js b/lib/convert.js index 2708a71..457e081 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -2,7 +2,6 @@ const path = require("path"); const fs = require("fs").promises; const throat = require("throat"); -const serializeToXML = require("xmlserializer").serializeToString; const { JSDOM } = require("jsdom"); const substitutions = require("./substitutions.json"); @@ -139,10 +138,11 @@ function getBodyXML(chapter, contentEl) { 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
in

......
\n

- xml = xml.replace(/\s*<\/em><\/p>/g, "

"); + xml = xml.replace(/
\s*<\/em><\/p>/g, "

"); // There are way too many nonbreaking spaces where they don't belong. // If they show up three in a row, then let them live. Otherwise, they die. @@ -203,17 +203,17 @@ function getBodyXML(chapter, contentEl) { fixEms(); // Similar problems occur in Ward with and as do in Worm with s - xml = xml.replace(//g, ""); - xml = xml.replace(/(\s*\s*)<\/b>/g, "$1"); - xml = xml.replace(/(\s*\s*)<\/strong>/g, "$1"); + xml = xml.replace(//g, ""); + xml = xml.replace(/(\s*
\s*)<\/b>/g, "$1"); + xml = xml.replace(/(\s*
\s*)<\/strong>/g, "$1"); xml = xml.replace(/<\/strong>(\s*)/g, "$1"); xml = xml.replace(/@<\/strong>/g, "@"); - xml = xml.replace(/(\s*)<\/strong>/g, "
$1"); + xml = xml.replace(/
(\s*)<\/strong>/g, "

$1"); xml = xml.replace(/(\s*)<\/strong>/g, "
$1"); // No need for line breaks before paragraph ends // These often occur with the
s inside / fixed above. - xml = xml.replace(/\s*<\/p>/g, "

"); + xml = xml.replace(/
\s*<\/p>/g, "

"); // Fix possessive of names ending in "s" // Note: if the "s" is unvoiced, as in Marquis, then it doesn't get the second "s". @@ -298,12 +298,12 @@ function getBodyXML(chapter, contentEl) { // Use
for separators // https://www.parahumans.net/2019/12/21/interlude-18-z-radiation/ has "super-separators" ("⊙ ⊙ ⊙ ⊙ ⊙") which we // leave untouched for now. - xml = xml.replace(/

■<\/p>/g, "


"); - xml = xml.replace(/

■<\/p>/g, "


"); - xml = xml.replace(/

⊙<\/p>/g, "


"); - xml = xml.replace(/

⊙<\/strong><\/p>/g, "


"); - xml = xml.replace(/

⊙<\/strong><\/em><\/p>/g, "


"); - xml = xml.replace(/

⊙⊙<\/strong><\/p>/g, "


"); + xml = xml.replace(/

■<\/p>/g, "


"); + xml = xml.replace(/

■<\/p>/g, "


"); + xml = xml.replace(/

⊙<\/p>/g, "


"); + xml = xml.replace(/

⊙<\/strong><\/p>/g, "


"); + xml = xml.replace(/

⊙<\/strong><\/em><\/p>/g, "


"); + xml = xml.replace(/

⊙⊙<\/strong><\/p>/g, "


"); // Fix recurring miscapitalization with questions xml = xml.replace(/\?”\s\s?She asked/g, "?” she asked"); diff --git a/lib/substitutions.json b/lib/substitutions.json index 0431645..4264abd 100644 --- a/lib/substitutions.json +++ b/lib/substitutions.json @@ -5,7 +5,7 @@ "after": "bugs: flies, ants" }, { - "before": "

Brief note from the author: This story isn’t intended for young or sensitive readers. Readers who are on the lookout for trigger warnings are advised to give Worm a pass.

\n
\n", + "before": "

Brief note from the author: This story isn’t intended for young or sensitive readers. Readers who are on the lookout for trigger warnings are advised to give Worm a pass.

\n
\n", "after": "", "_comment": "The pseudo-trigger warning is out of place in an eBook." } @@ -906,15 +906,15 @@ "after": "crash when the wave rolled" }, { - "regExp": "\n ?\\s*([^<]+)(
|

)", + "regExp": "\n ?\\s*([^<]+)(
|

)", "replacement": "\n

$1

" }, { - "regExp": "\n

([^<]+)(
|

)", + "regExp": "\n

([^<]+)(
|

)", "replacement": "\n

$1

" }, { - "regExp": "\n

([^<\n]+)
\n([^>\n]+)

\n", + "regExp": "\n

([^<\n]+)
\n([^>\n]+)

\n", "replacement": "\n

$1

\n

$2

\n" } ], @@ -1770,15 +1770,15 @@ "replacement": "

" }, { - "before": "agreed-upon confidentiality.
\n■ ", + "before": "agreed-upon confidentiality.
\n■ ", "after": "agreed-upon confidentiality.

\n
    \n
  • " }, { - "regExp": "
    \n■ ", + "regExp": "
    \n■ ", "replacement": "
  • \n
  • " }, { - "before": "three, male.
    \nBoth vials", + "before": "three, male.
    \nBoth vials", "after": "three, male.
  • \n
\n

Both vials" }, { @@ -1904,24 +1904,24 @@ "after": "

Sweet Honey—

" }, { - "before": "

Love me, love me, you know you wanna love me…
\nLove me, love me, you know you wanna love me…

", - "after": "

Love me, love me, you know you wanna love me…
\nLove me, love me, you know you wanna love me…

" + "before": "

Love me, love me, you know you wanna love me…
\nLove me, love me, you know you wanna love me…

", + "after": "

Love me, love me, you know you wanna love me…
\nLove me, love me, you know you wanna love me…

" }, { - "before": "

Love me, you?
\nLove me, true?

", - "after": "

Love me, you?
\nLove me, true?

" + "before": "

Love me, you?
\nLove me, true?

", + "after": "

Love me, you?
\nLove me, true?

" }, { - "before": "

Crazed, kooky, cracked, crazy,
\nNutty, barmy, mad for me…

", - "after": "

Crazed, kooky, cracked, crazy,
\nNutty, barmy, mad for me…

" + "before": "

Crazed, kooky, cracked, crazy,
\nNutty, barmy, mad for me…

", + "after": "

Crazed, kooky, cracked, crazy,
\nNutty, barmy, mad for me…

" }, { - "before": "

Crazed, kooky, cracked, crazy,
\nMental, dotty, whacked, loopy…

", - "after": "

Crazed, kooky, cracked, crazy,
\nMental, dotty, whacked, loopy…

" + "before": "

Crazed, kooky, cracked, crazy,
\nMental, dotty, whacked, loopy…

", + "after": "

Crazed, kooky, cracked, crazy,
\nMental, dotty, whacked, loopy…

" }, { - "before": "

Crazed, kooky, cracked, crazy,
\nNutty, screwy, mentally diseased…
\n
She ", - "after": "

Crazed, kooky, cracked, crazy,
\nNutty, screwy, mentally diseased…

\n

She " + "before": "

Crazed, kooky, cracked, crazy,
\nNutty, screwy, mentally diseased…
\n
She ", + "after": "

Crazed, kooky, cracked, crazy,
\nNutty, screwy, mentally diseased…

\n

She " }, { "before": "Ça va?", @@ -2206,7 +2206,7 @@ ], "https://parahumans.wordpress.com/2012/09/11/prey-14-3/": [ { - "before": "truck reached
\nthe other Nine", + "before": "truck reached
\nthe other Nine", "after": "truck reached the other Nine" }, { @@ -2266,7 +2266,7 @@ ], "https://parahumans.wordpress.com/2012/10/18/interlude-15-donation-bonus/": [ { - "before": "volunteered, asked
\n
to", + "before": "volunteered, asked
\n
to", "after": "volunteered, asked to" }, { @@ -3365,7 +3365,7 @@ "https://parahumans.wordpress.com/2013/06/25/interlude-24-donation-bonus-1/": [ { "before": "silence like this. Divide: They", - "after": "silence like this.
Divide: They" + "after": "silence like this.
Divide: They" }, { "before": "Bay,” Wanton said. “Not", @@ -3441,7 +3441,7 @@ }, { "before": "SimurghNotes", - "after": "Simurgh
Notes" + "after": "Simurgh
Notes" }, { "before": "avoided-", @@ -4238,7 +4238,7 @@ "after": "Imp: I’ve" }, { - "before": "Tattletale:
\nwaiting?", + "before": "Tattletale:
\nwaiting?", "after": "Tattletale: waiting?" }, { @@ -4308,7 +4308,7 @@ ], "https://www.parahumans.net/2017/09/11/daybreak-1-1/": [ { - "before": "

Ward is the second work in the Parahumans series, and reading Worm first is strongly recommended. A lot of this won’t make sense otherwise and if you do find yourself a fan of the universe, the spoilers in Ward will affect the reading of the other work.

\n

Ward is not recommended for young or sensitive readers.

\n
", + "before": "

Ward is the second work in the Parahumans series, and reading Worm first is strongly recommended. A lot of this won’t make sense otherwise and if you do find yourself a fan of the universe, the spoilers in Ward will affect the reading of the other work.

\n

Ward is not recommended for young or sensitive readers.

\n
", "after": "", "_comment": "This is out of place in an eBook." } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c5eb93a..599380f 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -2060,11 +2060,6 @@ "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", "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": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 90654f3..05b24e9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "jsdom": "^16.2.2", "requisition": "^1.5.0", "throat": "^5.0.0", - "xmlserializer": "^0.6.1", "yargs": "^15.3.1" }, "devDependencies": {