{{- if ne hugo.Context.MarkupScope "home" -}}

{{- $content := trim (partial "function/dos2unix.html" .Inner) "\n" -}}
{{- $classList := slice -}}
{{- with .Get "class" -}}
  {{- $classList = $classList | append . -}}
{{- end -}}
{{- $tag := .Get "tag" | default "div" -}}
{{- $loop := cond (ne (.Get "group") "") false (.Get "loop") -}}

{{- 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>.*` "<span class=\"chroma\">$1</span>" $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 -}}
  {{- $classList = $classList | append "highlight" -}}
{{- else -}}
  {{- $content = $content | .Page.RenderString -}}
{{- end -}}

{{- $wrapperAttrs := `class="typeit"` -}}
{{- with (.Get "group" | string) -}}
  {{- $wrapperAttrs = printf `%v data-group="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "speed" -}}
  {{- $wrapperAttrs = printf `%v data-speed="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "cursorSpeed" -}}
  {{- $wrapperAttrs = printf `%v data-cursor-speed="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "cursorChar" -}}
  {{- $wrapperAttrs = printf `%v data-cursor-char="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "duration" -}}
  {{- $wrapperAttrs = printf `%v data-duration="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with $loop -}}
  {{- $wrapperAttrs = printf `%v data-loop="true"` $wrapperAttrs -}}
{{- end -}}

{{- $innerAttrs := "" -}}
{{- with $classList -}}
  {{- $innerAttrs = printf `class="%v"` (delimit $classList " ") -}}
{{- end -}}

<div {{ $wrapperAttrs | safeHTMLAttr }}>
  {{- printf `<%v %v></%v>` $tag $innerAttrs $tag | safeHTML -}}
  <template><pre>{{ printf "%v" $content | safeHTML }}</pre></template>
</div>

{{- .Page.Store.Set "hasTyped" true -}}

{{- end -}}
