inject the line break earlier

This commit is contained in:
dre 2021-07-06 18:45:15 +08:00
parent c2773edb00
commit 4817e23eee
3 changed files with 3 additions and 6 deletions

View file

@ -22,10 +22,6 @@ func FormatHeadings(in chan pipe.StreamItem) chan pipe.StreamItem {
if len(sub) > 0 {
data = bytes.Replace(data, sub[1], append(sub[1], []byte(" ")...), 1)
}
// generally if we deal with a heading, add an extra blank line
if bytes.HasPrefix(data, []byte("#")) {
data = append(data, '\n')
}
// writeback
out <- pipe.NewItem(b.Index(), data)
}

View file

@ -23,7 +23,7 @@ func RemoveFrontMatter(in chan pipe.StreamItem) chan pipe.StreamItem {
data = bytes.Replace(data, match[0], []byte(""), 1)
for _, title := range re2.FindAllSubmatch(match[0], 1) {
// add title
data = []byte(fmt.Sprintf("# %s\n", title[1]))
data = []byte(fmt.Sprintf("# %s\n\n", title[1]))
}
}
out <- pipe.NewItem(b.Index(), data)

View file

@ -168,7 +168,8 @@ func fence(m *fsm, data []byte) stateFn {
func toFence(m *fsm, data []byte) stateFn {
if needsFence(data) {
m.blockBuffer = append(m.blockBuffer, append(data[4:], '\n')...)
data = append(data, '\n')
m.blockBuffer = append(m.blockBuffer, data[4:]...)
return toFence
}