From e7df6e465a5519cea543afe83f1033cb4c70d46c Mon Sep 17 00:00:00 2001 From: Shadi Romani Date: Mon, 26 Oct 2026 18:30:46 +0000 Subject: [PATCH 1/3] Collapse runs of blank lines in the Markdown output Shortcodes and the newlines around them in the source leave runs of two to five blank lines in the Markdown output. One blank line separates blocks just as well and costs fewer tokens. The body partial now swaps each fenced code block for a placeholder, collapses the runs, and swaps the code back, so blank lines inside samples stay as they are. Co-Authored-By: Claude Fable 5.1 --- layouts/partials/markdown/body.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 -}} From e9cafd4651cd242aece8bd3d8f1344c4708903d8 Mon Sep 17 00:00:00 2001 From: Shadi Romani Date: Mon, 26 Oct 2026 18:30:46 +0000 Subject: [PATCH 2/3] Drop the trailing blank lines from section pages A section page whose body already links every child ended with two blank lines, because the blank line before "Pages in this section" was written even when that list was left out. Co-Authored-By: Claude Fable 5.1 --- layouts/_default/list.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/layouts/_default/list.md b/layouts/_default/list.md index c74dc6e5b..a80cec7a5 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,11 @@ {{- $unlinked = $unlinked | append . -}} {{- end -}} {{- end -}} -{{- with $unlinked -}} +{{- /* One blank line between the body and the list, and no blank lines at + the end when every child is already linked. */ -}} +{{- with $unlinked }} +{{ with $body }} +{{ end -}} ## Pages in this section {{ range . -}} From 8a387ded14fbcc1e63c27727cd593b1ca4b22849 Mon Sep 17 00:00:00 2001 From: Shadi Romani Date: Tue, 27 Oct 2026 20:37:21 +0000 Subject: [PATCH 3/3] End a section page with one newline when it has no list A section page whose body already links every child ended without a newline, because the newline after the body was written only with the list. The list template now ends the body with a newline on its own and adds the blank line before the list only when there is a body and a list, so a section page ends the way a single page does. Co-Authored-By: Claude Fable 5.1 --- layouts/_default/list.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/layouts/_default/list.md b/layouts/_default/list.md index a80cec7a5..fb8bb2fd7 100644 --- a/layouts/_default/list.md +++ b/layouts/_default/list.md @@ -9,10 +9,12 @@ {{- $unlinked = $unlinked | append . -}} {{- end -}} {{- end -}} -{{- /* One blank line between the body and the list, and no blank lines at - the end when every child is already linked. */ -}} +{{- /* 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 }} -{{ with $body }} +{{- if $body }} {{ end -}} ## Pages in this section