Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A GitHub Pages compatible Table of Contents generator without a plugin or JavaScript :octocat:
Jekyll Pure Liquid Table of Contents (Jekyll TOC) is an open-source Jekyll include that generates a table of contents from kramdown-rendered HTML using only Liquid, so GitHub Pages sites can use it without plugins or JavaScript.
It is a single toc.html file you drop into your _includes folder and call with {% include toc.html html=content %}. It takes the compiled HTML of your markdown (as produced by kramdown) as the required html parameter and outputs a nested list of links to all heading levels. The project lives at allejo/jekyll-toc on GitHub, is maintained by the developer allejo, and is released under both BSD-3-Clause and MIT licenses.
Unlike kramdown's built-in option, this include can be placed in a Jekyll layout, so every page automatically gets a TOC without repeating the snippet in each post. Unlike JavaScript-based TOC generators, it renders server-side during the Jekyll build, so it works when JavaScript is disabled and adds only a small amount of build time.
h_min and h_max parameters include only headings within a chosen range; default is 1 to 6.ordered to true to output an <ol> instead of the default <ul>.sanitize to true to strip HTML tags from heading text in the TOC.class, id, item_class, and anchor_class let you theme the TOC; item_class and submenu_class support a %level% placeholder for the current heading level.base_url prepends a URL to TOC links when the TOC sits on a different page than the content.skip_no_ids, when true, ignores headings without an id attribute.flat_toc, when true, renders a single-level list instead of nested sublists.Jekyll site owners constrained by GitHub Pages' no-custom-plugin rule, theme developers who want to give their users an optional TOC, documentation authors managing large multi-page guides, and bloggers who write long posts that benefit from an automatic table of contents. The include has been adopted by documentation sites at Docker, Apache Beam and PDFBox, Travis CI, Google, Shopify, and the UK Ministry of Justice, as well as by Jekyll themes such as Minimal Mistakes and Bulma Clean.
h_min/h_max.toc.html into a theme so all users get TOC support; themes like Minimal Mistakes, Bulma Clean, and JetBrains' OSS theme already do this.base_url to point TOC links at headings on another page, for separated index and content pages.Download toc.html from the latest release and place it in your site's _includes directory. Then call {% include toc.html html=content %} in a layout or template, passing the compiled markdown HTML to the html parameter. Optionally adjust parameters such as h_min, h_max, ordered, and class to customize the output.
<h2> followed directly by <h4>) causes list items to render outside the list; it is not a plugin, so you must add the include call to your layout manually; it relies on kramdown-generated HTML, so it is Jekyll-specific.Jekyll TOC is free and open source. The repository is dual-licensed under BSD-3-Clause and MIT, so it can be redistributed and used in commercial projects under either license.
generator — usable but must be placed next to the actual markdown, making it hard to put in a layout.Yes. Because it is written entirely in Liquid and uses only standard Jekyll include and content variables, it requires no custom plugins, which GitHub Pages can't run. The author built it specifically to work in that environment and it is used on several GitHub Pages-hosted sites.
Download toc.html into your _includes folder, then include it in a layout with {% include toc.html html=content %}, where content is the kramdown-rendered HTML of your page. You can customize output with parameters like h_min, h_max, ordered, and sanitize.
This happens when your headings are not correctly nested. For example, if an <h2> is followed directly by an <h4> without an intermediate <h3>, the Liquid logic produces malformed HTML. The project deliberately keeps this behavior to avoid encouraging out-of-order headings; a third-party patch in issue #13 enables support for it.
The project is dual-licensed under BSD-3-Clause and MIT. You can choose which license applies when you redistribute or use the code in your own projects.
