Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display of code samples which got wonky with the switch from Pygm…
…ents to Rouge. 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 ![screenshot Pygments](http://snag.gy/GSRNu.jpg) ##### Display after switching to Rouge ![screenshot Rouge](http://snag.gy/bX0BD.jpg)
- Loading branch information
Showing
15 changed files
with
215 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% 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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{% 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 = "" %} | ||
|
||
|
||
{% comment %}Add line nr spans within <pre> tags{% endcomment %} | ||
|
||
{% 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 %} | ||
|
||
|
||
{% comment %}Remove superfluous blank lines outside of <pre> tags{% endcomment %} | ||
|
||
{% 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 %} | ||
|
||
{% comment %}Output{% endcomment %} | ||
|
||
{{ _content }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
--- | ||
layout: compress | ||
--- | ||
<!doctype html> | ||
<html lang="en"> | ||
{% include header.html %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
--- | ||
layout: compress | ||
--- | ||
<!doctype html> | ||
<html lang="en"> | ||
{% include header.html %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
--- | ||
layout: compress | ||
--- | ||
<!doctype html> | ||
<html lang="en"> | ||
{% include header.html %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.