From 906507e8719bf597f0a04ca40608f164097f5229 Mon Sep 17 00:00:00 2001 From: dre Date: Sun, 11 Jul 2021 13:48:46 +0800 Subject: [PATCH] fix bold/italic are not lists --- mdproc/preproc.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/mdproc/preproc.go b/mdproc/preproc.go index 5f2c07e..97a9b08 100644 --- a/mdproc/preproc.go +++ b/mdproc/preproc.go @@ -24,7 +24,7 @@ type fsm struct { pending []byte } -func Preproc() pipe.Pipeline { +func Preprocessor() pipe.Pipeline { return (&fsm{}).pipeline } @@ -72,19 +72,34 @@ func (m *fsm) blockFlush() { } } -func triggerBreak(data []byte) bool { - return len(data) == 0 || data[len(data)-1] == '.' -} - func isTerminated(data []byte) bool { return len(data) > 0 && data[len(data)-1] != '.' } +func triggerBreak(data []byte) bool { + if len(data) == 0 || len(data) == 1 && data[0] == '\n' { + return true + } + switch data[len(data)-1] { + case '.': + fallthrough + case ';': + fallthrough + case ':': + return true + } + return false +} + func handleList(data []byte) ([]byte, bool) { - re := regexp.MustCompile(`^([ \t]*[-*^]{1,1})[^*-]`) - sub := re.FindSubmatch(data) + // match italic, bold + nolist := regexp.MustCompile(`[\*_](.*)[\*_]`) + nosub := nolist.FindSubmatch(data) + // match lists + list := regexp.MustCompile(`^([ \t]*[-*^]{1,1})[^*-]`) + sub := list.FindSubmatch(data) // if lists, collapse to single level - if len(sub) > 1 { + if len(sub) > 1 && len(nosub) <= 1 { return bytes.Replace(data, sub[1], []byte("-"), 1), true }