Ensure newlines between sections
This commit is contained in:
+10
-1
@@ -26,6 +26,15 @@ func splitSections(raw []byte) [][]byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// joinSections reassembles sections produced by splitSections.
|
// 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 {
|
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()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user