{% capture headingsWorkspace %} {% assign minHeader = 2 %} {% assign maxHeader = 6 %} {% assign beforeHeading = 1 %} {% assign nodes = include.html | split: ' {% if headerLevel == 0 %} {% assign firstChunk = node | split: '>' | first %} {% unless firstChunk contains '<' %} {% capture node %}{% 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, '' %} {% capture anchor %}{% endcapture %} {% if html_id and headerLevel >= minHeader and headerLevel <= maxHeader %} {% if include.headerAttrs %} {% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '>' | first }} {{ include.headerAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}>{% endcapture %} {% endif %} {% capture anchor %}href="#{{ html_id }}"{% endcapture %} {% if include.anchorClass %} {% capture anchor %}{{ anchor }} class="{{ include.anchorClass }}"{% endcapture %} {% endif %} {% capture anchor %}{{ anchor }} title="{{ header }}"{% endcapture %} {% if include.anchorAttrs %} {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', header | replace: '%html_id%', html_id }}{% endcapture %} {% endif %} {% capture anchor %}{{ ' ' | replace: '%heading%', header | default: '' }}{% endcapture %} {% if beforeHeading %} {% capture anchor %}{{ anchor }} {% endcapture %} {% else %} {% capture anchor %} {{ anchor }}{% endcapture %} {% endif %} {% endif %} {% capture new_heading %} {% endcapture %} {% assign chunkCount = _workspace | size %} {% if chunkCount > 1 %} {% capture new_heading %}{{ new_heading }}{{ _workspace | last }}{% endcapture %} {% endif %} {% capture edited_headings %}{{ edited_headings }}{{ new_heading }}{% endcapture %} {% endfor %} {% endcapture %}{% assign headingsWorkspace = '' %}{{ edited_headings | strip }}