Skip to content

Commit

Permalink
support classname
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill committed Apr 29, 2017
1 parent 4b4fd10 commit 8649d87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import emptyTags from './empty-tags';
// escape an attribute
let esc = str => String(str).replace(/[&<>"']/g, s=>`&${map[s]};`);
let map = {'&':'amp','<':'lt','>':'gt','"':'quot',"'":'apos'};
let special = attr => (attr === 'className') ? 'class' : attr;

let sanitized = {};

Expand All @@ -23,7 +24,7 @@ export default function h(name, attrs) {
let s = `<${name}`;
if (attrs) for (let i in attrs) {
if (attrs[i]!==false && attrs[i]!=null) {
s += ` ${esc(i)}="${esc(attrs[i])}"`;
s += ` ${special(esc(i))}="${esc(attrs[i])}"`;
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,12 @@ describe('vhtml', () => {
`<div><area><base><br><col><command><embed><hr><img><input><keygen><link><meta><param><source><track><wbr><div></div><span></span><p></p></div>`
);
});

it('should handle className as class', () => {
expect(
<div className="my-class" />
).to.equal(
'<div class="my-class"></div>'
);
});
});

0 comments on commit 8649d87

Please sign in to comment.