Fix prefixing first paragraph with a newline, when there's no previous sibling node

This commit is contained in:
Christian Muehlhaeuser
2019-12-15 05:52:03 +01:00
parent a16d2a53b1
commit 27f86be69a
7 changed files with 7 additions and 7 deletions
+3 -1
View File
@@ -62,7 +62,9 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {
return Element{}
}
return Element{
Renderer: &ParagraphElement{},
Renderer: &ParagraphElement{
First: node.PreviousSibling() == nil,
},
Finisher: &ParagraphElement{},
}
+4 -1
View File
@@ -9,13 +9,16 @@ import (
)
type ParagraphElement struct {
First bool
}
func (e *ParagraphElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
rules := ctx.options.Styles.Paragraph
_, _ = w.Write([]byte("\n"))
if !e.First {
_, _ = w.Write([]byte("\n"))
}
be := BlockElement{
Block: &bytes.Buffer{},
Style: cascadeStyle(bs.Current().Style, rules, true),
-1
View File
@@ -1,2 +1 @@
This is a code. 
-1
View File
@@ -1,2 +1 @@
This text is emphasized. 
-1
View File
@@ -1,2 +1 @@
Image [Image: https://charm.sh/logo.png]. 
-1
View File
@@ -1,2 +1 @@
This is a link (https://charm.sh). 
-1
View File
@@ -1,2 +1 @@
This text is strong.