myakura/n — Issue #4: Better script for toc generation.
Author: myakura
Created: 2011-10-28 02:27:32+00:00
State: open

currently I use following for generating table of contents:

```javascript
if (!!document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
var sec = document.querySelectorAll('body > section[id]');
var h = document.querySelectorAll('body > section[id] > h2:first-of-type');
var toc = '';
var l = sec.length;
while (l--) {
toc = '
' + h[l].innerHTML + '' + toc;
}
var nav = document.createElement('nav');
nav.innerHTML = '

目次

' + toc + '

';
document.body.insertBefore(nav, sec[0]);
}, false);
}
```

Now, I started using subsections and h3 for the placeholder article. The code above doesn't cover that.
I've done that intentionally though, but now I want that toc can nest by one level (i.e. supporting subsections).