Skip to content

Commit

Permalink
fix(prop): innerText and innerHTML management + writeAttribute functi…
Browse files Browse the repository at this point in the history
…on isolation
  • Loading branch information
nomocas committed May 3, 2017
1 parent d364d7c commit 70462ee
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ const stringPragmas = babelute.createFacadePragmatics({
},

prop(tag, args) {
if (args[1])
tag.attributes += ' ' + args[0];
switch (args[0]) {
case 'innerText':
case 'innerHTML':
tag.attributes = args[1];
break;
case 'value':
tag.attributes += ' ' + writeAttribute('value', args[1]);
break;
default:
if (args[1])
tag.attributes += ' ' + args[0];
}
},

data(tag, args) {
Expand All @@ -79,11 +89,8 @@ const stringPragmas = babelute.createFacadePragmatics({
},

attr(tag, args /* name, value */ ) {
const value = args[1];
// tag.attributes += ' ' + args[0] + '="' + (typeof value === 'string' ? encodeHtmlSpecialChars(value) : value) + '"';
tag.attributes += ' ' + args[0] + '="' + (typeof value === 'string' ? value.replace(/"/g, '\\"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;') : value) + '"';
tag.attributes += ' ' + writeAttribute(args[0], args[1]);
},

id(tag, args /* value */ ) {
Expand Down Expand Up @@ -155,6 +162,12 @@ function tagOutput(parent, tag, name) {
parent.children += out + '></' + name + '>';
}

function writeAttribute(name, value) {
return name + '="' + (typeof value === 'string' ? value.replace(/"/g, '\\"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;') : value) + '"';
}

htmlLexicon.addAliases({
$toHTMLString(domElement) {
return stringPragmas.$output(domElement, this);
Expand Down

0 comments on commit 70462ee

Please sign in to comment.