From 4817e23eee8943cd546f87a5bbe8d7a68f22c0b3 Mon Sep 17 00:00:00 2001 From: dre Date: Tue, 6 Jul 2021 18:45:15 +0800 Subject: [PATCH] inject the line break earlier --- mdproc/headings.go | 4 ---- mdproc/hugo.go | 2 +- mdproc/preproc.go | 3 ++- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mdproc/headings.go b/mdproc/headings.go index 244f10e..c8d6207 100644 --- a/mdproc/headings.go +++ b/mdproc/headings.go @@ -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) } diff --git a/mdproc/hugo.go b/mdproc/hugo.go index aeb1914..493812e 100644 --- a/mdproc/hugo.go +++ b/mdproc/hugo.go @@ -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) diff --git a/mdproc/preproc.go b/mdproc/preproc.go index f39e507..5f2c07e 100644 --- a/mdproc/preproc.go +++ b/mdproc/preproc.go @@ -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 }