Skip to content

Instantly share code, notes, and snippets.

@xandrkat
Created August 16, 2020 14:15
Show Gist options
  • Select an option

  • Save xandrkat/83b6a9fd1c6c6709ae80fdb05a75bb68 to your computer and use it in GitHub Desktop.

Select an option

Save xandrkat/83b6a9fd1c6c6709ae80fdb05a75bb68 to your computer and use it in GitHub Desktop.
var map = [];
var last = 0;
for (var i = 1; i <= 5; i++) {
if ($('body').find('h' + i).length > 1) {
map[i] = $('body').find('h' + i);
map[i]['i'] = i;
}
}
map.forEach(function (el) {
var is = (last !== 0) ? last : el['i'];
var ll = el.length - 1;
el.map(function (key, els) {
if (key > 0) {
is++;
if (is <= 6) {
var replacement = document.createElement('h' + is);
} else {
var replacement = document.createElement('p');
}
if (ll === key) {
last = is;
}
var original = els;
for (var i = 0, l = original.attributes.length; i < l; ++i) {
var nodeName = original.attributes.item(i).nodeName;
var nodeValue = original.attributes.item(i).nodeValue;
replacement.setAttribute(nodeName, nodeValue);
}
replacement.innerHTML = original.innerHTML;
original.parentNode.replaceChild(replacement, original);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment