diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | README.zh-cn.md | 1 | ||||
-rw-r--r-- | config-examples/en-us/config.toml | 5 | ||||
-rw-r--r-- | config-examples/zh-cn/config.toml | 5 | ||||
-rw-r--r-- | layouts/partials/components/content.html | 43 |
5 files changed, 48 insertions, 7 deletions
@@ -101,6 +101,7 @@ dropCap | drop cap? | boolean, override `enableDropCap` in `config.toml`, theme dropCapAfterHr | drop cap after every horizontal rule tag? | boolean, override `enableDropCapAfterHr` in `config.toml`, theme only deleteHrBeforeDropCap | delete horizontal rule tag before drop cap? | boolean, override `deleteHrBeforeDropCap` in `config.toml`, theme only indent | indent instead of margin? | boolean, override `paragraphStyle` in `config.toml`, theme only +indentFirstParagraph | indent the first paragraph? | boolean, override `indentFirstParagraph` in `config.toml`, theme only align | normal, justify, center | srting, if euqal to "normal", will override `enableJustify` in `config.toml`, theme only original | original? You can add the following 8 terms if you set `false`. The `author` is required, other optional | boolean, override `original` in `config.toml`, theme only author | author of original post | string, theme only diff --git a/README.zh-cn.md b/README.zh-cn.md index 1deaefd..56796c9 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -101,6 +101,7 @@ dropCap | drop cap? | boolean, override `enableDropCap` in `config.toml`, theme dropCapAfterHr | drop cap after every horizontal rule tag? | boolean, override `enableDropCapAfterHr` in `config.toml`, theme only deleteHrBeforeDropCap | delete horizontal rule tag before drop cap? | boolean, override `deleteHrBeforeDropCap` in `config.toml`, theme only indent | indent instead of margin? | boolean, override `paragraphStyle` in `config.toml`, theme only +indentFirstParagraph | indent the first paragraph? | boolean, override `indentFirstParagraph` in `config.toml`, theme only align | normal, justify, center | srting, if euqal to "normal", will override `enableJustify` in `config.toml`, theme only original | original? You can add the following 8 terms if you set `false`. The `author` is required, other optional | boolean, override `original` in `config.toml`, theme only author | author of original post | string, theme only diff --git a/config-examples/en-us/config.toml b/config-examples/en-us/config.toml index 431bbbb..195f489 100644 --- a/config-examples/en-us/config.toml +++ b/config-examples/en-us/config.toml @@ -934,6 +934,11 @@ uglyURLs = false enableParagraphIndent = true + indentFirstParagraph = false + # Note: *global settings* + # `indentFirstParagraph` in post’s Front Matter + # has a higher priority than here + paragraphStyle = "margin" # Note: margin or indent # *global settings* diff --git a/config-examples/zh-cn/config.toml b/config-examples/zh-cn/config.toml index eea8e40..2d2712d 100644 --- a/config-examples/zh-cn/config.toml +++ b/config-examples/zh-cn/config.toml @@ -883,6 +883,11 @@ uglyURLs = false # 是否开启 enableParagraphIndent = true + # 是否缩进第一段(全局设置) + indentFirstParagraph = false + # 说明:文章的 Front Matter 中的 `indentFirstParagraph` + # 的优先级高于此处 + # 分段样式(全局设置) paragraphStyle = "margin" # 说明:段间距式(margin)或段首缩排(indent) diff --git a/layouts/partials/components/content.html b/layouts/partials/components/content.html index f6b2d4d..1804cbd 100644 --- a/layouts/partials/components/content.html +++ b/layouts/partials/components/content.html @@ -55,7 +55,7 @@ {{- end -}} {{- $enableDropCap := .Scratch.Get "enableDropCap" -}} {{- if $enableDropCap -}} - {{- $regexPatternDropCap := `(<p)(>)([^<])(.+(</p>|\n))` -}} + {{- $regexPatternDropCap := `(<p)(>)(.)([^<]+)` -}} {{- $regexReplacementDropCap := `$1 style="text-indent:0"$2<span class="drop-cap">$3</span>$4` -}} {{- $firstParagraphOld := (delimit (findRE $regexPatternDropCap .Content 1) " ") -}} {{- $firstParagraphNew := (replaceRE $regexPatternDropCap $regexReplacementDropCap $firstParagraphOld) -}} @@ -65,18 +65,19 @@ <!-- Drop Cap After `<hr />` --> {{- $Content := .Scratch.Get "Content" -}} +{{- $enableDropCapAfterHr := and .Site.Params.enableDropCap (.Params.dropCapAfterHr | default .Site.Params.enableDropCapAfterHr) -}} {{- if ne .Type "poetry" -}} - {{- if and .Site.Params.enableDropCap (.Params.dropCapAfterHr | default .Site.Params.enableDropCapAfterHr) -}} + {{- if $enableDropCapAfterHr -}} {{- if .Params.deleteHrBeforeDropCap | default .Site.Params.deleteHrBeforeDropCap -}} - {{- $replacement := `$3 style="text-indent:0"$4<span class="drop-cap">$5</span>$6` -}} + {{- $replacement := `$3 style="text-indent:0"$4<span class="drop-cap">$5</span>` -}} {{- $.Scratch.Set "replacement" $replacement -}} {{- else -}} - {{- $replacement := `$1$3 style="text-indent:0"$4<span class="drop-cap">$5</span>$6` -}} + {{- $replacement := `$1$3 style="text-indent:0"$4<span class="drop-cap">$5</span>` -}} {{- $.Scratch.Set "replacement" $replacement -}} {{- end -}} {{- $replacement := .Scratch.Get "replacement" -}} - {{- $regexPatternDropCapAfterHr := `(\n(<hr />|<hr>))(\n\n?<p)(>)([^<])(.+(</p>|\n))` -}} + {{- $regexPatternDropCapAfterHr := `(\n(<hr />|<hr>))(\n<p)(>)(.)` -}} {{- $regexReplacementDropCapAfterHr := $replacement -}} {{- $Content := $Content | replaceRE $regexPatternDropCapAfterHr $regexReplacementDropCapAfterHr | safeHTML -}} {{- .Scratch.Set "Content" $Content -}} @@ -175,8 +176,9 @@ <!-- Paragraph Indent --> {{- $Content := .Scratch.Get "Content" -}} +{{- $enableIndent := (and .Site.Params.enableParagraphIndent .Params.indent) | default (and .Site.Params.enableParagraphIndent (eq .Site.Params.paragraphStyle "indent")) -}} {{- if ne .Type "poetry" -}} - {{- if (and .Site.Params.enableParagraphIndent .Params.indent) | default (and .Site.Params.enableParagraphIndent (eq .Site.Params.paragraphStyle "indent")) -}} + {{- if $enableIndent -}} {{- $regexPatternIndent := `((</p>|<blockquote>)\n<p)(>)(.+(<br />|<br>))` -}} {{- $regexReplacementIndent := `$1 style="text-indent:0;padding-left:2em;margin:1em 0"$3$4` -}} {{- $Content := $Content | replaceRE $regexPatternIndent $regexReplacementIndent | safeHTML -}} @@ -184,6 +186,33 @@ {{- end -}} {{- end -}} +<!-- Do NOT Indent The First Paragraph --> +{{- $Content := .Scratch.Get "Content" -}} +{{- if and (not (.Params.indentFirstParagraph | default .Site.Params.indentFirstParagraph)) $enableIndent -}} + {{- if ne .Type "poetry" -}} + {{- if not $enableDropCap -}} + {{- $regex := `(<p)(>[^<]+)` -}} + {{- $replacement := `$1 style="text-indent:0"$2` -}} + {{- $firstParagraphOld := (delimit (findRE $regex .Content 1) " ") -}} + {{- $firstParagraphNew := (replaceRE $regex $replacement $firstParagraphOld) -}} + {{- $Content := replace $Content $firstParagraphOld $firstParagraphNew | safeHTML -}} + {{- .Scratch.Set "Content" $Content -}} + {{- end -}} + {{- $Content := .Scratch.Get "Content" -}} + {{- if not $enableDropCapAfterHr -}} + {{- $regex := `((</h[1-6]>|<hr>|<hr />)\n<p)(>)` -}} + {{- $.Scratch.Set "regex" $regex -}} + {{- else -}} + {{- $regex := `((</h[1-6]>)\n<p)(>)` -}} + {{- $.Scratch.Set "regex" $regex -}} + {{- end -}} + {{- $regex := .Scratch.Get "regex" -}} + {{- $replacement := `$1 style="text-indent:0"$3` -}} + {{- $Content := $Content | replaceRE $regex $replacement | safeHTML -}} + {{- .Scratch.Set "Content" $Content -}} + {{- end -}} +{{- end -}} + <!-- Dark Mode --> {{- if .Site.Params.enableHighlight -}} {{- if and .Site.Params.enableDarkMode (eq .Site.Params.defaultTheme "dark") -}} @@ -209,4 +238,4 @@ <!-- Final Content --> {{- $Content := .Scratch.Get "Content" -}} -{{- .Scratch.Set "Content" $Content -}}
\ No newline at end of file +{{- .Scratch.Set "Content" $Content -}} |