Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .gitmessage
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# style: delete excess whitespace
#
# Body (optional):
# What changed and why
# Important design decisions or context
# what changed (1 sentence)
# (if relevant) important decisions/context (succinct bullets)
#
# Footer (optional):
# BREAKING CHANGE: describe breaking change
Expand Down
33 changes: 33 additions & 0 deletions src/lib/_utils/js/promote-data-aria-attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copy `data-aria-*` attributes to matching `aria-*` on the same nodes.
* For HTML saved through WYSIWYG editors that strip unprefixed ARIA on publish.
*
* @param {ParentNode | null | undefined} [root=document]
*/
export default function promoteDataAriaAttributes(root = document) {
if (!root) {
return;
}

const elements =
root instanceof Document
? root.querySelectorAll('*')
: root instanceof Element
? [ root, ...root.querySelectorAll('*') ]
: [];

for (const el of elements) {
if (!(el instanceof Element)) {
continue;
}
for (const attr of [ ...el.attributes ]) {
if (!attr.name.startsWith('data-aria-')) {
continue;
}
el.setAttribute(
'aria-' + attr.name.slice('data-aria-'.length),
attr.value
);
}
}
}