diff --git a/lib/convert.js b/lib/convert.js index 9e57706..db00e13 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -92,7 +92,8 @@ function getBodyXml(chapter, contentEl) { const ems = contentEl.querySelectorAll("em, i"); Array.prototype.forEach.call(ems, function (em) { if (em.textContent.trim() === "") { - em.parentNode.removeChild(em); + const replacement = contentEl.ownerDocument.createTextNode(" "); + em.parentNode.replaceChild(replacement, em); } else { em.removeAttribute("style"); } @@ -118,9 +119,9 @@ function getBodyXml(chapter, contentEl) { span.parentNode.removeChild(span); } else { const docFrag = contentEl.ownerDocument.createDocumentFragment(); - Array.prototype.forEach.call(span.childNodes, function (childNode) { - docFrag.appendChild(childNode); - }); + while (span.firstChild) { + docFrag.appendChild(span.firstChild); + } span.parentNode.replaceChild(docFrag, span); } }); @@ -141,14 +142,12 @@ function getBodyXml(chapter, contentEl) { // Fix recurring strange pattern of extra
in

......
\n

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

"); - // Fix recurring broken-up s - xml = xml.replace(/<\/em>‘s/, "’s") - xml = xml.replace(/<\/em>/g, ""); - xml = xml.replace(/<\/em>([^A-Za-z]{1,2})/g, "$1"); - xml = xml.replace(/<\/em>\. /g, ". "); - // Fix recurring poor closing quotes xml = xml.replace(/“<\/p>/g, "”

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

"); + + // Fix use of ′ instead of closing single quote + xml = xml.replace(/′/g, "’"); // Some fixes for dashes; not comprehensive xml = xml.replace(/ – /g, "—"); @@ -158,21 +157,38 @@ function getBodyXml(chapter, contentEl) { xml = xml.replace(/-“/g, "—”"); xml = xml.replace(/

-/g, "

—"); xml = xml.replace(/-<\/p>/g, "—

"); + xml = xml.replace(/\s?\s?–\s?\s?/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. xml = xml.replace(/([^\xA0])\xA0\xA0?([^\xA0])/g, "$1 $2"); + // Fix recurring broken-up s + xml = xml.replace(/<\/em>‘s/g, "’s") + xml = xml.replace(/<\/em>/g, ""); + xml = xml.replace(/<\/em>\. /g, ". "); + xml = xml.replace(/“([^>]+)<\/em>(!|\?|\.)”/g, "“$1$2<\/em>”"); + + // Fix recurring miscapitalization with questions + xml = xml.replace(/\?”\s\s?She asked/g, "?” she asked"); + xml = xml.replace(/\?”\s\s?He asked/g, "?” he asked"); + + // Fix extra periods at the end of paragraphs + xml = xml.replace(/\.\.<\/p>/g, ".

"); + + // Replace single-word s with s. Other s are probably erroneous too, but these are known-bad. + xml = xml.replace(/([A-Za-z]+)<\/i>/g, "$1"); + // One-off fixes (substitutions[chapter.url] || []).forEach(function (substitution) { const indexOf = xml.indexOf(substitution.before); if (indexOf === -1) { - throw new Error(`Could not find text "${substitution.before}" in ${chapter.url}. The chapter may have been ` + - `updated at the source, in which case, you should edit substitutions.json.`); + console.warn(`Could not find text "${substitution.before}" in ${chapter.url}. The chapter may have been ` + + `updated at the source, in which case, you should edit substitutions.json.`); } if (indexOf !== xml.lastIndexOf(substitution.before)) { - throw new Error(`The text "${substitution.before}" occurred twice, and so the substitution was ambiguous. ` + - `Update substitutions.json for a more precise substitution.`); + console.warn(`The text "${substitution.before}" occurred twice, and so the substitution was ambiguous. ` + + `Update substitutions.json for a more precise substitution.`); } xml = xml.replace(new RegExp(escapeRegExp(substitution.before)), substitution.after); diff --git a/lib/substitutions.json b/lib/substitutions.json index 2889457..aea0325 100644 --- a/lib/substitutions.json +++ b/lib/substitutions.json @@ -1,4 +1,34 @@ { + "https://parahumans.wordpress.com/2011/08/06/interlude-2/": [ + { + "before": "principles, Glory", + "after": "principles, Glory" + } + ], + "https://parahumans.wordpress.com/2011/12/03/hive-5-9/": [ + { + "before": "insult. An excuse to trounce me physically.", + "after": "insult.
An excuse to trounce me physically." + } + ], + "https://parahumans.wordpress.com/2012/03/13/extermination-8-4/": [ + { + "before": "Endbringer. After the laser petered out, he", + "after": "Endbringer. After the laser petered out, he" + } + ], + "https://parahumans.wordpress.com/2012/03/17/extermination-8-5/": [ + { + "before": "past tense-, or", + "after": "past tense—or" + } + ], + "https://parahumans.wordpress.com/2012/08/11/snare-13-5/": [ + { + "before": "similar. ", + "after": "similar. " + } + ], "https://parahumans.wordpress.com/2012/09/11/prey-14-3/": [ { "before": "truck reached
\nthe other Nine", @@ -29,12 +59,6 @@ "after": "this sort of resistance?" } ], - "https://parahumans.wordpress.com/2012/11/27/monarch-16-2/": [ - { - "before": "waseven less", - "after": "was even less" - } - ], "https://parahumans.wordpress.com/2012/12/04/monarch-16-4/": [ { "before": "well, with Bitch’s civilian", @@ -73,8 +97,8 @@ ], "https://parahumans.wordpress.com/2013/01/09/migration-17-2/": [ { - "before": "fence!", - "after": "fence!" + "before": "left now.’

", + "after": "left now.

" } ], "https://parahumans.wordpress.com/2013/01/10/migration-17-3/": [ @@ -85,10 +109,6 @@ { "before": "No. the", "after": "No. The" - }, - { - "before": "help?” He", - "after": "help?” he" } ], "https://parahumans.wordpress.com/2013/01/12/migration-17-5/": [ @@ -122,10 +142,6 @@ } ], "https://parahumans.wordpress.com/2013/01/19/queen-18-1/": [ - { - "before": "could beon", - "after": "could be on" - }, { "before": "untrustworthy.", "after": "untrustworthy." @@ -137,18 +153,6 @@ "after": "French accent" } ], - "https://parahumans.wordpress.com/2013/01/31/interlude-18-donation-bonus-2/": [ - { - "before": "Bay.She", - "after": "Bay. She" - } - ], - "https://parahumans.wordpress.com/2013/02/07/interlude-18-donation-bonus-3/": [ - { - "before": "instinctthat", - "after": "instinct that" - } - ], "https://parahumans.wordpress.com/2013/02/12/queen-18-8/": [ { "before": "dragged long", @@ -158,7 +162,7 @@ "https://parahumans.wordpress.com/2013/02/14/interlude-18-donation-bonus-4/": [ { "before": "C.U.l China", - "after": "C.U. China" + "after": "C.U.I. China" }, { "before": "Faulltine asked", @@ -169,48 +173,116 @@ "after": "through Faultline" } ], - "https://parahumans.wordpress.com/2013/02/16/interlude-18/": [ - { - "before": "Gruewas", - "after": "Grue was" - }, - { - "before": "askinga", - "after": "asking a" - } - ], - "https://parahumans.wordpress.com/2013/02/19/scourge-19-1/": [ - { - "before": "‘s9′", - "after": "‘s9’" - } - ], - "https://parahumans.wordpress.com/2013/02/23/scourge-19-2/": [ - { - "before": "You’llstop", - "after": "You’ll stop" - } - ], - "https://parahumans.wordpress.com/2013/02/26/scourge-19-3/": [ - { - "before": "areconnected", - "after": "are connected" - } - ], "https://parahumans.wordpress.com/2013/02/28/interlude-19-donation-bonus-1/": [ - { - "before": "English?” He asked", - "after": "English?” he asked" - }, { "before": "and be brought it", "after": "and he brought it" } ], + "https://parahumans.wordpress.com/2013/03/09/scourge-19-6/": [ + { + "before": "heailng", + "after": "healing" + } + ], + "https://parahumans.wordpress.com/2013/03/12/scourge-19-7/": [ + { + "before": "they did, but how we dealt", + "after": "they did, but how we dealt" + } + ], "https://parahumans.wordpress.com/2013/03/16/interlude-19-y/": [ { "before": "Brockton bay", "after": "Brockton Bay" } + ], + "https://parahumans.wordpress.com/2013/03/30/chrysalis-20-4/": [ + { + "before": "guess-, while", + "after": "guess—while" + } + ], + "https://parahumans.wordpress.com/2013/04/04/interlude-20-donation-bonus-1/": [ + { + "before": "’20th’", + "after": "‘20th’" + } + ], + "https://parahumans.wordpress.com/2013/04/06/interlude-20/": [ + { + "before": "the costume were studded", + "after": "the costume was studded" + } + ], + "https://parahumans.wordpress.com/2013/04/13/imago-21-2/": [ + { + "before": "Captain’s hill", + "after": "Captain’s Hill" + } + ], + "https://parahumans.wordpress.com/2013/04/25/imago-21-7/": [ + { + "before": "Dinah. because this", + "after": "Dinah. Because this" + } + ], + "https://parahumans.wordpress.com/2013/04/30/interlude-21/": [ + { + "before": "But…Maybe she", + "after": "But… Maybe she" + } + ], + "https://parahumans.wordpress.com/2013/05/07/cell-22-2/": [ + { + "before": "said, “Is to set", + "after": "said, “is to set" + } + ], + "https://parahumans.wordpress.com/2013/05/18/interlude-22/": [ + { + "before": "long,” she warned", + "after": "long,” she warned" + } + ], + "https://parahumans.wordpress.com/2013/05/21/interlude-22-donation-bonus-1/": [ + { + "before": "“is it reassuring", + "after": "“Is it reassuring" + } + ], + "https://parahumans.wordpress.com/2013/05/25/drone-23-1/": [ + { + "before": "Defiant spoke , “Let’s", + "after": "Defiant spoke. “Let’s" + } + ], + "https://parahumans.wordpress.com/2013/05/28/drone-23-2/": [ + { + "before": "of the ship. It’s", + "after": "of the ship.’ It’s" + } + ], + "https://parahumans.wordpress.com/2013/06/01/drone-23-4/": [ + { + "before": "better off?'”", + "after": "better off?’”" + }, + { + "before": "said. Someone", + "after": "said. “Someone" + } + ], + "https://parahumans.wordpress.com/2013/09/28/venom-29-5/": [ + { + "before": "Losing you as you get further down.”", + "after": "Losing you as you get further down.”" + } + ], + "https://parahumans.wordpress.com/2013/11/05/teneral-e-2/": [ + { + "before": "property of Nero", + "after": "property of Nero" + } ] }