Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1520e98

Browse files
Fix HTML + SVG attribute casing
1 parent e02629e commit 1520e98

File tree

2 files changed

+466
-1
lines changed

2 files changed

+466
-1
lines changed

‎src/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
384384
v = styleObjToCss(v);
385385
}
386386
break;
387+
case 'acceptCharset':
388+
name = 'accept-charset';
389+
break;
390+
case 'httpEquiv':
391+
name = 'http-equiv';
392+
break;
387393

388394
default: {
389395
if (isSvgMode && XLINK.test(name)) {
@@ -395,6 +401,14 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
395401
// `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory
396402
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable
397403
v += '';
404+
} else if (isSvgMode) {
405+
if (SVG_CAMEL_CASE.test(name)) {
406+
name = name === 'panose1' ? 'panose-1' : camelToKebab(name);
407+
} else if (XML_REPLACE_REGEX.test(name)) {
408+
name = name.toLowerCase().replace(XML_REPLACE_REGEX, 'xml:');
409+
}
410+
} else if (!HTML_SKIP_CASE.test(name)) {
411+
name = name.toLowerCase();
398412
}
399413
}
400414
}
@@ -439,6 +453,16 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
439453
return s + '>' + html + '</' + type + '>';
440454
}
441455

456+
/**
457+
* Convert fooBar strings to foo-bar
458+
* @param {string} str
459+
*/
460+
const camelToKebab = (str) =>
461+
str.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase());
462+
463+
const HTML_SKIP_CASE = /^cell|^default|use/;
464+
const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;
465+
const XML_REPLACE_REGEX = /^xml:?/;
442466
const XLINK_REPLACE_REGEX = /^xlink:?/;
443467
const SELF_CLOSING = new Set([
444468
'area',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /