hexo icon indicating copy to clipboard operation
hexo copied to clipboard

TOC plugin (in addition of the helper)

Open noraj opened this issue 6 years ago • 5 comments

Feature request

Ok for the helper (https://hexo.io/docs/helpers#toc) https://github.com/hexojs/hexo/issues/408

but it would be cool to have a toc plugin too {% toc %} so instead of having the helper on a template we will be able to manually add a toc on a per article basis without modifying the template or frontmatters.

noraj avatar Oct 14 '18 19:10 noraj

Hi @noraj :wave:

I usually use this: https://github.com/bubkoo/hexo-toc

<!-- toc -->

Can you try and see if it works?

tcrowe avatar Oct 23 '18 01:10 tcrowe

@tcrowe Check what I said in #3288

noraj avatar Oct 23 '18 19:10 noraj

Maybe we could address this feature into a tag plugin which can be used as <!-- toc --> or {% toc %}.

SukkaW avatar Nov 17 '19 15:11 SukkaW

See also https://github.com/theme-next/hexo-theme-next/issues/1529

stevenjoezhang avatar Sep 01 '20 05:09 stevenjoezhang

I want to add a TOC in a page (Markdown content) but as @ptsteadman wrote this is not possible (https://github.com/hexojs/site/pull/118).

Using hexo-toc also doesn't work for me as it overwrites Hexo's native TOC helper: https://github.com/bubkoo/hexo-toc/issues/26 😢

bennycode avatar Apr 10 '22 11:04 bennycode

Hexo needs to generate the toc after all the tag plugins have been rendered, as other tag plugins may also generate heading elements in them. For example:

## Heading

{% toc %}

{% note %}
## Heading
{% endnote %}

Making the toc a tag plugin would make the rendering order unsatisfiable.

stevenjoezhang avatar Nov 21 '22 08:11 stevenjoezhang

Meanwhile I built my own hexo-insert-toc plugin which allows me to create a table of contents by placing a <!-- toc --> in my Markdown files.

bennycode avatar Nov 21 '22 12:11 bennycode

Closing as issue resolved

stevenjoezhang avatar Nov 21 '22 14:11 stevenjoezhang