Skip to content

Commit

Permalink
Create convertTableToDiv to fix royalroad tables on tolino
Browse files Browse the repository at this point in the history
  • Loading branch information
gamebeaker committed Sep 26, 2024
1 parent cb0d34e commit 4a400f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
7 changes: 7 additions & 0 deletions plugin/js/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Parser {
util.decodeCloudflareProtectedEmails(content);
this.removeNextAndPreviousChapterHyperlinks(webPage, content);
this.removeUnwantedElementsFromContentElement(content);
this.convertTabletoDiv(content);
this.addTitleToContent(webPage, content);
util.fixBlockTagsNestedInInlineTags(content);
this.imageCollector.replaceImageTags(content);
Expand Down Expand Up @@ -143,6 +144,12 @@ class Parser {
util.removeLeadingWhiteSpace(element);
};

convertTabletoDiv(element) {
if (this.userPreferences.styleSheet.value.includes(".WebToEpub-table")) {
util.convertTableToDiv(element);
}
};

customRawDomToContentStep(chapter, content) { // eslint-disable-line no-unused-vars
// override for any custom processing
}
Expand Down
30 changes: 29 additions & 1 deletion plugin/js/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,33 @@ var util = (function () {
node.remove();
}

var convertTableToDiv = function(element) {
for(let table of [...element.querySelectorAll("table")]) {
replaceTableToDivHelper(table, "td", "WebToEpub-cell");
replaceTableToDivHelper(table, "tr", "WebToEpub-row");
replaceTableToDivHelper(table, "tbody", "");
replaceTableToDivHelper(table.parentNode, "table", "WebToEpub-table");
}
}

var replaceTableToDivHelper = function(element, elementtoreplace, divclass) {
if (element == null || element == undefined) {
return;
}
for(let node of [...element.querySelectorAll(elementtoreplace)]) {
let elementchildren = [...node.childNodes];
let div = document.createElement("div");
div.append(...elementchildren);
if (elementtoreplace == "table") {
node.parentNode.style.overflow = "visible";
}
if (divclass != "") {
div.classList.add(divclass);
}
node.replaceWith(div);
}
}

/**
* @todo expand to remove ALL event handlers
*/
Expand Down Expand Up @@ -1035,7 +1062,8 @@ var util = (function () {
createChapterTab: createChapterTab,
syncLoadSampleDoc : syncLoadSampleDoc,
xmlToString: xmlToString,
zeroPad: zeroPad
zeroPad: zeroPad,
convertTableToDiv: convertTableToDiv
};
})();

Expand Down

0 comments on commit 4a400f9

Please sign in to comment.