Created
July 18, 2018 18:05
-
-
Save letrastudio/8a59e12f65f1ffa78f0e699c0bc3d155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% assign heading_level = "2" %} | |
{% assign opening_tag = "<h" | append: heading_level %} | |
{% assign closing_tag = "</h" | append: heading_level | append: ">" %} | |
{% assign toc = content | split: opening_tag %} | |
<nav class="page-toc"> | |
<ol> | |
{% for item in toc %} | |
{% if item contains closing_tag %} | |
{% assign tag = item | split: closing_tag | first | strip %} | |
{% assign attrs = tag | split: ">" | first | strip %} | |
{% assign id = attrs | split: "id=" | last | split: " " | first | remove: "'" | remove: '"' | strip %} | |
{% assign title = tag | split: ">" | last | strip %} | |
<li><a href="#{{ id }}">{{ title }}</a></li> | |
{% endif %} | |
{% endfor %} | |
</ol> | |
</nav> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment