diff --git a/_includes/vendor/anchor_headings.html b/_includes/vendor/anchor_headings.html index e9ca862..36b8470 100755 --- a/_includes/vendor/anchor_headings.html +++ b/_includes/vendor/anchor_headings.html @@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE. {% endcomment %} {% comment %} - Version 1.0.7 + Version 1.0.12 https://github.com/allejo/jekyll-anchor-headings "Be the pull request you wish to see in the world." ~Ben Balter @@ -37,6 +37,8 @@ Optional Parameters: * beforeHeading (bool) : false - Set to true if the anchor should be placed _before_ the heading's content + * headerAttrs (string) : '' - Any custom HTML attributes that will be added to the heading tag; you may NOT use `id`; + the `%heading%` and `%html_id%` placeholders are available * anchorAttrs (string) : '' - Any custom HTML attributes that will be added to the `` tag; you may NOT use `href`, `class` or `title`; the `%heading%` and `%html_id%` placeholders are available * anchorBody (string) : '' - The content that will be placed inside the anchor; the `%heading%` placeholder is available @@ -46,6 +48,7 @@ * h_max (int) : 6 - The maximum header level to build an anchor for; any header greater than this value will be ignored * bodyPrefix (string) : '' - Anything that should be inserted inside of the heading tag _before_ its anchor and content * bodySuffix (string) : '' - Anything that should be inserted inside of the heading tag _after_ its anchor and content + * generateId (true) : false - Set to true if a header without id should generate an id to use. Output: The original HTML with the addition of anchors inside of all of the h1-h6 headings. @@ -54,6 +57,7 @@ {% assign minHeader = include.h_min | default: 1 %} {% assign maxHeader = include.h_max | default: 6 %} {% assign beforeHeading = include.beforeHeading %} + {% assign headerAttrs = include.headerAttrs %} {% assign nodes = include.html | split: '{% endcapture %} {% assign _workspace = node | split: _closingTag %} - {% assign _idWorkspace = _workspace[0] | split: 'id="' %} - {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} - {% assign html_id = _idWorkspace[0] %} - {% capture _hAttrToStrip %}{{ _workspace[0] | split: '>' | first }}>{% endcapture %} {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} + {% assign escaped_header = header | strip_html | strip %} + + {% assign _classWorkspace = _workspace[0] | split: 'class="' %} + {% assign _classWorkspace = _classWorkspace[1] | split: '"' %} + {% assign _html_class = _classWorkspace[0] %} + + {% if _html_class contains "no_anchor" %} + {% assign skip_anchor = true %} + {% else %} + {% assign skip_anchor = false %} + {% endif %} + + {% assign _idWorkspace = _workspace[0] | split: 'id="' %} + {% if _idWorkspace[1] %} + {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} + {% assign html_id = _idWorkspace[0] %} + {% elsif include.generateId %} + + {% assign html_id = escaped_header | slugify %} + {% if html_id == "" %} + {% assign html_id = false %} + {% endif %} + {% capture headerAttrs %}{{ headerAttrs }} id="%html_id%"{% endcapture %} + {% endif %} {% capture anchor %}{% endcapture %} - {% if html_id and headerLevel >= minHeader and headerLevel <= maxHeader %} + {% if skip_anchor == false and html_id and headerLevel >= minHeader and headerLevel <= maxHeader %} + {% if headerAttrs %} + {% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ headerAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}>{% endcapture %} + {% endif %} + {% capture anchor %}href="#{{ html_id }}"{% endcapture %} {% if include.anchorClass %} @@ -102,14 +130,14 @@ {% endif %} {% if include.anchorTitle %} - {% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', header }}"{% endcapture %} + {% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', escaped_header }}"{% endcapture %} {% endif %} {% if include.anchorAttrs %} - {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}{% endcapture %} + {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', escaped_header | replace: '%html_id%', html_id }}{% endcapture %} {% endif %} - {% capture anchor %}{{ include.anchorBody | replace: '%heading%', header | default: '' }}{% endcapture %} + {% capture anchor %}{{ include.anchorBody | replace: '%heading%', escaped_header | default: '' }}{% endcapture %} {% if beforeHeading %} @@ -120,15 +148,15 @@ {% endif %} {% capture new_heading %} - + {% endcapture %}