-
Notifications
You must be signed in to change notification settings - Fork 3
/
code.html
37 lines (37 loc) · 1.81 KB
/
code.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{% comment %}
Převedení '```' zápisu na \{\% highlight \%\} (aby šlo kontrolovat v markdown prohlížeči) + vylepšení
Pouziti: `include code.html code={string} [caption={string|markdown}]`
- `code`: GitHub code started and ended with new line
- `caption`: popisek (jeden paragraf)
{% endcomment
%}{% assign new_line= "
"
%}{% assign pre_code= include.code | split: new_line
%}{% assign lines= pre_code | size
%}{% comment %}V nasledujicim cyklus preskoci "```" casti{% endcomment
%}{% capture code %}{% for line in pre_code %}{% if forloop.index > 2 and forloop.index < lines %}{{ line | append: new_line }}{% endif %}{% endfor %}{% endcapture
%}{% capture post_code
%}{% assign type= pre_code[1] | replace: "```", "" | replace: "JavaScript", "JS" | replace: "js", "JS" | replace: "bash", "console"
%}{% if type == "JS"
%}{% highlight js linenos %}{{code}}{% endhighlight
%}{% elsif type == "PHP"
%}{% highlight php linenos %}{{code}}{% endhighlight
%}{% elsif type == "JSON"
%}{% highlight json linenos %}{{code}}{% endhighlight
%}{% elsif type == "CSS"
%}{% highlight css linenos %}{{code}}{% endhighlight
%}{% elsif type == "HTML"
%}{% highlight html linenos %}{{code}}{% endhighlight
%}{% elsif type == "console"
%}{% highlight console %}{{code}}{% endhighlight
%}{% else
%}{% highlight text %}{{code}}{% endhighlight
%}{% endif
%}{% endcapture
%}{% assign caption= ""
%}{% if include.caption
%}{% capture caption %}<figcaption class="info">{{ include.caption | markdownify }}</figcaption>{% endcapture
%}{% assign caption= caption | prepend: new_line
%}{% endif
%}
{{ post_code | replace: "</figure>", caption | append: "</figure>" }}