From 314fe4600f598848b1dd9d1075900dc3a533a737 Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 23 Apr 2026 08:46:36 +0200 Subject: [PATCH] Ensure newlines between sections --- sections.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sections.go b/sections.go index bca603b..4b26820 100644 --- a/sections.go +++ b/sections.go @@ -26,6 +26,15 @@ func splitSections(raw []byte) [][]byte { } // joinSections reassembles sections produced by splitSections. +// Inserts a newline between sections when a non-empty section lacks a +// trailing newline, so an edited section cannot inline the next heading. func joinSections(sections [][]byte) []byte { - return bytes.Join(sections, nil) + var buf bytes.Buffer + for i, s := range sections { + buf.Write(s) + if i < len(sections)-1 && len(s) > 0 && s[len(s)-1] != '\n' { + buf.WriteByte('\n') + } + } + return buf.Bytes() }