diff --git a/plugin/js/Parser.js b/plugin/js/Parser.js index 2f8507b2..cd109c4e 100644 --- a/plugin/js/Parser.js +++ b/plugin/js/Parser.js @@ -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); @@ -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 } diff --git a/plugin/js/Util.js b/plugin/js/Util.js index 37661d50..688ef3a7 100644 --- a/plugin/js/Util.js +++ b/plugin/js/Util.js @@ -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 */ @@ -1035,7 +1062,8 @@ var util = (function () { createChapterTab: createChapterTab, syncLoadSampleDoc : syncLoadSampleDoc, xmlToString: xmlToString, - zeroPad: zeroPad + zeroPad: zeroPad, + convertTableToDiv: convertTableToDiv }; })();