Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more robust table of contents renderer #7

Merged
merged 2 commits into from
Aug 31, 2017

Conversation

SteveMarshall
Copy link
Contributor

It turns out that @allejo, who I found on #jekyll in Freenode, has written a pure Liquid table of contents renderer that works based on the final, rendered HTML rather than the Markdown. This means it doesn't have problems with headers that are generated by Liquid logic, and is thus more robust than my table of contents generator.

Given this code already exists, this PR incorporates it (attributing correctly), and makes use of it in our layout.

@SteveMarshall SteveMarshall force-pushed the fix-table-of-contents-liquid-rendering branch from 288e01c to 32492b5 Compare August 30, 2017 15:13
It turns out that @allejo, who I found on #jekyll in Freenode, has
written [a pure Liquid table of contents
renderer](https://allejo.io/blog/a-jekyll-toc-in-liquid-only/) that
works based on the final, rendered HTML rather than the Markdown. This
means it doesn't have problems with headers that are generated by
Liquid logic, and is thus more robust than my table of contents
generator. Given that, we can just integrate that table of contents
rendered.

This also adds the appropriate attribution for our use of @allejo's code.

The table of contents include does the following:

0. Accept, as input, the page content rendered as HTML (and, thus,
   already parsed by Liquid)
1. Split the HTML on `<h` and loop over the resulting `nodes` (making
   each `node` contain the remainder of the opening tag, and everything
   up to the next `<h`)
2. Generate new Markdown for each `node` by deconstructing the HTML up
   to the first `</h` (excluding headers and stripping markup according
   to input parameters)
5. Passes the rendered Markdown (in `my_toc`) through `markdownify` to
   output it.
@SteveMarshall SteveMarshall force-pushed the fix-table-of-contents-liquid-rendering branch from 32492b5 to 8d2ae92 Compare August 30, 2017 19:25
Now we have a more robust way to render tables of contents, we don't
have to exclude Jekyll-generated headers on the homepage, and don't have
to do our own set of markdown-mangling. Yay!
@SteveMarshall SteveMarshall force-pushed the fix-table-of-contents-liquid-rendering branch from 8d2ae92 to e51091f Compare August 30, 2017 19:48
@SteveMarshall SteveMarshall merged commit 17d0458 into master Aug 31, 2017
@SteveMarshall SteveMarshall deleted the fix-table-of-contents-liquid-rendering branch August 31, 2017 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants