Skip to content

Commit 60262a6

Browse files
authored
Merge pull request #3834 from vespa-engine/vadim/toc-comments-parsing-fix
Excluding commented section's headings from TOC
2 parents 26291b8 + 8fe062c commit 60262a6

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

_includes/toc.html

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
<!-- Copyright Vespa.ai. All rights reserved. -->
22
{% assign h2_count = content | split: '<h' | size | minus: 1 %}
33
{% if h2_count > 4 %}
4-
4+
55

66
<nav class="toc {% if page.title == 'FAQ - frequently asked questions'%} faq-toc {% endif %}" aria-labelledby="on-this-page-heading" style="position: fixed; align-self: flex-start;">
77
<h3 id="on-this-page-heading" style="pointer-events: none;">On this page:</h3>
88
{% assign headings = content | split: '<' %}
99

1010
<ul>
1111
{% for tag in headings %}
12-
{% assign tag_slice = tag | slice: 0, 1%}
13-
{% if tag_slice == '/' %}
12+
{% assign trimmed_tag = tag | strip %}
13+
{% assign tag_slice = trimmed_tag | slice: 0, 3 %}
14+
15+
<!-- skip if parser is inside of comment tag -->
16+
{% if tag_slice == '!--' %}
17+
{% assign skip = true %}
18+
{% endif %}
19+
<!-- stop skiping if parser reached comment tag end -->
20+
{% if tag contains '-->' %}
21+
{% assign skip = false %}
1422
{% continue %}
15-
{% else %}
23+
{% endif %}
24+
25+
{% if skip %}
26+
{% continue %}
27+
{% endif %}
28+
29+
30+
{% assign first_char = trimmed_tag | slice: 0, 1 %}
31+
{% if first_char == '/' %}
32+
{% continue %}
33+
{% endif %}
34+
1635
{% assign tag_start = tag | slice: 0, 3 %}
1736
{% if tag_start == 'h1 ' or tag_start == 'h2 ' or tag_start == 'h3 ' or tag_start == 'h1>' or tag_start == 'h2>' or tag_start == 'h3>' %}
1837
{% assign toc_level = tag | slice: 1, 2%}
@@ -26,13 +45,11 @@ <h3 id="on-this-page-heading" style="pointer-events: none;">On this page:</h3>
2645
<li class="toc-level-{{toc_level | minus: 1 }}">
2746
<a href="#{{ heading_id }}">{{ heading_text }}</a>
2847
</li>
29-
{% endif %}
30-
{% endif %}
48+
{% endif %}
3149
{% endif %}
3250
{% endfor %}
3351

3452
</ul>
3553
</div>
3654

37-
{% endif %}
38-
55+
{% endif %}

0 commit comments

Comments
 (0)