Skip to content

Commit

Permalink
unnecessary whitespace and new line characters removed. do nothing if…
Browse files Browse the repository at this point in the history
… html is only whitespace. #16
  • Loading branch information
aruntk committed Mar 14, 2017
1 parent d42a7c9 commit 94a50d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function randomIdent() {
class DissectHtml {
constructor(config, options) {
this.dissected = {
html: '/*__wc__loader*/\n',
html: '/*__wc__loader*/',
js: '',
requires: '', // appended first
}
Expand Down Expand Up @@ -48,7 +48,9 @@ class DissectHtml {
this.dissected[_child.nodeName] = _childContents
// boolean where determines the section of html the content goes in
const where = _child.nodeName === 'head'
self.dissected.html += `\n${wcRenderer.generateJS(_childContents, where)}\n`
if(!_childContents.match('^[\\n\\r\s]+$')) {
self.dissected.html += `${wcRenderer.generateJS(_childContents, where)}`
}
}
break

Expand Down
16 changes: 1 addition & 15 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@ class _renderer {
generateJS(html, toHead) {
const htmlStr = JSON.stringify(html)
const where = toHead ? 'head' : 'body'
return `
(function(document) {
var _htmlStr = ${htmlStr};
if (document.${where}) {
var el = document.${where};
var div = document.createElement('div');
div.innerHTML = _htmlStr;
while (div.children.length > 0) {
el.appendChild(div.children[0]);
}
} else {
document.write(_htmlStr);
}
})(document);
`
return `!function(a){var b=${htmlStr};if(a.${where}){var c=a.${where},d=a.createElement("div");for(d.innerHTML=b;d.children.length>0;)c.appendChild(d.children[0])}else a.write(b)}(document);`
}

}
Expand Down

0 comments on commit 94a50d1

Please sign in to comment.