title: Separate an HTML document with headings into sections
body: <p>How can I separate in sections a document with headings?</p>
  
  <p>Convert this</p>
  
  <pre><code>&lt;h1&gt;chapter 1&lt;/h1&gt;
  &lt;p&gt;lorem ipsum&lt;/p&gt;
  &lt;p&gt;sit amet&lt;/p&gt;
  &lt;h1&gt;chapter 2&lt;/h1&gt;
  &lt;p&gt;lorem ipsum&lt;/p&gt;
  &lt;p&gt;sit amet&lt;/p&gt;
  </code></pre>
  
  <p>into this</p>
  
  <pre><code>&lt;div class="chapter"&gt;
    &lt;h1&gt;chapter 1&lt;/h1&gt;
    &lt;p&gt;lorem ipsum&lt;/p&gt;
    &lt;p&gt;sit amet&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="chapter"&gt;
    &lt;h1&gt;chapter 2&lt;/h1&gt;
    &lt;p&gt;lorem ipsum&lt;/p&gt;
    &lt;p&gt;sit amet&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I guess with jQuery this is easy, but I haven't figured how yet.</p>