feat: new style and faster
This commit is contained in:
25
layouts/shortcodes/admonition.html
Normal file
25
layouts/shortcodes/admonition.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{{ if .IsNamedParams }}
|
||||
{{ if eq (.Get "details") "true" }}
|
||||
<details class="admonition {{ .Get "type" }}">
|
||||
{{ with .Get "title" }}<summary class="admonition-title">{{ . }}</summary>{{ end }}
|
||||
{{ .Inner }}
|
||||
</details>
|
||||
{{ else }}
|
||||
<div class="admonition {{ .Get "type" }}">
|
||||
{{- with .Get "title" }}<p class="admonition-title">{{ . }}</p>{{ end }}
|
||||
{{ .Inner }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ if eq (.Get 2) "true" }}
|
||||
<details class="admonition {{ .Get 0 }}">
|
||||
{{- with .Get 1 }}<summary class="admonition-title">{{ . }}</summary>{{ end }}
|
||||
{{ .Inner }}
|
||||
</details>
|
||||
{{ else }}
|
||||
<div class="admonition {{ .Get 0 }}">
|
||||
{{- with .Get 1 }}<p class="admonition-title">{{ . }}</p>{{ end }}
|
||||
{{ .Inner }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,35 +1,42 @@
|
||||
{{ $content := .Inner }}
|
||||
<!-- only the trailing newline is retained -->
|
||||
{{ $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner }}
|
||||
<!-- shuffle md5 as id -->
|
||||
{{ $id := delimit (split (md5 $content) "" | shuffle) "" | printf "tp-%s" }}
|
||||
|
||||
{{ if .Get "raw" }}
|
||||
{{ $content = trim $content "\n" }}
|
||||
<div id={{ printf "r%s" $id }} hidden=true>{{ $content | safeHTML }}</div>
|
||||
<div class={{ .Get "class" }} id={{ $id }}></div>
|
||||
{{ else if .Get "code" }}
|
||||
{{ $content = highlight $content (.Get "code") "encoding=utf-8" }}
|
||||
{{ $content = replaceRE `<div class="highlight">\s*?<pre class="chroma">\s*?<code.*?>(?s)(.*?)</code>\s*?</pre>\s*?</div>` "$1" $content }}
|
||||
{{ $content = trim $content "\n" }}
|
||||
{{ $content = replaceRE `\n</span>` "</span>\n" $content }}
|
||||
{{ $content = replaceRE `(?m)^(<span.*?>)(.*?)\[(.*?)\]\((.*?)\)(.*?)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content }}
|
||||
{{ $content = replaceRE ` ` " " $content | replaceRE `(<\w+) ` "$1 " | replaceRE `\n` "<br />" }}
|
||||
<div id={{ printf "r%s" $id }} hidden=true>{{ $content | safeHTML }}</div>
|
||||
<div class={{ .Get "class" | default "typeit-code" }} id={{ $id }}></div>
|
||||
{{ else }}
|
||||
{{ $tag := .Get "tag" | default "p" }}
|
||||
{{ $content = $content | markdownify | chomp }}
|
||||
{{ $content = trim $content "\n" }}
|
||||
<div id={{ printf "r%s" $id }} hidden=true>{{ $content | safeHTML }}</div>
|
||||
{{ printf "<%s class=%s id=%s></%s>" $tag (.Get "class" | default "typeit") $id $tag | safeHTML }}
|
||||
{{ end }}
|
||||
|
||||
<script>
|
||||
var typeitMap = window.typeitMap || {};
|
||||
{{ with .Get "group" }}
|
||||
if (!typeitMap[{{ . }}]) {
|
||||
typeitMap[{{ . }}] = [];
|
||||
}
|
||||
typeitMap[{{ . }}].push({{ $id }});
|
||||
<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 -->
|
||||
{{ $content = highlight $content (.Get "code") "linenos=" }}
|
||||
<!-- 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 " " and replace "\n" to "<br />" -->
|
||||
{{ $content = replaceRE ` ` " " $content | replaceRE `(<\w+) ` "$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="code" id={{ $id }}></div>
|
||||
{{ else }}
|
||||
typeitMap[{{ $id }}] = true;
|
||||
{{ $tag := .Get "tag" | default "p" }}
|
||||
{{ $content = $content | markdownify | chomp }}
|
||||
<div id={{ printf "r%s" $id }} hidden=true>{{ $content | safeHTML }}</div>
|
||||
{{ printf "<%s id=%s></%s>" $tag $id $tag | safeHTML }}
|
||||
{{ end }}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var typeitMap = window.typeitMap || {};
|
||||
{{ with .Get "group" }}
|
||||
if (!typeitMap[{{ . }}]) {
|
||||
typeitMap[{{ . }}] = [];
|
||||
}
|
||||
typeitMap[{{ . }}].push({{ $id }});
|
||||
{{ else }}
|
||||
typeitMap[{{ $id }}] = true;
|
||||
{{ end }}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user