Skip to content

Allow h1 in in-page toc#1842

Merged
mdlinville merged 2 commits intodocker:masterfrom
mdlinville:allow_h1_in_toc
Feb 18, 2017
Merged

Allow h1 in in-page toc#1842
mdlinville merged 2 commits intodocker:masterfrom
mdlinville:allow_h1_in_toc

Conversation

@mdlinville
Copy link

@mdlinville mdlinville commented Feb 18, 2017

#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: 1 from being honored. It also adds documentation about valid front-matter elements to the README, for the edification of all.

To test: Check out this PR, edit a page (maybe testing.md), set toc_min: 1, and verify that the page title is in the in-page TOC and when you click it, you get to the # anchor.

Copy link
Contributor

@londoncalling londoncalling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mdlinville mdlinville merged commit b40c280 into docker:master Feb 18, 2017
@mdlinville
Copy link
Author

@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 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh derp! I see what you mean, good call

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.

3 participants