Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add .no_toc support #21

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion _includes/toc.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% capture tocWorkspace %}
{% comment %}
Version 1.0.6
Version 1.0.7
https://github.com/allejo/jekyll-toc

"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
Expand Down Expand Up @@ -59,6 +59,14 @@
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
{% assign html_id = _idWorkspace[0] %}

{% assign _classWorkspace = _workspace[0] | split: 'class="' %}
{% assign _classWorkspace = _classWorkspace[1] | split: '"' %}
{% assign html_class = _classWorkspace[0] %}

{% if html_class contains "no_toc" %}
{% continue %}
{% endif %}

{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}

Expand Down
31 changes: 31 additions & 0 deletions _tests/noTocClass.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# see https://github.com/allejo/jekyll-toc/issues/15
---

{% capture markdown %}
# Contents header
{:.no_toc}

* A markdown unordered list which will be replaced with the ToC, excluding the "Contents header" from above
{:toc}

# H1 header

## H2 header
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li>
<a href="#h1-header">H1 header</a>
<ul>
<li>
<a href="#h2-header">H2 header</a>
</li>
</ul>
</li>
</ul>
34 changes: 34 additions & 0 deletions _tests/noTocClassMultipleClasses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# If a heading has `no_toc` with other classes, it should still ignore it from
# the TOC
# see https://github.com/allejo/jekyll-toc/issues/15
---

{% capture markdown %}
# Contents header
{:.no_toc.another-class}

* A markdown unordered list which will be replaced with the ToC, excluding the "Contents header" from above
{:toc}

# H1 header
{:.custom-class}

## H2 header
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li>
<a href="#h1-header">H1 header</a>
<ul>
<li>
<a href="#h2-header">H2 header</a>
</li>
</ul>
</li>
</ul>