Hexo: TOC seems not suitable when skipping heading levels

Created on 4 Sep 2016  ·  5Comments  ·  Source: hexojs/hexo

When there is a link in the header, such as:

# Header1

Content....

# [Header2](http://selfboot.cn)

content...

## Sub Header

content...

Then the toc generated seems a bit strange, just looks like:

<ol class="toc">
<li class="toc-item toc-level-1">
...
</ol>
<li class="toc-item toc-level-1"><a class="toc-link" href="#Sub Header"><span class="toc-number">2.</span> <span class="toc-text">Sub Header</span></a></li>
...

Should not all the <li class="toc-item toc-level-*"> be in ol.toc ?

Version:

$ hexo --version
hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 15.6.0 darwin x64
http_parser: 2.7.0
node: 6.4.0
v8: 5.0.71.60
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2h

And in this blog, there is a live demo.

bug

Most helpful comment

@stevenjoezhang It appears that @ppoffice has already fix the issue in his icarus theme. Maybe we could borrow some idea from it.

All 5 comments

Seems it has been resolved on your site.

I have not resolved this issue.

As you can see, in my blog, the structure is as follows:

image

But it should be as follows:

image

I think I might know what is happened here.

The title timeit in your post is <h1> (#) while the subtitle under (likes 命令行接口 and Python 接口) are in <h3> (###).

So far there is no better way to fix that issue, all we could suggest is not to skip any level of headings now.

We will keep this issue opened until we came up with some better idea to solve this.

@stevenjoezhang It appears that @ppoffice has already fix the issue in his icarus theme. Maybe we could borrow some idea from it.

Was this page helpful?
0 / 5 - 0 ratings