-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
Ignore specific headers #3
Comments
Glad this could save you some time 😄 Is this the type of structure you're looking at? <h2>Heading 1</h2>
<div class="bd-example">
<h2>Sample Heading</h2>
</div> You would need the toc to only include "Heading 1" but ignore "Sample Heading"? Or does "Sample Heading" have a If it's the former, I'm open to clever ideas on how to achieve this. At the moment, the toc is just blindly pulling out headings and doesn't really know about the structure of the HTML. If the headings have a class to ignore, that should be pretty straightforward to add. |
Our structure is similar to that, yeah. <h2>foo</h2>
<h2>bar</h2>
<div class="bd-example">
<p>foo</p>
<h4>Sample Heading</h4> <!-- we don't need this -->
</div>
<h2>bar</h2>
<h3>bar</h3> So it's the former case you mention above. I guess we could try extending it later if needed :) I had a quick look but couldn't make the loop it work properly at the limited time I spent. Basically I used |
So I've pushed f94a076, which should fix removing any extra whitespace from the generated TOC. Adding The whitespace control (e.g. The problem I'm seeing right now by trying to exclude headings inside of a selector is, I can loop through the nodes and find <h2>foo</h2>
<h2>bar</h2>
<div class="bd-example">
<p>foo</p>
<h4>Sample Heading</h4> <!-- we don't need this -->
<div class="row">
<div class="col-md-6">
<h5>Nested Heading</h5>
</div>
<div class="col-md-6">
<h4>Heading would be tracked again</h4>
</div>
</div>
</div>
<h2>bar</h2>
<h3>bar</h3> Sure, I could make it a unique tag like At least, this is the approach I was thinking of but it wouldn't reliably work. Clever approaches are welcome! |
We could introduce a custom directive, like Something like this: <h2>foo</h2>
<h2>bar</h2>
<!-- toc-ignore -->
<div class="bd-example">
<p>foo</p>
<h4>Sample Heading</h4> <!-- we don't need this -->
<div class="row">
<div class="col-md-6">
<h5>Nested Heading</h5>
</div>
<div class="col-md-6">
<h4>Heading would be tracked again</h4>
</div>
</div>
</div>
<!-- /toc-ignore -->
<h2>bar</h2>
<h3>bar</h3> |
That is a sensible solution, indeed. But ideally we shouldn't have such comments in the final HTML. I know it's hard because I also tried finding a solution myself :/ If you don't find any solution, no worries, I'll still use this in other projects :) |
I'll continue to see if I can think of a more reliable solution, but I'd think a plug-in that's actually aware of the DOM would be better suited as a solution to this problem. |
Thanks for your time. If you find a clean solution please let me know, otherwise feel free to close this. |
@XhmikosR would a solution like this work for you? Take a look at the Any other possible HTML structures you guys have that I could test against? |
@allejo: huge thanks for trying to sort this! I tried that branch in https://github.com/twbs/bootstrap/tree/v4-dev-xmr-jekyll-toc-alt and while it doesn't include the
|
Yea... Being able to handle and work with the XML is definitely needed or at least would be helpful to support any given structure. What I currently have to work with, is this sample which matches a similar structure to the alerts page. <h2 id="foo">foo</h2>
<h2 id="bar">bar</h2>
<div class="bd-example">
<p>foo</p>
<h4 id="sample-heading">Sample Heading</h4> <!-- we don't need this -->
<div class="row">
<div class="col-md-6">
<h5 id="nested-heading">Nested Heading</h5>
</div>
<div class="col-md-6">
<h4 id="heading-would-be-tracked-again">Heading would be tracked again</h4>
<p>lorem ipsum</p>
</div>
</div>
</div>
<p>sample text</p>
<h2 id="bar2">bar2</h2>
<h3 id="bar3">bar3</h3> ...which gets converted into this: [
'<h2 id="foo">foo</h2>',
'<h2 id="bar">bar</h2><div class="bd-example"><p>foo</p>',
'<h4 id="sample-heading">Sample Heading</h4><!-- we don't need this --><div class="row"><div class="col-md-6">',
'<h5 id="nested-heading">Nested Heading</h5></div><div class="col-md-6">',
'<h4 id="heading-would-be-tracked-again">Heading would be tracked again</h4><p>lorem ipsum</p></div></div></div><p>sample text</p>',
'<h2 id="bar2">bar2</h2>',
'<h3 id="bar3">bar3</h3>'
] I'm open to clever ideas but don't think there's a sane and reliable way of handling this situation. Sorry about that! |
Hi, @allejo.
Thanks for doing this, I was about to do it myself, so it saved me a lot of time. :)
Now, I'm in the process of switching to your solution in Bootstrap.
The only change I made so far is switch the
comment
directive to{%- comment -%}...{%- endcomment -%}
so that we don't get any useless whitespace in the output. And a trivial end-of-file linebreak.The thing that we seem to be missing is the ability to ignore a specific selector or selectors. For example, we need to ignore any header inside
.bd-example
from being added in the TOC.I'll see if I can find a solution myself, but I'm opening this to track the issue.
The text was updated successfully, but these errors were encountered: