fix(srcatch): fix srcatch bugs

This commit is contained in:
Dillon
2020-02-27 20:14:40 +08:00
parent 0dc5feb7f3
commit ae81e3767e
32 changed files with 370 additions and 210 deletions

View File

@@ -1,6 +0,0 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "echarts-%s" -}}
<div class="echarts" id="{{ $id }}"></div>
{{- $scratch.SetInMap "echartsMap" $id (printf "{%s}" .Inner) -}}

View File

@@ -0,0 +1,6 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
{{- $content := .Inner | transform.Unmarshal | jsonify -}}
{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}}
<div class="echarts" id="{{ $id }}"></div>
{{- slice $id | $scratch.Add "echartsArr" -}}

View File

@@ -1,6 +1,5 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "mermaid-%s" -}}
{{- $id := partial "function/id.html" (dict "content" (trim .Inner "\n") "scratch" $scratch) -}}
<div class="mermaid" id="{{ $id }}"></div>
{{- $scratch.SetInMap "mermaidMap" $id (trim .Inner "\n") -}}
{{- slice $id | $scratch.Add "mermaidArr" -}}

View File

@@ -1,16 +1,12 @@
{{- $scratch := .Page.Scratch.Get "scratch" -}}
{{- /* only the trailing newline is retained */ -}}
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString -}}
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 $content) "" | shuffle) "" | printf "typeit-%s" -}}
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString | chomp -}}
{{- $id := partial "function/id.html" (dict "content" $content "scratch" $scratch) -}}
<div class={{ .Get "class" | default "typeit" }}>
{{- /* raw html content */ -}}
{{- if .Get "raw" -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
<div id={{ $id }}></div>
{{- else if .Get "code" -}}
{{- /* highlight code content without line number */ -}}
@@ -23,16 +19,9 @@
{{- $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 -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
<div class="highlight" id={{ $id }}></div>
{{- else -}}
{{- $tag := .Get "tag" | default "p" -}}
{{- $content = $content | chomp -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
{{- printf "<%s id=%s></%s>" $tag $id $tag | safeHTML -}}
{{- end -}}