From c2773edb00c9294ed162fd9c5d81c7f3c1d039a2 Mon Sep 17 00:00:00 2001 From: dre Date: Tue, 6 Jul 2021 18:39:27 +0800 Subject: [PATCH] fix post list double linebreak issue --- mdproc/hugo_test.go | 2 -- mdproc/preproc.go | 15 ++++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mdproc/hugo_test.go b/mdproc/hugo_test.go index e7e0e06..0dd23b4 100644 --- a/mdproc/hugo_test.go +++ b/mdproc/hugo_test.go @@ -48,7 +48,6 @@ and - an unordered - list - This is a paragraph with a link to the [gemini protocol](https://en.wikipedia.org/wiki/Gemini_(protocol)). ` + "```" + ` @@ -73,7 +72,6 @@ this is code too - an unordered - list - This is a paragraph with a link to the gemini protocol[1]. => https://en.wikipedia.org/wiki/Gemini_(protocol) 1: gemini protocol diff --git a/mdproc/preproc.go b/mdproc/preproc.go index 76f1bcf..f39e507 100644 --- a/mdproc/preproc.go +++ b/mdproc/preproc.go @@ -99,7 +99,7 @@ func needsFence(data []byte) bool { return len(data) >= 4 && string(data[0:4]) == " " } -func normal(m *fsm, data []byte) stateFn { +func normalText(m *fsm, data []byte) stateFn { if len(bytes.TrimSpace(data)) == 0 { return normal } @@ -134,22 +134,24 @@ func normal(m *fsm, data []byte) stateFn { m.blockBuffer = append(m.blockBuffer, append(data, '\n')...) m.blockFlush() - return normal } +func normal(m *fsm, data []byte) stateFn { + return normalText(m, data) +} + func list(m *fsm, data []byte) stateFn { if data, isList := handleList(data); isList { + data = append(data, '\n') m.blockBuffer = append(m.blockBuffer, data...) - m.blockFlush() return list } - m.blockBuffer = append(m.blockBuffer, append(data, '\n')...) m.blockFlush() - return normal + return normalText(m, data) } func fence(m *fsm, data []byte) stateFn { @@ -172,9 +174,8 @@ func toFence(m *fsm, data []byte) stateFn { } m.blockFlush() - m.blockBuffer = append(m.blockBuffer, append(data, '\n')...) - return normal + return normalText(m, data) } func paragraph(m *fsm, data []byte) stateFn {