Skip to content

Commit

Permalink
remove redundant whitespaces; not entirely correct though. see #4
Browse files Browse the repository at this point in the history
  • Loading branch information
freddy committed Apr 22, 2013
1 parent acf2f14 commit 23abc83
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/html2dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ function mkId(node) {
if (parentName != undefined) { appendToParent(parentName, node); }
}
else if (node.nodeType == Node.TEXT_NODE) {
// skips whitespace-only text nodes:
if (/\S/.test(node.textContent)) {
// skips whitespace-only
newText(node, node.textContent);
/* remove duplicate whitespaces..
* XXX this is wrong for pre-tags and tags with style
* white-space: pre, pre-wrap or pre-line
* see http://stackoverflow.com/questions/15361012/extract-whitespace-collapsed-text-from-html-as-it-would-be-rendered
*/
cleaned = node.textContent.replace(/\s+/,' ')
newText(node, cleaned);
if (parentName != undefined) { appendToParent(parentName, node); }
}
}
Expand Down

0 comments on commit 23abc83

Please sign in to comment.