diff options
Diffstat (limited to 'mardown/ast_paragraph.go')
| -rw-r--r-- | mardown/ast_paragraph.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/mardown/ast_paragraph.go b/mardown/ast_paragraph.go index 3ebc519..04f2086 100644 --- a/mardown/ast_paragraph.go +++ b/mardown/ast_paragraph.go @@ -2,6 +2,7 @@ package mardown import ( "errors" + "fmt" "html/template" ) @@ -12,6 +13,7 @@ var ( type astParagraph struct { content []block + oneLine bool } func (a *astParagraph) Eval() (template.HTML, error) { @@ -23,18 +25,26 @@ func (a *astParagraph) Eval() (template.HTML, error) { } content += ct } - return content, nil + if a.oneLine { + return content, nil + } + return template.HTML(fmt.Sprintf("<p>%s</p>", content)), nil } -func paragraph(lxs lexers) (block, error) { +func paragraph(lxs lexers, oneLine bool) (*astParagraph, error) { tree := new(astParagraph) + tree.oneLine = oneLine + maxBreak := 2 + if oneLine { + maxBreak = 1 + } n := 0 lxs.current-- // because we do not use it before the next - for lxs.Next() && n < 2 { + for lxs.Next() && n < maxBreak { switch lxs.Current().Type { case lexerBreak: n++ - case lexerLiteral: + case lexerLiteral, lexerHeader: tree.content = append(tree.content, astLiteral(lxs.Current().Value)) case lexerModifier: //TODO: handle |
