github.com/googleapis/api-linter@v1.65.2/docs/_includes/toc.html (about) 1 {% comment %} 2 Taken from https://github.com/allejo/jekyll-toc 3 Original file is Copyright © 2017, Vladimir Jimenez 4 (Dual-licensed BSD / MIT) 5 {% endcomment %} 6 {% capture tocWorkspace %} 7 {% comment %} 8 Version 1.0.6 9 https://github.com/allejo/jekyll-toc 10 11 "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe 12 13 Usage: 14 {% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %} 15 16 Parameters: 17 * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll 18 19 Optional Parameters: 20 * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC 21 * class (string) : '' - a CSS class assigned to the TOC 22 * id (string) : '' - an ID to assigned to the TOC 23 * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored 24 * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored 25 * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list 26 * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level 27 * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content 28 * anchor_class (string) : '' - add custom class(es) for each anchor element 29 30 Output: 31 An ordered or unordered list representing the table of contents of a markdown block. This snippet will only 32 generate the table of contents and will NOT output the markdown given to it 33 {% endcomment %} 34 35 {% capture my_toc %}- {:.toc-header} Contents{% endcapture %} 36 {% assign orderedList = include.ordered | default: false %} 37 {% assign minHeader = include.h_min | default: 1 %} 38 {% assign maxHeader = include.h_max | default: 6 %} 39 {% assign nodes = include.html | split: '<h' %} 40 {% assign firstHeader = true %} 41 {% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %} 42 {% for node in nodes %} 43 {% if node == "" %} 44 {% continue %} 45 {% endif %} 46 {% assign headerLevel = node | replace: '"', '' | slice: 0, 1 | times: 1 %} 47 {% if headerLevel < minHeader or headerLevel > maxHeader %} 48 {% continue %} 49 {% endif %} 50 {% if firstHeader %} 51 {% assign firstHeader = false %} 52 {% assign minHeader = headerLevel %} 53 {% endif %} 54 {% assign indentAmount = headerLevel | minus: minHeader | add: 1 %} 55 {% assign _workspace = node | split: '</h' %} 56 {% assign _idWorkspace = _workspace[0] | split: 'id="' %} 57 {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} 58 {% assign html_id = _idWorkspace[0] %} 59 {% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %} 60 {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} 61 {% assign space = '' %} 62 {% for i in (1..indentAmount) %} 63 {% assign space = space | prepend: ' ' %} 64 {% endfor %} 65 {% unless include.item_class == blank %} 66 {% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %} 67 {% endunless %} 68 {% capture my_toc %}{{ my_toc }} 69 {{ space }}{{ listModifier }} {{ listItemClass }} [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %} 70 {% endfor %} 71 {% if include.class %} 72 {% capture my_toc %}{:.{{ include.class }}} 73 {{ my_toc | lstrip }}{% endcapture %} 74 {% endif %} 75 {% if include.id %} 76 {% capture my_toc %}{: #{{ include.id }}} 77 {{ my_toc | lstrip }}{% endcapture %} 78 {% endif %} 79 {% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}