Update allejo/jekyll-toc to v1.0.14
https://github.com/allejo/jekyll-toc/releases/tag/v1.0.14
This commit is contained in:
parent
ab19c77ac9
commit
99a77e4d3a
1 changed files with 95 additions and 21 deletions
|
@ -1,6 +1,30 @@
|
||||||
{% capture tocWorkspace %}
|
{% capture tocWorkspace %}
|
||||||
{% comment %}
|
{% comment %}
|
||||||
Version 1.0.8
|
Copyright (c) 2017 Vladimir "allejo" Jimenez
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person
|
||||||
|
obtaining a copy of this software and associated documentation
|
||||||
|
files (the "Software"), to deal in the Software without
|
||||||
|
restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
{% endcomment %}
|
||||||
|
{% comment %}
|
||||||
|
Version 1.0.14
|
||||||
https://github.com/allejo/jekyll-toc
|
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
|
"...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe
|
||||||
|
@ -19,8 +43,10 @@
|
||||||
* h_max (int) : 6 - the maximum TOC header level to use; any header greater 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
|
* 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
|
* item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level
|
||||||
|
* submenu_class (string) : '' - add custom class(es) for each child group of headings; has support for '%level%' placeholder which is the current "submenu" heading level
|
||||||
* baseurl (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content
|
* 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
|
* anchor_class (string) : '' - add custom class(es) for each anchor element
|
||||||
|
* skipNoIDs (bool) : false - skip headers that do not have an `id` attribute
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
|
An ordered or unordered list representing the table of contents of a markdown block. This snippet will only
|
||||||
|
@ -29,10 +55,12 @@
|
||||||
|
|
||||||
{% capture my_toc %}{% endcapture %}
|
{% capture my_toc %}{% endcapture %}
|
||||||
{% assign orderedList = include.ordered | default: false %}
|
{% assign orderedList = include.ordered | default: false %}
|
||||||
|
{% assign skipNoIDs = include.skipNoIDs | default: false %}
|
||||||
{% assign minHeader = include.h_min | default: 1 %}
|
{% assign minHeader = include.h_min | default: 1 %}
|
||||||
{% assign maxHeader = include.h_max | default: 6 %}
|
{% assign maxHeader = include.h_max | default: 6 %}
|
||||||
{% assign nodes = include.html | split: '<h' %}
|
{% assign nodes = include.html | split: '<h' %}
|
||||||
{% assign firstHeader = true %}
|
{% assign firstHeader = true %}
|
||||||
|
{% assign previousLevel = 0 %}
|
||||||
|
|
||||||
{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}
|
{% capture listModifier %}{% if orderedList %}1.{% else %}-{% endif %}{% endcapture %}
|
||||||
|
|
||||||
|
@ -47,12 +75,6 @@
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if firstHeader %}
|
|
||||||
{% assign firstHeader = false %}
|
|
||||||
{% assign minHeader = headerLevel %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% assign indentAmount = headerLevel | minus: minHeader %}
|
|
||||||
{% assign _workspace = node | split: '</h' %}
|
{% assign _workspace = node | split: '</h' %}
|
||||||
|
|
||||||
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
|
{% assign _idWorkspace = _workspace[0] | split: 'id="' %}
|
||||||
|
@ -67,24 +89,57 @@
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if firstHeader %}
|
||||||
|
{% assign firstHeader = false %}
|
||||||
|
{% assign minHeader = headerLevel %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
|
{% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %}
|
||||||
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
|
{% assign header = _workspace[0] | replace: _hAttrToStrip, '' %}
|
||||||
|
|
||||||
|
{% assign indentAmount = headerLevel | minus: minHeader %}
|
||||||
{% assign space = '' %}
|
{% assign space = '' %}
|
||||||
{% for i in (1..indentAmount) %}
|
{% for i in (1..indentAmount) %}
|
||||||
{% assign space = space | prepend: ' ' %}
|
{% assign space = space | prepend: ' ' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% unless include.item_class == blank %}
|
{% if include.item_class and include.item_class != blank %}
|
||||||
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
|
{% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %}
|
||||||
{% endunless %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% capture anchor_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
|
||||||
|
{% capture anchor_body %}{{ anchor_body | replace: "|", "\|" }}{% endcapture %}
|
||||||
|
|
||||||
|
{% if html_id %}
|
||||||
|
{% capture list_item %}[{{ anchor_body }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% endcapture %}
|
||||||
|
{% elsif skipNoIDs == true %}
|
||||||
|
{% continue %}
|
||||||
|
{% else %}
|
||||||
|
{% capture list_item %}{{ anchor_body }}{% endcapture %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If we have a submenu class and we're unindenting, then we need to add a "closing" class to this group of bullet
|
||||||
|
points
|
||||||
|
-->
|
||||||
|
{% if include.submenu_class and previousLevel > indentAmount %}
|
||||||
|
<!--
|
||||||
|
`space` is the current indentation, so we if want to close off the previous grouping, we need to add one
|
||||||
|
more level of indentation
|
||||||
|
-->
|
||||||
|
{% assign submenuIndentation = space | prepend: ' ' %}
|
||||||
|
|
||||||
{% capture heading_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %}
|
|
||||||
{% capture my_toc %}{{ my_toc }}
|
{% capture my_toc %}{{ my_toc }}
|
||||||
{{ space }}{{ listModifier }} {{ listItemClass }} [{{ heading_body | replace: "|", "\|" }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
|
{{ submenuIndentation }}{:.{{ include.submenu_class | replace: '%level%', previousLevel }}}{% endcapture %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% capture my_toc %}{{ my_toc }}
|
||||||
|
{{ space }}{{ listModifier }} {{ listItemClass }} {{ list_item }}{% if include.anchor_class %}{:.{{ include.anchor_class }}}{% endif %}{% endcapture %}
|
||||||
|
|
||||||
|
{% assign previousLevel = indentAmount %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if include.class %}
|
{% if include.class and include.class != blank %}
|
||||||
{% capture my_toc %}{:.{{ include.class }}}
|
{% capture my_toc %}{:.{{ include.class }}}
|
||||||
{{ my_toc | lstrip }}{% endcapture %}
|
{{ my_toc | lstrip }}{% endcapture %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -93,4 +148,23 @@
|
||||||
{% capture my_toc %}{: #{{ include.id }}}
|
{% capture my_toc %}{: #{{ include.id }}}
|
||||||
{{ my_toc | lstrip }}{% endcapture %}
|
{{ my_toc | lstrip }}{% endcapture %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If we have a submenu class, we need to close off all the remaining list item groups so that submenu classes are
|
||||||
|
applied correctly to them
|
||||||
|
-->
|
||||||
|
{% if include.submenu_class != blank %}
|
||||||
|
<!-- The last level of indentation that we were at, we need to work backwards from there closing each group -->
|
||||||
|
{% for i in (1..previousLevel) %}
|
||||||
|
{% assign lvl = previousLevel | plus: 1 | minus: i %} <!-- Invert the indent level based on `i` -->
|
||||||
|
{% assign closingSpace = '' %}
|
||||||
|
|
||||||
|
{% for i in (1..lvl) %}
|
||||||
|
{% assign closingSpace = closingSpace | prepend: ' ' %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% capture my_toc %}{{ my_toc }}
|
||||||
|
{{ closingSpace }}{:.{{ include.submenu_class | replace: '%level%', lvl }}}{% endcapture %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
|
{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }}
|
||||||
|
|
Loading…
Reference in a new issue