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

Projects
None yet
2 participants
@SteveMarshall
Member

SteveMarshall commented Aug 30, 2017

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 requested a review from digitalronin Aug 30, 2017

@SteveMarshall SteveMarshall force-pushed the fix-table-of-contents-liquid-rendering branch Aug 30, 2017

Add a Liquid-handling table of contents renderer
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 Aug 30, 2017

Use the more robust table of contents renderer
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 to e51091f Aug 30, 2017

@SteveMarshall SteveMarshall merged commit 17d0458 into master Aug 31, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@SteveMarshall SteveMarshall deleted the fix-table-of-contents-liquid-rendering branch Aug 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment