FIX: allows to specify camelCased attributes in wrap component (#7919)

This commit is contained in:
Joffrey JAFFEUX 2019-07-22 09:24:27 +02:00 committed by GitHub
parent 651a5b6e40
commit 67650328b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -11,10 +11,16 @@ function parseAttributes(tagInfo) {
); );
} }
function camelCaseToDash(str) {
return str.replace(/([a-zA-Z])(?=[A-Z])/g, "$1-").toLowerCase();
}
function applyDataAttributes(token, state, attributes) { function applyDataAttributes(token, state, attributes) {
Object.keys(attributes).forEach(tag => { Object.keys(attributes).forEach(tag => {
const value = state.md.utils.escapeHtml(attributes[tag]); const value = state.md.utils.escapeHtml(attributes[tag]);
tag = state.md.utils.escapeHtml(tag.replace(/[^a-z0-9\-]/g, "")); tag = camelCaseToDash(
state.md.utils.escapeHtml(tag.replace(/[^A-Za-z\-0-9]/g, ""))
);
if (value && tag && tag.length > 1) { if (value && tag && tag.length > 1) {
token.attrs.push([`data-${tag}`, value]); token.attrs.push([`data-${tag}`, value]);