Skip to content

Commit 4ade354

Browse files
committed
Update toc.html
1 parent c37c923 commit 4ade354

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎_includes/toc.html‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
{% assign id_parts = h2_content | split: '"' %}
3030
{% assign heading_id = id_parts[0] %}
3131

32-
{% comment %} Extract the text after the closing anchor tag {% endcomment %}
33-
{% if h2_content contains '</a>' %}
32+
{% comment %} Extract text before a trailing anchor or after a leading anchor {% endcomment %}
33+
{% assign h2_opening = heading_id | append: '">' %}
34+
{% assign h2_before_anchor = h2_content | split: '<a ' | first | remove_first: h2_opening | strip_html | strip %}
35+
{% if h2_before_anchor != "" %}
36+
{% assign heading_text = h2_before_anchor | truncate: 80, "" %}
37+
{% elsif h2_content contains '</a>' %}
3438
{% assign after_anchor_parts = h2_content | split: '</a>' %}
3539
{% assign heading_text = after_anchor_parts[1] | strip_html | strip | truncate: 80, "" %}
3640
{% else %}
@@ -58,7 +62,11 @@
5862
{% assign h3_id_parts = h3_content | split: '"' %}
5963
{% assign h3_id = h3_id_parts[0] %}
6064

61-
{% if h3_content contains '</a>' %}
65+
{% assign h3_opening = h3_id | append: '">' %}
66+
{% assign h3_before_anchor = h3_content | split: '<a ' | first | remove_first: h3_opening | strip_html | strip %}
67+
{% if h3_before_anchor != "" %}
68+
{% assign h3_text = h3_before_anchor | truncate: 60, "" %}
69+
{% elsif h3_content contains '</a>' %}
6270
{% assign h3_after_anchor = h3_content | split: '</a>' %}
6371
{% assign h3_text = h3_after_anchor[1] | strip_html | strip | truncate: 60, "" %}
6472
{% else %}

0 commit comments

Comments
 (0)