Skip to content

Instantly share code, notes, and snippets.

@julian-boolean
Last active October 9, 2015 22:01
Show Gist options
  • Save julian-boolean/b547a79fe85785376d8b to your computer and use it in GitHub Desktop.
Save julian-boolean/b547a79fe85785376d8b to your computer and use it in GitHub Desktop.
/*Indent everything under h1,h2,h3 and h4 tags with indent width relative to order of headers.
<h1>ffoooo</h1>
<p> stuff
<pre>
<h2>
<p> level 2 stuff
<h3>
<h4>level 3 stuff
<p> level 4 stuff.
<h3>
<p> back to level 3
<h1>
<p>all the way back to level 1.
<h3>
<p>level 2,even thought the tag is h3
etc...
*/
[1,2,3,4].forEach(function(num){
var nodeType = 'h' + num;
$(nodeType).each(function(){
var $ul = $('<ul class="nobullet">').insertAfter($(this));
$ul.nextUntil(nodeType).wrapAll('<li>').parent().appendTo($ul);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment