diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/d-wrap.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/d-wrap.js.es6 index 4b4b4ce4d20..73dd3ca26cc 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/d-wrap.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/d-wrap.js.es6 @@ -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) { Object.keys(attributes).forEach(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) { token.attrs.push([`data-${tag}`, value]);