-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtypeit.html
39 lines (35 loc) · 1.58 KB
/
typeit.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
38
39
{{- $content := trim .Inner "\n" -}}
{{- $classList := slice -}}
{{- with .Get "class" -}}
{{- $classList = $classList | append . -}}
{{- end -}}
{{- $tag := .Get "tag" | default "div" -}}
{{- if .Get "code" -}}
{{- /* highlight code content without line number */ -}}
{{- $content = highlight $content (.Get "code") "lineNos=false, noClasses=false" -}}
{{- /* delete outer label */ -}}
{{- $content = replaceRE `.*<code[^<>]*>(?s)(.*)</code>.*` "$1" $content -}}
{{- if .Get "code-link" -}}
{{- /* parsing code links */ -}}
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=\"$4\">$3</a>$1$5$6" $content -}}
{{- end -}}
{{- /* split multiline string */ -}}
{{- $content = split $content "\n" -}}
{{- $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" -}}
{{- $attrs := printf `id="%v"` $id -}}
{{- with $classList -}}
{{- $attrs = delimit $classList " " | printf `%v class="%v"` $attrs -}}
{{- end -}}
<div class="typeit">
{{- printf `<%v %v></%v>` $tag $attrs $tag | safeHTML -}}
</div>