Skip to content

Commit e898565

Browse files
committed
Fix incorrect parsing when headings have attributes
Closes #4
1 parent 77dcd64 commit e898565

5 files changed

+71
-3
lines changed

_includes/toc.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@
4444
{% assign indentAmount = headerLevel | minus: minHeader | add: 1 %}
4545
{% assign _workspace = node | split: '</h' %}
4646

47-
{% assign _idWorkspace = _workspace[0] | split: '"' %}
48-
{% assign html_id = _idWorkspace[1] %}
47+
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
48+
{% assign _idWorkspace = _idWorkspace[1] | split: '"' %}
49+
{% assign html_id = _idWorkspace[0] %}
4950

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

5354
{% assign space = '' %}

_tests/headingWithClasses.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
# See https://github.com/allejo/jekyll-toc/issues/4
3+
---
4+
5+
{% capture markdown %}
6+
# Miscellaneous features
7+
{: .hide-from-excerpt}
8+
9+
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
10+
{% endcapture %}
11+
{% assign text = markdown | markdownify %}
12+
13+
{% include toc.html html=text %}
14+
15+
<!-- /// -->
16+
17+
<ul>
18+
<li><a href="#miscellaneous-features">Miscellaneous features</a></li>
19+
</ul>

_tests/headingWithClassesAndTags.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
{% capture markdown %}
5+
# Miscellaneous **features**
6+
{: #custom-heading}
7+
{% endcapture %}
8+
{% assign text = markdown | markdownify %}
9+
10+
{% include toc.html html=text %}
11+
12+
<!-- /// -->
13+
14+
<ul>
15+
<li><a href="#custom-heading">Miscellaneous <strong>features</strong></a></li>
16+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
{% capture markdown %}
5+
# Miscellaneous **features**
6+
{: #custom-heading}
7+
{% endcapture %}
8+
{% assign text = markdown | markdownify %}
9+
10+
{% include toc.html html=text sanitize=true %}
11+
12+
<!-- /// -->
13+
14+
<ul>
15+
<li><a href="#custom-heading">Miscellaneous features</a></li>
16+
</ul>

_tests/headingWithCustomID.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
{% capture markdown %}
5+
# Miscellaneous features
6+
{: #custom-heading}
7+
{% endcapture %}
8+
{% assign text = markdown | markdownify %}
9+
10+
{% include toc.html html=text %}
11+
12+
<!-- /// -->
13+
14+
<ul>
15+
<li><a href="#custom-heading">Miscellaneous features</a></li>
16+
</ul>

0 commit comments

Comments
 (0)