Skip to content

Commit

Permalink
Fix incorrect parsing when headings have attributes
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
allejo committed Nov 3, 2017
1 parent 77dcd64 commit e898565
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
7 changes: 4 additions & 3 deletions _includes/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
{% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
{% assign _workspace = node | split: '</h' %}

{% assign _idWorkspace = _workspace[0] | split: '"' %}
{% assign html_id = _idWorkspace[1] %}
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
{% assign html_id = _idWorkspace[0] %}

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

{% assign space = '' %}
Expand Down
19 changes: 19 additions & 0 deletions _tests/headingWithClasses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# See https://github.com/allejo/jekyll-toc/issues/4
---

{% capture markdown %}
# Miscellaneous features
{: .hide-from-excerpt}

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li><a href="#miscellaneous-features">Miscellaneous features</a></li>
</ul>
16 changes: 16 additions & 0 deletions _tests/headingWithClassesAndTags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---

{% capture markdown %}
# Miscellaneous **features**
{: #custom-heading}
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li><a href="#custom-heading">Miscellaneous <strong>features</strong></a></li>
</ul>
16 changes: 16 additions & 0 deletions _tests/headingWithClassesAndTagsButSanitized.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---

{% capture markdown %}
# Miscellaneous **features**
{: #custom-heading}
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text sanitize=true %}

<!-- /// -->

<ul>
<li><a href="#custom-heading">Miscellaneous features</a></li>
</ul>
16 changes: 16 additions & 0 deletions _tests/headingWithCustomID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---

{% capture markdown %}
# Miscellaneous features
{: #custom-heading}
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text %}

<!-- /// -->

<ul>
<li><a href="#custom-heading">Miscellaneous features</a></li>
</ul>

0 comments on commit e898565

Please sign in to comment.