Skip to content

Commit

Permalink
fix markdownfmt adds trailing blank lines to document (#1)
Browse files Browse the repository at this point in the history
* fix markdownfmt adds trailing blank lines to document

* fix markdownfmt adds trailing blank lines to document
  • Loading branch information
favadi authored and Kunde21 committed Sep 3, 2019
1 parent cf3eaf9 commit 3cd4054
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 5 additions & 3 deletions markdown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"io/ioutil"
"strings"

runewidth "github.com/mattn/go-runewidth"
blackfriday "github.com/russross/blackfriday/v2"
"github.com/mattn/go-runewidth"
"github.com/russross/blackfriday/v2"
"github.com/shurcooL/go/indentwriter"
)

Expand Down Expand Up @@ -113,7 +113,9 @@ func (_ *markdownRenderer) TitleBlock(out *bytes.Buffer, text []byte) {}

func (mr *markdownRenderer) Header(node *blackfriday.Node, entering bool) {
if entering {
mr.doubleSpace(nil)
if node.Prev != nil || node.Parent.Type != blackfriday.Document {
mr.doubleSpace(nil)
}
if node.IsTitleblock && node.Level >= 3 {
mr.leader = append(mr.leader, append(bytes.Repeat([]byte{'#'}, node.Level), ' '))
} else if !node.IsTitleblock {
Expand Down
5 changes: 1 addition & 4 deletions markdown/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import (
"io"
"log"

blackfriday "github.com/russross/blackfriday/v2"
"github.com/russross/blackfriday/v2"
)

func (mr *markdownRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
switch node.Type {
case blackfriday.Document:
if !entering {
mr.doubleSpace(nil)
}
break
case blackfriday.BlockQuote:
mr.BlockQuote(mr.buf, node, entering)
Expand Down

0 comments on commit 3cd4054

Please sign in to comment.