11{{- $content := trim .Inner "\n" -}}
2- {{- $classList := .Get "class" | slice -}}
2+ {{- $classList := slice -}}
3+ {{- with .Get "class" -}}
4+ {{- $classList = $classList | append . -}}
5+ {{- end -}}
36{{- $tag := .Get "tag" | default "div" -}}
47
5- {{- with .Get "code" -}}
8+ {{- if .Get "code" -}}
69 {{- /* highlight code content without line number */ -}}
7- {{- $content = highlight $content . "linenos =false" -}}
10+ {{- $content = highlight $content (.Get "code") "lineNos=false, noClasses =false" -}}
811 {{- /* delete outer label */ -}}
9- {{- $content = replaceRE `< div class =" highlight " > < pre class =" chroma " > < code [^ < > ]*> (?s)(.*)</ code > </ pre > </ div > ` "$1" $content -}}
10- {{- /* parsing markdown links */ -}}
11- {{- $content = replaceRE `( < span [^ < > ]* > )([^ < > ]*)\[([^ < > ]+)\]\(([^ < > ]+)\)([^ < > ]*)( </ span > )` "$1$2$6 < a href = $4 > $3 </ a > $1$5$6" $content -}}
12- {{- /* replace " " to " " and replace "\n" to " < br /> " */ -}}
13- {{- $content = replaceRE ` ` " " $content | replaceRE `( < \w+) ` "$1 " | replaceRE `\n` " < br /> " -}}
14- {{- /* fix " < br /> " location error which is a bug of Typeit HTML parser */ -}}
15- {{- $content = replaceRE ` < br /> </ span > ` " </ span > < br /> " $content -}}
12+ {{- $content = replaceRE `.* < code [^ < > ]*> (?s)(.*)</ code > .* ` "$1" $content -}}
13+ {{- if .Get "code-link" -}}
14+ {{- /* parsing code links */ -}}
15+ {{- $content = replaceRE `( < span [^ < > ]* > )([^ < > ]*)\[([^ < > ]+)\]\(([^ < > ]+)\)([^ < > ]*)( </ span > )` "$1$2$6 < a href = \ "$4\" > $3 </ a > $1$5$6" $content -}}
16+ {{- end -}}
17+ {{- /* split multiline string */ -}}
18+ {{- $content = split $content "\n" -}}
1619 {{- $classList = $classList | append "highlight" -}}
1720{{- else -}}
1821 {{- $content = $content | .Page.RenderString -}}
2629{{- $group = $group | default slice | append $id -}}
2730{{- dict $key $group | merge $typeitMap | .Page.Scratch.SetInMap "this" "typeitMap" -}}
2831
32+ {{- $attrs := printf `id="%v"` $id -}}
33+ {{- with $classList -}}
34+ {{- $attrs = delimit $classList " " | printf `%v class="%v"` $attrs -}}
35+ {{- end -}}
36+
2937< div class ="typeit ">
30- {{- printf `< %v id="%v" class="%v" > </ %v> ` $tag $id (delimit $classList " ") $tag | safeHTML -}}
31- </ div >
38+ {{- printf `< %v %v > </ %v> ` $tag $attrs $tag | safeHTML -}}
39+ </ div >
0 commit comments