Skip to content

Add new allowCamelCasedAttributes option for camel cased attribute #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function attribute(ctx, key, value) {
/* Stringify the attribute name. */
function attributeName(ctx, key) {
var info = information(key) || {};
var name = info.name || kebab(key);
var name = info.name || (ctx.allowCamelCased ? key : kebab(key));

if (
name.slice(0, DATA.length) === DATA &&
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function toHTML(node, options) {
dangerous: settings.allowDangerousHTML,
voids: settings.voids || voids.concat(),
entities: settings.entities || {},
close: settings.closeSelfClosing
close: settings.closeSelfClosing,
allowCamelCased: settings.allowCamelCasedAttributes || false
}, node);
}
8 changes: 8 additions & 0 deletions test/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@ test('`element`', function (t) {
'should support `<template>`s content'
);

t.deepEqual(
to(h('svg', {viewBox: '0 0 400000 200', preserveAspectRatio: 'xMinYMin slice'}), {
allowCamelCasedAttributes: true
}),
'<svg viewBox="0 0 400000 200" preserveAspectRatio="xMinYMin slice"></svg>',
'should support camelCased attribute name like "viewBox"'
);

t.end();
});