diff --git a/CHANGELOG.md b/CHANGELOG.md index 729654b2..b69f4eaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Update Indonesian localized UI text strings. [#2731](https://github.com/mmistakes/minimal-mistakes/pull/2731) - Update remote theme documentation. [#2734](https://github.com/mmistakes/minimal-mistakes/pull/2734) +- Update allejo/jekyll-toc to v1.1.0, skip headings without an ID. [#2752](https://github.com/mmistakes/minimal-mistakes/pull/2752) ## [4.21.0](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.21.0) @@ -17,7 +18,7 @@ - Fix greedy navigation by improving reliability of remaining space for visible links. [#2664](https://github.com/mmistakes/minimal-mistakes/issues/2664) - Collapse white-space in `figure` helper to fix issues when used in Markdown ordered and unordered lists. [#2697](https://github.com/mmistakes/minimal-mistakes/pull/2697) - Fix dead link to CI services in documentation. [#2635](https://github.com/mmistakes/minimal-mistakes/issues/2635) [#2692](https://github.com/mmistakes/minimal-mistakes/pull/2692) -- Fix a small type in documentation. [#2718](https://github.com/mmistakes/minimal-mistakes/pull/2718) +- Fix a small typo in documentation. [#2718](https://github.com/mmistakes/minimal-mistakes/pull/2718) ### Enhancements diff --git a/_includes/toc.html b/_includes/toc.html index e6c1cb4a..8c710072 100644 --- a/_includes/toc.html +++ b/_includes/toc.html @@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE. {% endcomment %} {% comment %} - Version 1.0.14 + Version 1.1.0 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 @@ -44,34 +44,51 @@ * 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 * 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 + * base_url (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 - * skipNoIDs (bool) : false - skip headers that do not have an `id` attribute + * skip_no_ids (bool) : false - skip headers that do not have an `id` attribute 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 {% endcomment %} - {% capture my_toc %}{% endcapture %} + {% capture newline %} + {% endcapture %} + {% assign newline = newline | rstrip %} + + {% capture deprecation_warnings %}{% endcapture %} + + {% if include.baseurl %} + {% capture deprecation_warnings %}{{ deprecation_warnings }}{{ newline }}{% endcapture %} + {% endif %} + + {% if include.skipNoIDs %} + {% capture deprecation_warnings %}{{ deprecation_warnings }}{{ newline }}{% endcapture %} + {% endif %} + + {% capture jekyll_toc %}{% endcapture %} {% assign orderedList = include.ordered | default: false %} - {% assign skipNoIDs = include.skipNoIDs | default: false %} + {% assign baseURL = include.base_url | default: include.baseurl | default: '' %} + {% assign skipNoIDs = include.skip_no_ids | default: include.skipNoIDs | default: false %} {% assign minHeader = include.h_min | default: 1 %} {% assign maxHeader = include.h_max | default: 6 %} - {% assign nodes = include.html | split: ' maxHeader %} + {% if currLevel < minHeader or currLevel > maxHeader %} {% continue %} {% endif %} @@ -79,92 +96,87 @@ {% assign _idWorkspace = _workspace[0] | split: 'id="' %} {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} - {% assign html_id = _idWorkspace[0] %} + {% assign htmlID = _idWorkspace[0] %} {% assign _classWorkspace = _workspace[0] | split: 'class="' %} {% assign _classWorkspace = _classWorkspace[1] | split: '"' %} - {% assign html_class = _classWorkspace[0] %} + {% assign htmlClass = _classWorkspace[0] %} - {% if html_class contains "no_toc" %} + {% if htmlClass contains "no_toc" %} {% continue %} {% endif %} {% if firstHeader %} - {% assign firstHeader = false %} - {% assign minHeader = headerLevel %} + {% assign minHeader = currLevel %} {% endif %} {% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %} {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} - {% assign indentAmount = headerLevel | minus: minHeader %} - {% assign space = '' %} - {% for i in (1..indentAmount) %} - {% assign space = space | prepend: ' ' %} - {% endfor %} - {% if include.item_class and include.item_class != blank %} - {% capture listItemClass %}{:.{{ include.item_class | replace: '%level%', headerLevel }}}{% endcapture %} + {% capture listItemClass %} class="{{ include.item_class | replace: '%level%', currLevel | split: '.' | join: ' ' }}"{% endcapture %} {% endif %} - {% capture anchor_body %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} - {% capture anchor_body %}{{ anchor_body | replace: "|", "\|" }}{% endcapture %} + {% if include.submenu_class and include.submenu_class != blank %} + {% assign subMenuLevel = currLevel | minus: 1 %} + {% capture subMenuClass %} class="{{ include.submenu_class | replace: '%level%', subMenuLevel | split: '.' | join: ' ' }}"{% endcapture %} + {% endif %} - {% if html_id %} - {% capture list_item %}[{{ anchor_body }}]({% if include.baseurl %}{{ include.baseurl }}{% endif %}#{{ html_id }}){% endcapture %} + {% capture anchorBody %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} + + {% if htmlID %} + {% capture anchorAttributes %} href="{% if baseURL %}{{ baseURL }}{% endif %}#{{ htmlID }}"{% endcapture %} + + {% if include.anchor_class %} + {% capture anchorAttributes %}{{ anchorAttributes }} class="{{ include.anchor_class | split: '.' | join: ' ' }}"{% endcapture %} + {% endif %} + + {% capture listItem %}{{ anchorBody }}{% endcapture %} {% elsif skipNoIDs == true %} {% continue %} {% else %} - {% capture list_item %}{{ anchor_body }}{% endcapture %} + {% capture listItem %}{{ anchorBody }}{% endcapture %} {% endif %} - - {% if include.submenu_class and previousLevel > indentAmount %} - - {% assign submenuIndentation = space | prepend: ' ' %} + {% if currLevel > lastLevel %} + {% capture jekyll_toc %}{{ jekyll_toc }}<{{ listModifier }}{{ subMenuClass }}>{% endcapture %} + {% elsif currLevel < lastLevel %} + {% assign repeatCount = lastLevel | minus: currLevel %} - {% capture my_toc %}{{ my_toc }} -{{ 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 %} - - {% if include.class and include.class != blank %} - {% capture my_toc %}{:.{{ include.class }}} -{{ my_toc | lstrip }}{% endcapture %} - {% endif %} - - {% if include.id %} - {% capture my_toc %}{: #{{ include.id }}} -{{ my_toc | lstrip }}{% endcapture %} - {% endif %} - - - {% if include.submenu_class != blank %} - - {% for i in (1..previousLevel) %} - {% assign lvl = previousLevel | plus: 1 | minus: i %} - {% assign closingSpace = '' %} - - {% for i in (1..lvl) %} - {% assign closingSpace = closingSpace | prepend: ' ' %} + {% for i in (1..repeatCount) %} + {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} {% endfor %} - {% capture my_toc %}{{ my_toc }} -{{ closingSpace }}{:.{{ include.submenu_class | replace: '%level%', lvl }}}{% endcapture %} - {% endfor %} + {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} + {% else %} + {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} + {% endif %} + + {% capture jekyll_toc %}{{ jekyll_toc }}{{ listItem }}{% endcapture %} + + {% assign lastLevel = currLevel %} + {% assign firstHeader = false %} + {% endfor %} + + {% assign repeatCount = minHeader | minus: 1 %} + {% assign repeatCount = lastLevel | minus: repeatCount %} + {% for i in (1..repeatCount) %} + {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} + {% endfor %} + + {% if jekyll_toc != '' %} + {% assign rootAttributes = '' %} + {% if include.class and include.class != blank %} + {% capture rootAttributes %} class="{{ include.class | split: '.' | join: ' ' }}"{% endcapture %} + {% endif %} + + {% if include.id and include.id != blank %} + {% capture rootAttributes %}{{ rootAttributes }} id="{{ include.id }}"{% endcapture %} + {% endif %} + + {% if rootAttributes %} + {% assign nodes = jekyll_toc | split: '>' %} + {% capture jekyll_toc %}<{{ listModifier }}{{ rootAttributes }}>{{ nodes | shift | join: '>' }}>{% endcapture %} + {% endif %} {% endif %} -{% endcapture %}{% assign tocWorkspace = '' %}{{ my_toc | markdownify | strip }} +{% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc }} diff --git a/_layouts/single.html b/_layouts/single.html index 71cb4e83..d74002b7 100644 --- a/_layouts/single.html +++ b/_layouts/single.html @@ -36,7 +36,7 @@ layout: default {% endif %} diff --git a/docs/_docs/14-helpers.md b/docs/_docs/14-helpers.md index c80b2858..59ac0171 100644 --- a/docs/_docs/14-helpers.md +++ b/docs/_docs/14-helpers.md @@ -249,7 +249,7 @@ To embed the following Bilibili video at url `https://www.bilibili.com/video/BV1 {% raw %}{% include video id="BV1E7411e7hC" provider="bilibili" %}{% endraw %} ``` -If you want to enable danmaku (弹幕) for the embedded video, which is disabled by default, you can supply an additional parameter `danmaku="1"` as shown below: +If you want to enable danmaku (弹幕) for the embedded video, which is disabled by default, you can supply an additional parameter `danmaku="1"` as shown below: ```liquid {% raw %}{% include video id="BV1E7411e7hC" provider="bilibili" danmaku="1" %}{% endraw %} diff --git a/docs/_docs/18-history.md b/docs/_docs/18-history.md index f0520d51..2e1791ce 100644 --- a/docs/_docs/18-history.md +++ b/docs/_docs/18-history.md @@ -20,6 +20,7 @@ toc: false - Update Indonesian localized UI text strings. [#2731](https://github.com/mmistakes/minimal-mistakes/pull/2731)] - Update remote theme documentation. [#2734](https://github.com/mmistakes/minimal-mistakes/pull/2734) +- Update allejo/jekyll-toc to v1.1.0, skip headings without an ID. [#2752](https://github.com/mmistakes/minimal-mistakes/pull/2752) ## [4.21.0](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.21.0) @@ -28,7 +29,7 @@ toc: false - Fix greedy navigation by improving reliability of remaining space for visible links. [#2664](https://github.com/mmistakes/minimal-mistakes/issues/2664) - Collapse white-space in `figure` helper to fix issues when used in Markdown ordered and unordered lists. [#2697](https://github.com/mmistakes/minimal-mistakes/pull/2697) - Fix dead link to CI services in documentation. [#2635](https://github.com/mmistakes/minimal-mistakes/issues/2635) [#2692](https://github.com/mmistakes/minimal-mistakes/pull/2692) -- Fix a small type in documentation. [#2718](https://github.com/mmistakes/minimal-mistakes/pull/2718) +- Fix a small typo in documentation. [#2718](https://github.com/mmistakes/minimal-mistakes/pull/2718) ### Enhancements