Skip to content

Commit

Permalink
Merge pull request #21 from allejo/feature/no-toc-support
Browse files Browse the repository at this point in the history
Add `.no_toc` support
  • Loading branch information
allejo committed Apr 11, 2019
2 parents 8857ac9 + adb8191 commit b70da2b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
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>

0 comments on commit b70da2b

Please # to comment.