fix(check): fix some html check bugs

This commit is contained in:
Dillon
2020-02-18 16:22:24 +08:00
parent d8681cd489
commit 4b3addf634
20 changed files with 53 additions and 67 deletions

View File

@@ -2,7 +2,7 @@
{{- partial "function/image.html" (dict "src" .Destination "alt" .Text "title" .Title ) -}}
{{- with .Title | default .Text -}}
<figcaption class="image-caption">
{{- . -}}
{{- . | safeHTML -}}
</figcaption>
{{- end -}}
</figure>

View File

@@ -4,7 +4,7 @@
<link href="{{ .Permalink }}"/>
{{- if not .Date.IsZero -}}
<updated>
{{- .Date.Format "02-01-2006T15:04:05-07:00" | safeHTML -}}
{{- .Date.Format "02-01-2006T15:04:05-07:00" -}}
</updated>
{{- end -}}
<id>
@@ -21,9 +21,7 @@
<generator>Hugo -- gohugo.io</generator>
{{- range first 15 (where .Data.Pages "Type" "in" .Site.Params.mainSections) -}}
<entry>
<title type="html">
{{- printf "<![CDATA[%s]]>" .Title | safeHTML -}}
</title>
<title type="html"><![CDATA[{{ .Title -}}]]></title>
<link href="{{ .Permalink }}"/>
<id>
{{- .Permalink -}}
@@ -36,14 +34,12 @@
</author>
{{- end -}}
<published>
{{- .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML -}}
{{- .Date.Format "2006-01-02T15:04:05-07:00" -}}
</published>
<updated>
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML -}}
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" -}}
</updated>
<content type="html">
{{- printf "<![CDATA[%s]]>" .Content | safeHTML -}}
</content>
<content type="html"><![CDATA[{{- .Content -}}]]></content>
</entry>
{{- end -}}
</feed>

View File

@@ -76,12 +76,12 @@
"wordcount": {{ .WordCount }},
"url": "{{ .Permalink }}",
{{- if not .PublishDate.IsZero -}}
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}",
{{- else if not .Date.IsZero -}}
"datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" }}",
{{- end -}}
{{- with .Lastmod -}}
"dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" }}",
{{- end -}}
{{- with .Site.Copyright -}}
"license": "{{ . }}",

View File

@@ -37,7 +37,7 @@
{{- $currentPage := . -}}
{{- range .Site.Menus.main -}}
<a class="menu-item" href="{{ .URL | absLangURL }}" title="{{ .Title }}">
{{- .Name | safeHTML -}}
{{- .Pre | safeHTML }}{{ .Name -}}
</a>
{{- end -}}
<a href="javascript:void(0);" class="theme-switch" title="{{ T "switchTheme" }}">

View File

@@ -16,12 +16,16 @@
{{- if $.Site.Params.home.profile.typeit -}}
{{- $id := md5 . | printf "tp-%s" -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- . | safeHTML -}}
{{- /* FIXME: https://github.com/gohugoio/hugo/issues/6882 */ -}}
{{- /* . | $.RenderString | safeHTML */ -}}
{{- . | markdownify | safeHTML -}}
</div>
<div id={{ $id }} class="typeit"></div>
{{- $.Scratch.SetInMap "typeitMap" $id (slice $id) -}}
{{- else -}}
{{- . | safeHTML -}}
{{- /* FIXME: https://github.com/gohugoio/hugo/issues/6882 */ -}}
{{- /* . | $.RenderString | safeHTML */ -}}
{{- . | markdownify | safeHTML -}}
{{- end -}}
</h2>
{{- end -}}

View File

@@ -47,14 +47,14 @@
{{- /* TOC */ -}}
{{- if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) -}}
<div class="post-toc" id="post-toc">
<aside class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2>
{{- $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default true }}
<div class="post-toc-content{{ if not (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false)) }} always-active{{ end }}">
{{- .TableOfContents -}}
</div>
</div>
<div class="post-toc-mobile" id="post-toc-mobile">
</aside>
<aside class="post-toc-mobile" id="post-toc-mobile">
<details>
<summary>
<div class="post-toc-title">
@@ -68,7 +68,7 @@
{{- $toc | safeHTML -}}
</div>
</details>
</div>
</aside>
{{- end -}}
{{- /* Content */ -}}

View File

@@ -30,7 +30,7 @@
{{- end -}}
{{- if not .Date.IsZero -}}
<lastBuildDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML -}}
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</lastBuildDate>
{{- end -}}
<atom:link href="{{.Permalink}}" rel="self" type="application/rss+xml" />
@@ -43,7 +43,7 @@
{{- .Permalink -}}
</link>
<pubDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML -}}
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</pubDate>
{{- with .Site.Author.email -}}
<author>

View File

@@ -1,4 +1,5 @@
{{- $_hugo_config := `{ "version": 1 }` -}}
{{- $inner := .Inner | .Page.RenderString -}}
{{- $iconMap := dict "note" "fas fa-pencil-alt" -}}
{{- $iconMap = dict "abstract" "fas fa-list-ul" | merge $iconMap -}}
{{- $iconMap = dict "info" "fas fa-info-circle" | merge $iconMap -}}
@@ -22,14 +23,14 @@
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}<i class="details {{ $iconDetails }}"></i>
</summary>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</details>
{{- else -}}
<div class="admonition {{ $type }}">
{{- with .Get "title" -}}
<p class="admonition-title"><i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}</p>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</div>
{{- end -}}
{{- else -}}
@@ -41,14 +42,14 @@
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}<i class="details {{ $iconDetails }}"></i>
</summary>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</details>
{{- else -}}
<div class="admonition {{ $type }}">
{{- with .Get 1 -}}
<p class="admonition-title"><i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}</p>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</div>
{{- end -}}
{{- end -}}

View File

@@ -1,5 +1,4 @@
{{ $_hugo_config := `{ "version": 1 }` -}}
<!-- [left, center, right] -->
{{- /* [left, center, right] */ -}}
<div class={{ .Get 0 | printf "align-%s" }}>
{{- .Inner -}}
{{- .Inner | .Page.RenderString -}}
</div>

View File

@@ -1,5 +1,4 @@
{{ $_hugo_config := `{ "version": 1 }` -}}
<!-- [left, right] -->
{{- /* [left, right] */ -}}
<div class={{ .Get 0 | printf "float-%s" }}>
{{- .Inner -}}
{{- .Inner | .Page.RenderString -}}
</div>

View File

@@ -1,4 +1,4 @@
<!-- shuffle md5 as id -->
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "mermaid-%s" -}}
<div class="mermaid" id="{{ $id }}"></div>
{{- .Page.Scratch.SetInMap "mermaidMap" $id (trim .Inner "\n") -}}

View File

@@ -1,25 +1,25 @@
<!-- only the trailing newline is retained -->
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner -}}
<!-- shuffle md5 as id -->
{{- /* 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" -}}
<div class={{ .Get "class" | default "typeit" }}>
<!-- raw html content -->
{{- /* 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 -->
{{- /* highlight code content without line number */ -}}
{{- $content = highlight $content (.Get "code") "linenos=false" -}}
<!-- delete outer label -->
{{- /* delete outer label */ -}}
{{- $content = replaceRE `<div class="highlight"><pre class="chroma"><code[^<>]*>(?s)(.*)</code></pre></div>` "$1" $content -}}
<!-- parsing markdown links -->
{{- /* parsing markdown links */ -}}
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content -}}
<!-- replace " " to "&nbsp;" and replace "\n" to "<br />" -->
{{- /* replace " " to "&nbsp;" and replace "\n" to "<br />" */ -}}
{{- $content = replaceRE ` ` "&nbsp;" $content | replaceRE `(<\w+)&nbsp;` "$1 " | replaceRE `\n` "<br />" -}}
<!-- fix "<br />" location error which is a bug of Typeit HTML parser -->
{{- /* 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 -}}
@@ -27,7 +27,7 @@
<div class="highlight" id={{ $id }}></div>
{{- else -}}
{{- $tag := .Get "tag" | default "p" -}}
{{- $content = $content | markdownify | chomp -}}
{{- $content = $content | chomp -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>

View File

@@ -9,7 +9,7 @@
</loc>
{{- if not .Lastmod.IsZero -}}
<lastmod>
{{- safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) -}}
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" -}}
</lastmod>
{{- end -}}
{{- with .Sitemap.ChangeFreq -}}