Say, I have the following HTML:
<h1>Style Guide</h1>
<h2 id="a">a</h2>
<h3 id="aa">aa</h3>
<p>aa foo bar</p>
<h4 id="aaa">aaa</h4>
<p>blah blah</p>
<h2 id="b">b</h2>
<p>bbb</p>
<h2 id="c">c</h2>
<h3 id="cc">cc</h3>
<p>cc cc cc</p>
The generated ToC puts cc h3 into the first a group, instead of putting it under c group:

Say, I have the following HTML:
The generated ToC puts
cch3 into the firstagroup, instead of putting it undercgroup: