diff --git a/markup/lexer.go b/markup/lexer.go index b69a3cf..4dae95b 100644 --- a/markup/lexer.go +++ b/markup/lexer.go @@ -51,6 +51,13 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) { addLine := func(text interface{}) { *ast = append(*ast, Line{id: state.id, contents: text}) } + addParagraphIfNeeded := func() { + if state.where == "p" { + state.where = "" + addLine(fmt.Sprintf("

%s

", state.id, strings.ReplaceAll(ParagraphToHtml(state.name, state.buf), "\n", "
"))) + state.buf = "" + } + } // Process empty lines depending on the current state if "" == strings.TrimSpace(line) { @@ -66,6 +73,8 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) { case "launchpad": state.where = "" addLine(state.buf + "") + case "p": + addParagraphIfNeeded() } return } @@ -91,7 +100,7 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) { goto numberState case "launchpad": goto launchpadState - default: + default: // "p" or "" goto normalState } @@ -175,43 +184,57 @@ normalState: switch { case startsWith("```"): + addParagraphIfNeeded() state.where = "pre" state.buf = fmt.Sprintf("
", state.id, strings.TrimPrefix(line, "```"))
 	case startsWith("* "):
+		addParagraphIfNeeded()
 		state.where = "list"
 		state.buf = fmt.Sprintf("