diff --git a/layouts/_default/list.md b/layouts/_default/list.md index c74dc6e5b..fb8bb2fd7 100644 --- a/layouts/_default/list.md +++ b/layouts/_default/list.md @@ -1,8 +1,6 @@ {{ partial "markdown/front-matter.md" . }} {{- $body := partial "markdown/body.md" . }} -{{ with $body }}{{ . }} - -{{ end -}} +{{ $body }} {{- /* Leave out the children that the body already links, for example in a link group, so the page does not list them twice. */ -}} {{- $unlinked := slice -}} @@ -11,7 +9,13 @@ {{- $unlinked = $unlinked | append . -}} {{- end -}} {{- end -}} -{{- with $unlinked -}} +{{- /* End the body with a newline, and add a blank line before the list. + A page with no body needs neither. */ -}} +{{- if $body }} +{{ end -}} +{{- with $unlinked }} +{{- if $body }} +{{ end -}} ## Pages in this section {{ range . -}} diff --git a/layouts/partials/markdown/body.md b/layouts/partials/markdown/body.md index 1050d4780..b69d280fe 100644 --- a/layouts/partials/markdown/body.md +++ b/layouts/partials/markdown/body.md @@ -23,4 +23,16 @@ {{- end -}} {{- end -}} {{- end -}} +{{- /* Shortcodes and their source leave runs of blank lines. One blank line + separates blocks just as well and costs fewer tokens. Keep the runs + inside fenced code, where they are part of the sample: swap each + fence for a placeholder, collapse the runs, and swap the fences back. */ -}} +{{- $fences := findRE "(?ms)^[ \t]*```.*?^[ \t]*```[ \t]*$" $body -}} +{{- range $i, $fence := $fences -}} + {{- $body = replace $body $fence (printf "\x00%d\x00" $i) -}} +{{- end -}} +{{- $body = replaceRE `\n([ \t]*\n){2,}` "\n\n" $body -}} +{{- range $i, $fence := $fences -}} + {{- $body = replace $body (printf "\x00%d\x00" $i) $fence -}} +{{- end -}} {{- $body | strings.TrimSpace -}}