From df37bf46ff06d10adb8dd1ad451d2f9d5408ad64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?iBug=20=E2=99=A6?= Date: Wed, 8 Jan 2020 01:36:05 +0800 Subject: [PATCH] Update toc.html from allejo/jekyll-toc:master (#2355) --- _includes/toc.html | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/_includes/toc.html b/_includes/toc.html index 54ab8b03da40..25b9f6a382b0 100644 --- a/_includes/toc.html +++ b/_includes/toc.html @@ -1,6 +1,6 @@ {% capture tocWorkspace %} {% comment %} - Version 1.0.5 + Version 1.0.8 https://github.com/allejo/jekyll-toc "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe @@ -9,20 +9,22 @@ {% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %} Parameters: - * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll + * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll Optional Parameters: - * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC - * class (string) : '' - a CSS class assigned to the TOC - * id (string) : '' - an ID to assigned to the TOC - * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored - * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored - * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list - * item_class (string) : '' - add custom class for each list item; has support for '%level%' placeholder, which is the current heading level - * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content + * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC + * class (string) : '' - a CSS class assigned to the TOC + * id (string) : '' - an ID to assigned to the TOC + * h_min (int) : 1 - the minimum TOC header level to use; any header lower than this value will be ignored + * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored + * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list + * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level + * baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content + * anchor_class (string) : '' - add custom class(es) for each anchor element Output: - 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 + 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 {% endcomment %} {% capture my_toc %}{% endcapture %} @@ -50,13 +52,21 @@ {% assign minHeader = headerLevel %} {% endif %} - {% assign indentAmount = headerLevel | minus: minHeader | add: 1 %} + {% assign indentAmount = headerLevel | minus: minHeader %} {% assign _workspace = node | split: '' | first }}>{% endcapture %} {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} @@ -69,8 +79,9 @@ {% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %} {% endunless %} + {% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} {% capture my_toc %}{{ my_toc }} -{{ space }}{{ listModifier }} {{ listItemClass }} [{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% endcapture %} +{{ space }}{{ listModifier }} {{ listItemClass }} [{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %} {% endfor %} {% if include.class %} @@ -82,4 +93,4 @@ {% capture my_toc %}{: #{{ include.id }}} {{ my_toc | lstrip }}{% endcapture %} {% endif %} -{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }} \ No newline at end of file +{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}