Allow h1 in in-page toc#1842
Allow h1 in in-page toc#1842mdlinville merged 2 commits intodocker:masterfrom mdlinville:allow_h1_in_toc
Conversation
londoncalling
left a comment
There was a problem hiding this comment.
Works great! I tested it on the Compose v3 file to show the H1 in the on-page, right-side menu. Bravo. Please let me know when it's merged.
|
@londoncalling It's merged! 🥇 |
| so if we request the h1 heading to be in the in-page TOC, | ||
| append it to the content before we pass it to the TOC generator | ||
| {% endcomment %} | ||
| {% assign my_content = "<h1>" | append: page.title | append: "</h1>" | append: content %} |
There was a problem hiding this comment.
Ahhh I think if an ID attr is added to this <h1> (i.e. make it <h1 id="page-title">) then the change to the _includes/toc_pure_liquid.html wouldn't be necessary. Just as a quick note 👍
There was a problem hiding this comment.
You might think that, but actually when you give it an ID then the link it generates encodes the ID. So if you do <h1 id="page-title-in-toc">...</h1>, then the link to the <h1> in the TOC becomes: http://localhost:4000/compose/compose-file/#/page-title-in-toc
It doesn't really make it do the wrong thing, since that ID doesn't really exist on the page, but it's kind of not really what you want either. I'm OK with the fix we have (and the follow-on PR where @londoncalling removed my inadvertent extra {{content}} div that I was using for debugging!
There was a problem hiding this comment.
Ohhh derp! I see what you mean, good call
#1474 added the ability to control the minimum and maximum level of HTML headings that would display in the in-page TOC for a given page. This PR fixes a bug that presented
toc_min: 1from being honored. It also adds documentation about valid front-matter elements to theREADME, for the edification of all.To test: Check out this PR, edit a page (maybe
testing.md), settoc_min: 1, and verify that the page title is in the in-page TOC and when you click it, you get to the#anchor.