Skip to content

Commit

Permalink
Merge pull request #36 from allejo/hotfix/no-toc-first-heading
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo authored May 20, 2020
2 parents d03f24a + 47f865e commit c5850a7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
14 changes: 7 additions & 7 deletions _includes/toc.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% capture tocWorkspace %}
{% comment %}
Version 1.0.11
Version 1.0.12
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 @@ -55,12 +55,6 @@
{% continue %}
{% endif %}

{% if firstHeader %}
{% assign firstHeader = false %}
{% assign minHeader = headerLevel %}
{% endif %}

{% assign indentAmount = headerLevel | minus: minHeader %}
{% assign _workspace = node | split: '</h' %}

{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
Expand All @@ -75,9 +69,15 @@
{% continue %}
{% endif %}

{% if firstHeader %}
{% assign firstHeader = false %}
{% assign minHeader = headerLevel %}
{% endif %}

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

{% assign indentAmount = headerLevel | minus: minHeader %}
{% assign space = '' %}
{% for i in (1..indentAmount) %}
{% assign space = space | prepend: ' ' %}
Expand Down
37 changes: 37 additions & 0 deletions _tests/noTocForFirstHeading copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# See https://github.com/allejo/jekyll-toc/issues/35
---

{% capture markdown %}
## skip me
{: .no_toc}

## skip me also
{: .no_toc}

## skip me, too...
{: .no_toc}

## skip me last
{: .no_toc}

### also skip me as a subheading!
{: .no_toc}

### Subheading A

### Subheading B

### Subheading C
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li><a href="#subheading-a">Subheading A</a></li>
<li><a href="#subheading-b">Subheading B</a></li>
<li><a href="#subheading-c">Subheading C</a></li>
</ul>
25 changes: 25 additions & 0 deletions _tests/noTocForFirstHeading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# See https://github.com/allejo/jekyll-toc/issues/35
---

{% capture markdown %}
## some prominent header i want to hide
{: .no_toc}

### Subheading A

### Subheading B

### Subheading C
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li><a href="#subheading-a">Subheading A</a></li>
<li><a href="#subheading-b">Subheading B</a></li>
<li><a href="#subheading-c">Subheading C</a></li>
</ul>

0 comments on commit c5850a7

Please sign in to comment.