I need to automatically edit some html files kept in a database. I'm doing a script using node.js to get the files, then I use jsdom and jquery to do the editions I need.
Finally I need to save the files back to the database, however, all text should use HTML entities.
So, for instance, this page:
<html>
<header>
<title>Título da página</title>
</heade>
<body>
<h1> Aqui também há acentos </h1>
</body>
</html>
Should be saved as:
<html>
<header>
<title>Título da página</title>
</heade>
<body>
<h1> Aqui também há acentos </h1>
</body>
</html>
It doens't seem JSDOM API has this option, but I'm having a hard time finding all text elements with jquery also. Any suggestion?
Thanks,
PS: Some of the things I tried:
function recursiveReplace(node) {
if (node.nodeType == 3) { // text node
node.nodeValue = node.nodeValue.replace("1", "۱");
} else if (node.nodeType == 1) { // element
$(node).contents().each(function () {
recursiveReplace(this);
});
}
}
recursiveReplace(document.body);
from here
And
$('body').text()
from here, which replaces all the body with just the text, instead of the text inside the tags.
And some other...