2020-08-14 19:35:00 +03:00
|
|
|
<!--
|
|
|
|
Refactor the HTML structure.
|
|
|
|
-->
|
|
|
|
|
|
|
|
{% assign _content = include.content %}
|
|
|
|
|
2020-12-24 19:22:21 +03:00
|
|
|
<!--
|
|
|
|
In order to allow a wide table to scroll horizontally,
|
|
|
|
we suround the markdown table with `<div class="table-wrapper">` and `</div>`
|
|
|
|
-->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2020-08-14 19:35:00 +03:00
|
|
|
{% if _content contains '<table>' %}
|
2020-12-14 10:01:05 +03:00
|
|
|
{% assign _content = _content
|
|
|
|
| replace: '<table>', '<div class="table-wrapper"><table>'
|
|
|
|
| replace: '</table>', '</table></div>'
|
|
|
|
| replace: '</table></div></code>', '</table></code>'
|
|
|
|
%}
|
2020-08-14 19:35:00 +03:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<!--
|
|
|
|
Fixed kramdown code highlight rendering:
|
|
|
|
https://github.com/penibelst/jekyll-compress-html/issues/101
|
|
|
|
https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901
|
|
|
|
-->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2020-08-14 19:35:00 +03:00
|
|
|
{% if _content contains '<pre class="highlight">' %}
|
2020-12-14 10:01:05 +03:00
|
|
|
{% assign _content = _content
|
|
|
|
| replace: '<div class="highlight"><pre class="highlight"><code', '<div class="highlight"><code'
|
|
|
|
| replace: '</code></pre></div>', '</code></div>'
|
|
|
|
%}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<!-- Add attribute 'hide-bullet' to the checkbox list -->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2020-12-14 10:01:05 +03:00
|
|
|
{% if _content contains '<li class="task-list-item"><' %}
|
|
|
|
{% assign _content = _content
|
|
|
|
| replace: '"task-list-item"><', '"task-list-item" hide-bullet><'
|
|
|
|
%}
|
2020-08-14 19:35:00 +03:00
|
|
|
{% endif %}
|
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
|
2021-07-04 15:09:45 +03:00
|
|
|
<!-- images -->
|
|
|
|
|
2021-01-09 17:30:31 +03:00
|
|
|
{% if _content contains '<img src="' %}
|
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
<!-- add CDN prefix if it exists -->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2021-01-09 17:30:31 +03:00
|
|
|
{% if site.img_cdn != '' %}
|
|
|
|
{% assign img_path_replacement = '<img src="' | append: site.img_cdn | append: '/' %}
|
|
|
|
{% else %}
|
|
|
|
{% assign img_path_replacement = '<img src="' | append: site.baseurl | append: '/' %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% assign _content = _content | replace: '<img src="/', img_path_replacement %}
|
|
|
|
|
|
|
|
<!-- lazy-load images <https://github.com/ApoorvSaxena/lozad.js#usage> -->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2021-06-30 15:11:10 +03:00
|
|
|
{% assign _content = _content | replace: '<img src="', '<img data-proofer-ignore data-src="' %}
|
2021-06-30 14:08:42 +03:00
|
|
|
|
|
|
|
<!-- add image placehoder to prevent layout reflow -->
|
|
|
|
|
|
|
|
{% assign _img_content = nil %}
|
|
|
|
|
|
|
|
{% assign _images = _content | split: '<img ' %}
|
|
|
|
|
|
|
|
{% for _img in _images %}
|
|
|
|
{% if forloop.first %}
|
|
|
|
{% assign _img_content = _img %}
|
|
|
|
{% continue %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% assign _width = nil %}
|
|
|
|
{% assign _height = nil %}
|
|
|
|
{% assign _attrs = _img | split: '>' | first | split: ' ' %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
{% for _attr in _attrs %}
|
|
|
|
{% capture _key %}{{ _attr | split: '=' | first }}{% endcapture %}
|
|
|
|
{% capture _value %}{{ _attr | split: '=' | last | replace: '"', '' }}{% endcapture %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
{% case _key %}
|
|
|
|
{% when 'width' %}
|
|
|
|
{% assign _width = _value %}
|
|
|
|
{% when 'height' %}
|
|
|
|
{% assign _height = _value %}
|
|
|
|
{% endcase %}
|
|
|
|
|
|
|
|
{% if _width and _height %}
|
|
|
|
{% capture _svg %}data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 {{_width}} {{_height}}'%3E%3C/svg%3E{% endcapture %}
|
|
|
|
{% assign _img_content = _img_content | append: '<img src="' | append: _svg | append: '" ' | append: _img %}
|
|
|
|
{% break %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% unless _width and _height %}
|
|
|
|
{% assign _img_content = _img_content | append: '<img ' | append: _img %}
|
|
|
|
{% endunless %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% assign _content = _img_content %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
2021-07-04 15:09:45 +03:00
|
|
|
<!-- Add lang-badge for code snippets -->
|
|
|
|
|
|
|
|
{% if _content contains '<div class="language-' %}
|
|
|
|
{% assign _code_splits = _content | split: '<div class="language-' %}
|
|
|
|
{% assign _new_content = nil %}
|
|
|
|
|
|
|
|
{% for _snippet in _code_splits %}
|
|
|
|
{% if forloop.first %}
|
|
|
|
{% assign _new_content = _snippet %}
|
|
|
|
{% else %}
|
|
|
|
{% assign _lang = _snippet | split: ' ' | first %}
|
|
|
|
{% capture _tag_head %}<div lang="{{_lang}}" class="language-{% endcapture %}
|
|
|
|
{% assign _new_content = _new_content | append: _tag_head | append: _snippet %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% if _new_content %}
|
|
|
|
{% assign _content = _new_content %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
|
2020-12-14 10:01:05 +03:00
|
|
|
<!-- return -->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2020-08-14 19:35:00 +03:00
|
|
|
{{ _content }}
|