Merge pull request #79 from dillonzq/fix/html_check_bug

fix(check): fix some html check bugs
This commit is contained in:
Dillon
2020-02-18 16:25:26 +08:00
committed by GitHub
20 changed files with 53 additions and 67 deletions

View File

@@ -7,7 +7,7 @@ jobs:
theme-path: theme-path:
type: string type: string
docker: docker:
- image: cibuilds/hugo:0.64 - image: cibuilds/hugo:0.62
working_directory: ~/LoveIt working_directory: ~/LoveIt
steps: steps:
- checkout - checkout
@@ -15,10 +15,9 @@ jobs:
- run: git submodule update --init - run: git submodule update --init
- run: - run:
command: | command: |
cd << parameters.example-site-path >> cd << parameters.example-site-path >> && pwd
pwd HUGO_ENV=production hugo --themesDir << parameters.theme-path >> -v --gc
HUGO_ENV=production hugo --themesDir << parameters.theme-path >> -v --minify --gc htmlproofer public --check-html --allow-hash-href --empty-alt-ignore --disable-external
htmlproofer public --allow-hash-href --empty-alt-ignore --disable-external
workflows: workflows:
build-check-exampleSite: build-check-exampleSite:
jobs: jobs:

View File

@@ -62,7 +62,7 @@ in-line changes such as annotations and abbreviations.
### Blockquote with attribution ### Blockquote with attribution
> Don't communicate by sharing memory, share memory by communicating.</p> > Don't communicate by sharing memory, share memory by communicating.
> — <cite>Rob Pike[^1]</cite> > — <cite>Rob Pike[^1]</cite>
[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015. [^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015.

View File

@@ -42,7 +42,7 @@ Markdown 开始被应用于网络以外的领域,包括作者书籍、文章
我们可以把一个文档看成一系列的块,如段落、引用、列表、标题和代码块。 我们可以把一个文档看成一系列的块,如段落、引用、列表、标题和代码块。
有些块(如引号和列表)可以包含其它的块,即 **容器块** 有些块(如引号和列表)可以包含其它的块,即 **容器块**
其他的块(如标题和段落)则包含内联元素(如文本、链接、强调、图像、内联代码等),即 **叶子块** 其他的块(如标题和段落)则包含内联元素(如文本、链接、强调、图像、内联代码等),即 **叶子块**
块的符号总是优先于内联元素的符号。例如: 块的符号总是优先于内联元素的符号。例如:

View File

@@ -381,7 +381,6 @@ Here is a story about love...
{{< /typeit >}} {{< /typeit >}}
{{< typeit group="test" code="java" >}} {{< typeit group="test" code="java" >}}
u.accepted(); // [2018/01/05](/since/) special
int a = 1; int a = 1;
{{< /typeit >}} {{< /typeit >}}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,25 +1,25 @@
<!-- only the trailing newline is retained --> {{- /* only the trailing newline is retained */ -}}
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner -}} {{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString -}}
<!-- shuffle md5 as id --> {{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 $content) "" | shuffle) "" | printf "typeit-%s" -}} {{- $id := delimit (split (md5 $content) "" | shuffle) "" | printf "typeit-%s" -}}
<div class={{ .Get "class" | default "typeit" }}> <div class={{ .Get "class" | default "typeit" }}>
<!-- raw html content --> {{- /* raw html content */ -}}
{{- if .Get "raw" -}} {{- if .Get "raw" -}}
<div id={{ printf "r%s" $id }} hidden=true> <div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}} {{- $content | safeHTML -}}
</div> </div>
<div id={{ $id }}></div> <div id={{ $id }}></div>
{{- else if .Get "code" -}} {{- else if .Get "code" -}}
<!-- highlight code content without line number --> {{- /* highlight code content without line number */ -}}
{{- $content = highlight $content (.Get "code") "linenos=false" -}} {{- $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 -}} {{- $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 -}} {{- $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 />" -}} {{- $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 -}} {{- $content = replaceRE `<br /></span>` "</span><br />" $content -}}
<div id={{ printf "r%s" $id }} hidden=true> <div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}} {{- $content | safeHTML -}}
@@ -27,7 +27,7 @@
<div class="highlight" id={{ $id }}></div> <div class="highlight" id={{ $id }}></div>
{{- else -}} {{- else -}}
{{- $tag := .Get "tag" | default "p" -}} {{- $tag := .Get "tag" | default "p" -}}
{{- $content = $content | markdownify | chomp -}} {{- $content = $content | chomp -}}
<div id={{ printf "r%s" $id }} hidden=true> <div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}} {{- $content | safeHTML -}}
</div> </div>

View File

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

View File

@@ -84,16 +84,6 @@
this.util.forEach(toc.querySelectorAll('a:first-child'), (link) => { this.util.forEach(toc.querySelectorAll('a:first-child'), (link) => {
link.classList.add('toc-link'); link.classList.add('toc-link');
}); });
// when headings do not start with `h1`
const oldTocList = toc.children[0];
let newTocList = oldTocList;
let temp;
while (newTocList.children.length === 1
&& (temp = newTocList.children[0].children[0]).tagName === 'UL') {
newTocList = temp;
}
if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList);
} }
_initTocState(tocContainer) { _initTocState(tocContainer) {
@@ -157,7 +147,7 @@
initToc() { initToc() {
const tocContainer = document.getElementById('post-toc'); const tocContainer = document.getElementById('post-toc');
if (tocContainer !== null) { if (tocContainer !== null) {
const toc = document.getElementById('TableOfContents'); const toc = tocContainer.getElementById('TableOfContents');
if (toc === null) { if (toc === null) {
tocContainer.parentElement.removeChild(tocContainer); tocContainer.parentElement.removeChild(tocContainer);
} else { } else {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long