Skip to content

Commit

Permalink
Trim whitespace in converted chapters
Browse files Browse the repository at this point in the history
This shouldn't have any visible effects.
  • Loading branch information
domenic authored Jan 3, 2025
1 parent 8833cad commit 424b0de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/convert-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ function getBodyXML(chapter, bookTitle, contentEl) {
}

// Remove empty <p>s or Last Chapter/Next Chapter <p>s
while (isEmptyOrGarbage(contentEl.lastElementChild)) {
contentEl.lastElementChild.remove();
while (isEmptyOrGarbage(contentEl.firstChild)) {
contentEl.firstChild.remove();
}
while (isEmptyOrGarbage(contentEl.lastChild)) {
contentEl.lastChild.remove();
}

// Remove redundant attributes and style
Expand Down Expand Up @@ -137,11 +140,12 @@ function getBodyXML(chapter, bookTitle, contentEl) {

const h1El = contentEl.ownerDocument.createElement("h1");
h1El.textContent = chapter.usedTitle;
bodyEl.appendChild(h1El);
bodyEl.append(h1El, "\n\n");

while (contentEl.firstChild) {
bodyEl.appendChild(contentEl.firstChild);
bodyEl.append(contentEl.firstChild);
}
bodyEl.append("\n");

const xmlSerializer = new contentEl.ownerDocument.defaultView.XMLSerializer();
let xml = xmlSerializer.serializeToString(bodyEl);
Expand Down
4 changes: 0 additions & 4 deletions lib/substitutions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4619,10 +4619,6 @@
}
],
"https://www.parahumans.net/2017/12/01/daybreak-1-8/": [
{
"before": "<p style=\"text-align: center;\">\n</p><p>",
"after": "<p>"
},
{
"before": "parahumans online",
"after": "Parahumans Online"
Expand Down

0 comments on commit 424b0de

Please sign in to comment.