yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4f83d48b2
master
1{% capture headingsWorkspace %} 2{% comment %} 3Copyright (c) 2018 Vladimir "allejo" Jimenez 4 5Permission is hereby granted, free of charge, to any person 6obtaining a copy of this software and associated documentation 7files (the "Software"), to deal in the Software without 8restriction, including without limitation the rights to use, 9copy, modify, merge, publish, distribute, sublicense, and/or sell 10copies of the Software, and to permit persons to whom the 11Software is furnished to do so, subject to the following 12conditions: 13 14The above copyright notice and this permission notice shall be 15included in all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24OTHER DEALINGS IN THE SOFTWARE. 25{% endcomment %} 26{% comment %} 27Version 1.0.9 28https://github.com/allejo/jekyll-anchor-headings 29 30"Be the pull request you wish to see in the world." ~Ben Balter 31 32Usage: 33{% include anchor_headings.html html=content anchorBody="#" %} 34 35Parameters: 36* html (string) - the HTML of compiled markdown generated by kramdown in Jekyll 37 38Optional Parameters: 39* beforeHeading (bool) : false - Set to true if the anchor should be placed _before_ the heading's content 40* headerAttrs (string) : '' - Any custom HTML attributes that will be added to the heading tag; you may NOT use `id`; 41the `%heading%` and `%html_id%` placeholders are available 42* anchorAttrs (string) : '' - Any custom HTML attributes that will be added to the `< a > ` tag; you may NOT use `href`, 43 `class` or `title`; 44 the `%heading%` and `%html_id%` placeholders are available 45 * anchorBody (string) : '' - The content that will be placed inside the anchor; the `%heading%` placeholder is 46 available 47 * anchorClass (string) : '' - The class(es) that will be used for each anchor. Separate multiple classes with a 48 space 49 * anchorTitle (string) : '' - The `title` attribute that will be used for anchors 50 * h_min (int) : 1 - The minimum header level to build an anchor for; any header lower than this value will be 51 ignored 52 * h_max (int) : 6 - The maximum header level to build an anchor for; any header greater than this value will be 53 ignored 54 * bodyPrefix (string) : '' - Anything that should be inserted inside of the heading tag _before_ its anchor and 55 content 56 * bodySuffix (string) : '' - Anything that should be inserted inside of the heading tag _after_ its anchor and 57 content 58 59 Output: 60 The original HTML with the addition of anchors inside of all of the h1-h6 headings. 61 {% endcomment %} 62 63 {% assign minHeader = include.h_min | default: 1 %} 64 {% assign maxHeader = include.h_max | default: 2 %} 65 {% assign beforeHeading = include.beforeHeading %} 66 {% assign nodes = include.html | split: '< h ' %} {% capture edited_headings %}{% endcapture %} {% for _node in nodes 67 %} {% capture node %}{{ _node | strip }}{% endcapture %} {% if node=="" %} {% continue %} {% endif %} {% assign 68 nextChar=node | replace: '"' , '' | strip | slice: 0, 1 %} {% assign headerLevel=nextChar | times: 1 %}<!-- If 69the level is cast to 0, it means it's not a h1-h6 tag, so let's see if we need to fix it --> 70 {% if headerLevel == 0 %} 71<!-- Split up the node based on closing angle brackets and get the first one. --> 72 {% assign firstChunk = node | split: '> ' | first %} 73 74<!-- If the first chunk does NOT contain a '<', that means we've broken another HTML tag that starts with 'h' --> 75 {% unless firstChunk contains '< ' %} {% capture node %}< h{{ node }}{% endcapture %} {% endunless %} {% capture 76 edited_headings %}{{ edited_headings }}{{ node }}{% endcapture %} {% continue %} {% endif %} {% capture 77 _closingTag %}</ h{{ headerLevel }}> {% endcapture %} 78 {% assign _workspace = node | split: _closingTag %} 79 {% assign _idWorkspace = _workspace[0] | split: 'id="' %} 80 {% assign _idWorkspace = _idWorkspace[1] | split: '"' %} 81 {% assign html_id = _idWorkspace[0] %} 82 83 {% capture _hAttrToStrip %}{{ _workspace[0] | split: '> ' | first }}> {% endcapture %} 84 {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} 85 86<!-- Build the anchor to inject for our heading --> 87 {% capture anchor %}{% endcapture %} 88 89 {% if html_id and headerLevel> = minHeader and headerLevel< = maxHeader %} {% assign escaped_header=header | 90 strip_html %} {% if include.headerAttrs %} {% capture _hAttrToStrip %}{{ _hAttrToStrip | split: '> ' | 91 first }} {{ include.headerAttrs | replace: '%heading%' , escaped_header | replace: '%html_id%' , html_id 92 }}> {% endcapture %} 93 {% endif %} 94 95 {% capture anchor %}href="#{{ html_id }}"{% endcapture %} 96 97 {% if include.anchorClass %} 98 {% capture anchor %}{{ anchor }} class="{{ include.anchorClass }}"{% endcapture %} 99 {% endif %} 100 101 {% if include.anchorTitle %} 102 {% capture anchor %}{{ anchor }} title="{{ include.anchorTitle | replace: '%heading%', escaped_header 103 }}"{% endcapture %} 104 {% endif %} 105 106 {% if include.anchorAttrs %} 107 {% capture anchor %}{{ anchor }} {{ include.anchorAttrs | replace: '%heading%', escaped_header | 108 replace: '%html_id%', html_id }}{% endcapture %} 109 {% endif %} 110 111 {% capture anchor %}< a {{ anchor }}> {{ include.anchorBody | replace: '%heading%', escaped_header | 112 default: '' }}</ a> {% endcapture %} 113 114<!-- In order to prevent adding extra space after a heading, we'll let the 'anchor' value contain it --> 115 {% if beforeHeading %} 116 {% capture anchor %}{{ anchor }} {% endcapture %} 117 {% else %} 118 {% capture anchor %} {{ anchor }}{% endcapture %} 119 {% endif %} 120 {% endif %} 121 122 {% capture new_heading %} 123< h{{ _hAttrToStrip }} {{ include.bodyPrefix }} {% if beforeHeading %} {{ anchor }}{{ header }} {% else 124 %} {{ header }}{{ anchor }} {% endif %} {{ include.bodySuffix }}</ h{{ headerLevel }}> 125 {% endcapture %} 126 127<!-- 128If we have content after the `</hX>` tag, then we'll want to append that here so we don't lost any content. 129--> 130 {% assign chunkCount = _workspace | size %} 131 {% if chunkCount> 1 %} 132 {% capture new_heading %}{{ new_heading }}{{ _workspace | last }}{% endcapture %} 133 {% endif %} 134 135 {% capture edited_headings %}{{ edited_headings }}{{ new_heading }}{% endcapture %} 136 {% endfor %} 137 {% endcapture %}{% assign headingsWorkspace = '' %}{{ edited_headings | strip }}