Ensure newlines between sections

This commit is contained in:
2026-04-23 08:46:36 +02:00
parent 093b5c2ef0
commit 314fe4600f
+10 -1
View File
@@ -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()
}