|
1 | 1 | {% capture tocWorkspace %}
|
2 | 2 | {% comment %}
|
3 |
| - Version 1.0.2 |
| 3 | + Version 1.0.3 |
| 4 | + https://github.com/allejo/jekyll-toc |
4 | 5 |
|
5 | 6 | "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
|
6 | 7 |
|
|
16 | 17 | * id (string) : '' - an ID to assigned to the TOC
|
17 | 18 | * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored
|
18 | 19 | * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored
|
| 20 | + * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list |
19 | 21 |
|
20 | 22 | Output:
|
21 |
| - An unordered list representing the table of contents of a markdown block. This snippet will only generate the table of contents and will NOT output the markdown given to it |
| 23 | + An ordered or unordered list representing the table of contents of a markdown block. This snippet will only generate the table of contents and will NOT output the markdown given to it |
22 | 24 | {% endcomment %}
|
23 | 25 |
|
24 | 26 | {% capture my_toc %}{% endcapture %}
|
| 27 | + {% assign orderedList = include.ordered | default: false %} |
25 | 28 | {% assign minHeader = include.h_min | default: 1 %}
|
26 | 29 | {% assign maxHeader = include.h_max | default: 6 %}
|
27 | 30 | {% assign nodes = include.html | split: '<h' %}
|
28 | 31 | {% assign firstHeader = true %}
|
29 | 32 |
|
| 33 | + {% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %} |
| 34 | + |
30 | 35 | {% for node in nodes %}
|
31 | 36 | {% if node == "" %}
|
32 | 37 | {% continue %}
|
|
55 | 60 |
|
56 | 61 | {% assign space = '' %}
|
57 | 62 | {% for i in (1..indentAmount) %}
|
58 |
| - {% assign space = space | prepend: ' ' %} |
| 63 | + {% assign space = space | prepend: ' ' %} |
59 | 64 | {% endfor %}
|
60 | 65 |
|
61 | 66 | {% capture my_toc %}{{ my_toc }}
|
62 |
| -{{ space }}- [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}](#{{ html_id }}){% endcapture %} |
| 67 | +{{ space }}{{ listModifier }} [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}](#{{ html_id }}){% endcapture %} |
63 | 68 |
|
64 | 69 | {% endfor %}
|
65 | 70 |
|
|
0 commit comments