|
// remove hard spaces |
|
let bodyHTML = document.body.innerHTML; |
|
bodyHTML = bodyHTML.replace(/ /gim, ' '); |
|
bodyHTML = bodyHTML.replace(/\u00a0/gim, ' '); // |
|
bodyHTML = bodyHTML.replace(' ', ' '); |
|
bodyHTML = bodyHTML.replace(/<[^/>]+>[ \n\r\t]*<\/[^>]+>/gim, ''); // remove empry tags |
|
bodyHTML = bodyHTML.replace(/,([^ ])/gim, ', $1'); // fixes commas not followed by space |
|
//bodyHTML = bodyHTML.replace(/”([^ ])/gim, '” $1'); // fixes not followed by space |
|
//bodyHTML = bodyHTML.replace(/\.([^ <\d])/gim, '\. $1'); // fixes dot stops not followed by space |
|
//bodyHTML = bodyHTML.replace(/\:([^ ])/gim, '\: $1'); |
|
//bodyHTML = bodyHTML.replace(/\;([^ ])/gim, '\; $1'); |
|
document.body.innerHTML = bodyHTML; |
|
|
|
const linker = (accumulator, link) => accumulator + link.outerHTML; |
|
|
|
function replaceTags(query, newTag, exeptions, strip) { |
|
let newEle = null; |
|
let eleHTML = ''; |
|
let links = []; |
|
let linksHTML = ''; |
|
let newDom = null; |
|
let [tag, tagClass] = newTag.split('.') |
|
|
|
let elements = document.querySelectorAll(query) |
|
for (ele of elements) { |
|
newEle = document.createElement(tag); |
|
if (ele.id !== '') { |
|
newEle.id = ele.id; |
|
} |
|
if (tagClass !== undefined) { |
|
newEle.className = tagClass |
|
} |
|
if (strip !== undefined) { |
|
newEle.innerHTML = ele.innerHTML |
|
} else { |
|
eleHTML = ele.innerHTML |
|
links = Array.from(ele.querySelectorAll(exeptions)) |
|
if (links.length == 0) { |
|
linksHTML = '' |
|
} else { |
|
linksHTML = links.reduce(linker) |
|
} |
|
newEle.innerHTML = ele.textContent + linksHTML |
|
} |
|
|
|
if (newEle.innerHTML == '') { |
|
newDom = ele.parentNode.replaceChild(document.createTextNode(" "), ele); |
|
//newDom = ele.parentNode.removeChild( ele); |
|
} else { |
|
newDom = ele.parentNode.replaceChild(newEle, ele); |
|
} |
|
} |
|
} |
|
|
|
let replace = [ |
|
['p.Tittle', 'h2', 'a'], |
|
['p.Podtyt-', 'h3.subtitle', 'a'], |
|
['span.char-style-override-14', 'em'], |
|
['p.Podtyt-2', 'h3', 'a'], |
|
['p.podtyt-3', 'h4', 'a'], |
|
['p.podtyt4', 'h5', 'a'], |
|
['p.tekst2', 'p.colofon', false], |
|
['p.Normal', 'p', '', false], |
|
['p.tekst', 'p', '', false], |
|
['p.tekst1', 'p.opening', '', false], |
|
|
|
['p.tibetan', 'p.tibetan', 'a', false] |
|
] |
|
|
|
for (toReplace of replace) |
|
replaceTags(...toReplace) |
|
|
|
|
|
|