Welcome to mirror list, hosted at ThFree Co, Russian Federation.

typeit.html « shortcodes « layouts - github.com/uPagge/uBlogger.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d2ea0125d788bc85a243f8eb8a20ccc7b04e099 (plain)
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
{{- $content := trim .Inner "\n" -}}
{{- $classList := .Get "class" | slice -}}
{{- $tag := .Get "tag" | default "div" -}}

{{- with .Get "code" -}}
    {{- /* highlight code content without line number */ -}}
    {{- $content = highlight $content . "linenos=false" -}}
    {{- /* delete outer label */ -}}
    {{- $content = replaceRE `<div class="highlight"><pre class="chroma"><code[^<>]*>(?s)(.*)</code></pre></div>` "$1" $content -}}
    {{- /* parsing markdown links */ -}}
    {{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content -}}
    {{- /* replace " " to "&nbsp;" and replace "\n" to "<br />" */ -}}
    {{- $content = replaceRE ` ` "&nbsp;" $content | replaceRE `(<\w+)&nbsp;` "$1 " | replaceRE `\n` "<br />" -}}
    {{- /* fix "<br />" location error which is a bug of Typeit HTML parser */ -}}
    {{- $content = replaceRE `<br /></span>` "</span><br />" $content -}}
    {{- $classList = $classList | append "highlight" -}}
{{- else -}}
    {{- $content = $content | .Page.RenderString -}}
{{- end -}}

{{- /* trim the newline */ -}}
{{- $id := dict "Content" $content "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $key := .Get "group" | string | default $id -}}
{{- $typeitMap := (.Page.Scratch.Get "this").typeitMap | default dict -}}
{{- $group := index $typeitMap $key -}}
{{- $group = $group | default slice | append $id -}}
{{- dict $key $group | merge $typeitMap | .Page.Scratch.SetInMap "this" "typeitMap" -}}

<div class="typeit">
    {{- printf `<%v id="%v" class="%v"></%v>` $tag $id (delimit $classList " ") $tag | safeHTML -}}
</div>