Skip to content

Commit 8649d87

Browse files
committed
support classname
1 parent 4b4fd10 commit 8649d87

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/vhtml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import emptyTags from './empty-tags';
33
// escape an attribute
44
let esc = str => String(str).replace(/[&<>"']/g, s=>`&${map[s]};`);
55
let map = {'&':'amp','<':'lt','>':'gt','"':'quot',"'":'apos'};
6+
let special = attr => (attr === 'className') ? 'class' : attr;
67

78
let sanitized = {};
89

@@ -23,7 +24,7 @@ export default function h(name, attrs) {
2324
let s = `<${name}`;
2425
if (attrs) for (let i in attrs) {
2526
if (attrs[i]!==false && attrs[i]!=null) {
26-
s += ` ${esc(i)}="${esc(attrs[i])}"`;
27+
s += ` ${special(esc(i))}="${esc(attrs[i])}"`;
2728
}
2829
}
2930

test/vhtml.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ describe('vhtml', () => {
157157
`<div><area><base><br><col><command><embed><hr><img><input><keygen><link><meta><param><source><track><wbr><div></div><span></span><p></p></div>`
158158
);
159159
});
160+
161+
it('should handle className as class', () => {
162+
expect(
163+
<div className="my-class" />
164+
).to.equal(
165+
'<div class="my-class"></div>'
166+
);
167+
});
160168
});

0 commit comments

Comments
 (0)