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-07-04 15:09:45 +03:00
|
|
|
<!-- images -->
|
|
|
|
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign IMG_TAG = '<img ' %}
|
2021-06-30 14:08:42 +03:00
|
|
|
|
2021-12-14 18:28:15 +03:00
|
|
|
{% if _content contains IMG_TAG %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% assign _img_content = nil %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign _img_snippets = _content | split: IMG_TAG %}
|
2021-06-30 14:08:42 +03:00
|
|
|
|
2021-12-14 18:28:15 +03:00
|
|
|
{% for _img_snippet in _img_snippets %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% if forloop.first %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign _img_content = _img_snippet %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% continue %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% assign _width = nil %}
|
|
|
|
{% assign _height = nil %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign _src = nil %}
|
|
|
|
|
2022-01-04 19:53:16 +03:00
|
|
|
{% assign _left = _img_snippet | split: '>' | first %}
|
|
|
|
{% assign _right = _img_snippet | remove: _left %}
|
2021-12-11 19:38:49 +03:00
|
|
|
|
2022-01-04 19:53:16 +03:00
|
|
|
{% assign _left = _left | remove: ' /' %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign _left = _left | replace: ' w=', ' width=' | replace: ' h=', ' height=' %}
|
|
|
|
{% assign _attrs = _left | split: ' ' %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
{% for _attr in _attrs %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% assign _pair = _attr | split: '=' %}
|
|
|
|
{% if _pair.size < 2 %}
|
|
|
|
{% continue %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% capture _key %}{{ _pair | first }}{% endcapture %}
|
|
|
|
{% capture _value %}{{ _pair | last | replace: '"', '' }}{% endcapture %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
2021-06-30 14:08:42 +03:00
|
|
|
{% case _key %}
|
2021-12-11 19:38:49 +03:00
|
|
|
{% when 'width' %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% assign _width = _value %}
|
2021-12-11 19:38:49 +03:00
|
|
|
{% when 'height' %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% assign _height = _value %}
|
2021-12-14 18:28:15 +03:00
|
|
|
{% when 'src' %}
|
|
|
|
{% assign _src = _value %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% endcase %}
|
|
|
|
|
2021-12-14 18:28:15 +03:00
|
|
|
{% if _width and _height and _src %}
|
2021-06-30 14:08:42 +03:00
|
|
|
{% break %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
2021-12-14 18:28:15 +03:00
|
|
|
{% if _src %}
|
|
|
|
{% unless _src contains '://' %}
|
|
|
|
|
|
|
|
<!-- Add CDN URL -->
|
|
|
|
{% if site.img_cdn %}
|
|
|
|
{% assign _src_prefix = site.img_cdn %}
|
|
|
|
{% else %}
|
|
|
|
{% assign _src_prefix = site.baseurl %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<!-- Add image path -->
|
|
|
|
{% if page.img_path %}
|
|
|
|
{% assign _path = page.img_path %}
|
|
|
|
{% assign last_char = _path | slice: -1 %}
|
|
|
|
|
|
|
|
{% unless last_char == '/' %}
|
|
|
|
{% assign _path = _path | append: '/' %}
|
|
|
|
{% endunless %}
|
|
|
|
|
|
|
|
{% assign _src_prefix = _src_prefix | append: _path %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% assign _final_src = _src_prefix | append: _src %}
|
|
|
|
{% assign _left = _left | replace: _src, _final_src %}
|
|
|
|
|
|
|
|
{% endunless %}
|
|
|
|
|
|
|
|
<!-- lazy-load images <https://github.com/ApoorvSaxena/lozad.js#usage> -->
|
|
|
|
|
|
|
|
{% assign _left = _left | replace: 'src=', 'data-src=' %}
|
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<!-- Add SVG placehoder to prevent layout reflow -->
|
|
|
|
|
|
|
|
{% if _width and _height %}
|
|
|
|
{%- capture _svg -%}
|
|
|
|
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 {{ _width }} {{ _height }}'%3E%3C/svg%3E"
|
|
|
|
{%- endcapture -%}
|
|
|
|
|
|
|
|
{% assign _left = _svg | append: ' ' | append: _left %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
<!-- Bypass the HTML-proofer test -->
|
|
|
|
{% assign _left = _left | append: ' data-proofer-ignore' %}
|
|
|
|
|
|
|
|
{% assign _img_content = _img_content | append: IMG_TAG | append: _left | append: _right %}
|
2021-06-30 14:08:42 +03:00
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% assign _content = _img_content %}
|
2021-01-09 17:30:31 +03:00
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
2021-09-09 17:09:07 +03:00
|
|
|
<!-- Add header for code snippets -->
|
2021-07-04 15:09:45 +03:00
|
|
|
|
2021-09-15 17:50:28 +03:00
|
|
|
{% if _content contains '<div class="highlight"><code>' %}
|
|
|
|
{% assign _code_spippets = _content | split: '<div class="highlight"><code>' %}
|
|
|
|
{% assign _new_content = '' %}
|
|
|
|
|
|
|
|
{% for _snippet in _code_spippets %}
|
|
|
|
|
|
|
|
{% if forloop.last %}
|
|
|
|
{% assign _new_content = _new_content | append: _snippet %}
|
2021-07-04 15:09:45 +03:00
|
|
|
|
|
|
|
{% else %}
|
2021-09-15 17:50:28 +03:00
|
|
|
|
|
|
|
{% assign _left = _snippet | split: '><' | last%}
|
|
|
|
|
|
|
|
{% if _left contains 'file="' %}
|
2021-12-03 11:34:26 +03:00
|
|
|
{% assign _label_text = _left | split: 'file="' | last | split: '"' | first %}
|
2021-09-22 16:27:15 +03:00
|
|
|
{% assign _label_icon = 'far fa-file-code' %}
|
2021-09-15 17:50:28 +03:00
|
|
|
{% else %}
|
2021-09-22 16:20:30 +03:00
|
|
|
{% assign _lang = _left | split: 'language-' | last | split: ' ' | first %}
|
2021-12-03 11:34:26 +03:00
|
|
|
{% capture _label_text %}{% include language-alias.html language=_lang %}{% endcapture %}
|
2021-09-22 13:25:46 +03:00
|
|
|
{% assign _label_icon = 'fas fa-code small' %}
|
2021-09-15 17:50:28 +03:00
|
|
|
{% endif %}
|
|
|
|
|
2021-09-22 13:25:46 +03:00
|
|
|
{% capture _label %}
|
2021-12-03 11:34:26 +03:00
|
|
|
<span label-text="{{ _label_text | strip }}"><i class="{{ _label_icon }}"></i></span>
|
2021-09-22 13:25:46 +03:00
|
|
|
{% endcapture %}
|
|
|
|
|
2021-09-15 17:50:28 +03:00
|
|
|
{% assign _new_content = _new_content | append: _snippet
|
2021-09-22 13:25:46 +03:00
|
|
|
| append: '<div class="code-header">'
|
|
|
|
| append: _label
|
2021-09-22 17:21:33 +03:00
|
|
|
| append: '<button aria-label="copy" title-succeed="'
|
2021-09-16 10:38:59 +03:00
|
|
|
| append: site.data.locales[lang].post.button.copy_code.succeed
|
2021-09-22 16:27:15 +03:00
|
|
|
| append: '"><i class="far fa-clipboard"></i></button></div>'
|
2021-09-15 17:50:28 +03:00
|
|
|
| append: '<div class="highlight"><code>'
|
2021-09-09 16:07:07 +03:00
|
|
|
%}
|
2021-09-15 17:50:28 +03:00
|
|
|
|
2021-07-04 15:09:45 +03:00
|
|
|
{% endif %}
|
2021-09-15 17:50:28 +03:00
|
|
|
|
2021-07-04 15:09:45 +03:00
|
|
|
{% endfor %}
|
|
|
|
|
2021-09-15 17:50:28 +03:00
|
|
|
{% assign _content = _new_content %}
|
2021-07-04 15:09:45 +03:00
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
|
2021-12-05 21:19:23 +03:00
|
|
|
<!-- Create heading anchors -->
|
|
|
|
|
|
|
|
{% assign heading_levels = '2,3,4,5' | split: ',' %}
|
|
|
|
{% assign _heading_content = _content %}
|
|
|
|
|
|
|
|
{% for level in heading_levels %}
|
|
|
|
{% capture mark_start %}<h{{ level }} id="{% endcapture %}
|
|
|
|
{% capture mark_end %}</h{{ level }}>{% endcapture %}
|
|
|
|
|
|
|
|
{% if _heading_content contains mark_start %}
|
|
|
|
{% assign _new_content = nil %}
|
|
|
|
{% assign heading_snippets = _heading_content | split: mark_start %}
|
|
|
|
|
|
|
|
{% for snippet in heading_snippets %}
|
|
|
|
{% if forloop.first %}
|
|
|
|
{% assign _new_content = snippet %}
|
|
|
|
{% continue %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% assign id = snippet | split: '"' | first %}
|
2021-12-30 10:57:02 +03:00
|
|
|
{% capture anchor %}<a href="#{{ id }}" class="anchor"><i class="fas fa-hashtag"></i></a>{% endcapture %}
|
2021-12-05 21:19:23 +03:00
|
|
|
|
|
|
|
{% assign left = snippet | split: mark_end | first %}
|
|
|
|
{% assign right = snippet | replace: left, '' %}
|
|
|
|
|
|
|
|
{% assign _new_content = _new_content | append: mark_start
|
|
|
|
| append: left | append: anchor | append: mark_end | append: right
|
|
|
|
%}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% assign _heading_content = _new_content %}
|
|
|
|
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% assign _content = _heading_content %}
|
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 }}
|