mirror of
https://gh.wpcy.net/https://github.com/TGMPA/TGM-Plugin-Activation.git
synced 2026-07-14 10:56:39 +08:00
Jekyll 3.0 forces switching from Pygments to Rouge for code highlighting. Using the Rouge native linenr feature screws up the layout of our code samples - see screenshots below. This PR fixes that by: * turning off the Rouge line nr feature. * using Liquid to add empty linenr spans at the beginning of each line * using CSS with :before to add the actual line numbers This PR also includes some additional HTML source code compression, getting rid of extraneous new lines caused by Liquid parsing (outside of `<pre>` tags). Both the linenrs as well as the blank line removal can be turned on/off via a configuration feature in `_config.yml`. Additionally, the syntax highlight styling has been synced with the GH native syntax highlight styles. ##### How it used to display  ##### Display after switching to Rouge 
2 lines
No EOL
1.7 KiB
HTML
2 lines
No EOL
1.7 KiB
HTML
{% capture _LINE_FEED %}
|
|
{% endcapture %}{% capture _TAB %} {% endcapture %}{% capture _content %}{{ content }}{% endcapture %}{% assign _pre_befores = _content | split: "<pre" %}{% assign _content = "" %}{% for _pre_before in _pre_befores %}{% assign _pres = _pre_before | split: "</pre>" %}{% assign _pres_after = "" %}{% assign _pre_content = "" %}{% if _pres.size == 2 %}{% if site.compress_html.codelinespans and _pres.first contains ' data-lang=' %}{% assign _lines = _pres.first | split: _LINE_FEED %}{% capture _pre_content %}{% for _line in _lines %}{% if forloop.first %}{{ _line | replace: 'data-lang="php">', 'data-lang="php"><span class="lineno"></span>' }}{{ _LINE_FEED }}{% elsif forloop.last %}{% assign _trimmed = _line | split: _TAB | join: "" | split: " " | join: "" %}{% if _trimmed != empty and trimmed != '</code>' %}<span class="lineno"></span>{% endif %}{{ _line }}{{ _LINE_FEED }}{% else %}<span class="lineno"></span>{{ _line }}{{ _LINE_FEED }}{% endif %}{% endfor %}{% endcapture %}{% endif %}{% endif %}{% if _pres.size != 0 %}{% if site.compress_html.blanklines %}{% assign _lines = _pres.last | split: _LINE_FEED %}{% capture _pres_after %}{% for _line in _lines %}{% assign _trimmed = _line | split: " " | join: " " %}{% if _trimmed != empty or forloop.last %}{% unless forloop.first %}{{ _LINE_FEED }}{% endunless %}{{ _line }}{% endif %}{% endfor %}{% endcapture %}{% else %}{% assign _pres_after = _pres.last | split: " " | join: " " %}{% endif %}{% endif %}{% capture _content %}{{ _content }}{% if _pre_before contains "</pre>" %}<pre{{ _pre_content }}</pre>{% endif %}{% unless _pre_before contains "</pre>" and _pres.size == 1 %}{{ _pres_after }}{% endunless %}{% endcapture %}{% endfor %}{{ _content }} |