toshimaru / jekyll-toc

Jekyll plugin which generates a table of contents.
MIT License
340 stars 52 forks source link

JekyllTag: toc #38

Open toshimaru opened 6 years ago

toshimaru commented 6 years ago

Switch from filter to tag.

def toc(html)
> page.content == html
=> true

NOTE

toshimaru commented 5 years ago

issue reported by @XhmikosR. https://github.com/toshimaru/jekyll-toc/pull/82#issuecomment-478687677

Quote:

@toshimaru this breaks a few things, or one of the other 0.12.0 changes.

If you try our v4-dev branch from https://github.com/twbs/bootstrap.git, and switch to jekyll-toc 0.12.0, you see that even with {% toc %} we get no ToC. Also, bd-example isn't skipped anymore, at least for the alerts page I see Well Done in ToC, only this entry.

toshimaru commented 5 years ago

It happens when page content returns wrong HTML(partially markdown content).

> context.registers[:page]['content']
=> "## Examples\n\nAlerts are available for any length of text, as well as an optional dismiss button. For proper styling, use one of the eight **required** contextual classes (e.g., `.alert-success`). For inline dismissal, use the [alerts jQuery plugin](#dismissing).\n\n{% capture example %}\n{% for color in site.data.theme-colors %}\n<div class=\"alert alert-{{ color.name }}\" role=\"alert\">\n  A simple {{ color.name }} alert—check it out!\n</div>{% endfor %}\n{% endcapture %}\n{% include example.html content=example %}\n\n{% include callout-warning-color-assistive-technologies.md %}\n\n### Link color\n\nUse the `.alert-link` utility class to quickly provide matching colored links within any alert.\n\n{% capture example %}\n{% for color in site.data.theme-colors %}\n<div class=\"alert alert-{{ color.name }}\" role=\"alert\">\n  A simple {{ color.name }}
...

not sure why it happens.

Right behavior

Retirning HTML.

 context.registers[:page]['content']
=> "<style type=\"text/css\">\n@-webkit-keyframes anim {\n    0%   { opacity: 0; }\n    100% { opacity: 1; }\n}\n@keyframes anim {\n    0%   { opacity: 0; }\n    100% { opacity: 1; }\n}\n.post-image  {\n  -ms-animation: anim 2s infinite;\n  -webkit-animation: anim 2s infinite;\n  animation: anim 2s infinite;\n}\n</style>\n\n<p><a href=\"http://www.adventar.org/calendars/57\">CSS Property Advent Calendar 2013</a>の11日目の記事としてCSSアニメーションのプロパティを紹介をします。</p>\n\n<h2 id=\"なぜcssアニメーションなのか\">なぜCSSアニメーションなのか?</h2>
...
XhmikosR commented 5 years ago

I think it's a matter of order. With 0.12.0 you are accessing content before it's been processed by Jekyll, thus the example shortcode hasn't run by the time jekyll-toc runs.

toshimaru commented 5 years ago

Yes, it seems so. will look into further why the order changes by a content.

toshimaru commented 5 years ago

Created PR: https://github.com/twbs/bootstrap/pull/28598

XhmikosR commented 5 years ago

Thanks for the PR, but being we only use Jekyll for v4 I think it'd be wiser to just leave it as is. On master we switch to Hugo, I just thought this was a regression that's why I commented :)