Skip to content

Commit 85b270b

Browse files
committed
Fixes #503
1 parent af6c0b5 commit 85b270b

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

ast/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func (n *HTMLBlock) Dump(source []byte, level int) {
515515
cl := n.ClosureLine
516516
fmt.Printf("%sClosure: \"%s\"\n", indent2, string(cl.Value(source)))
517517
}
518+
fmt.Printf("%sHasBlankPreviousLines: %v\n", indent2, n.HasBlankPreviousLines())
518519
fmt.Printf("%s}\n", indent)
519520
}
520521

ast_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
. "github.com/yuin/goldmark"
8+
"github.com/yuin/goldmark/ast"
89
"github.com/yuin/goldmark/testutil"
910
"github.com/yuin/goldmark/text"
1011
)
@@ -202,3 +203,92 @@ func TestASTInlineNodeText(t *testing.T) {
202203
}
203204

204205
}
206+
207+
func TestHasBlankPreviousLines(t *testing.T) {
208+
var cases = []struct {
209+
Name string
210+
Source string
211+
Node func(n ast.Node) ast.Node
212+
Expected bool
213+
}{
214+
{
215+
Name: "nesting paragraphs in blockquotes",
216+
Source: `
217+
> a
218+
>
219+
> b
220+
`,
221+
Node: func(n ast.Node) ast.Node {
222+
return n.FirstChild().FirstChild().NextSibling()
223+
},
224+
Expected: true,
225+
},
226+
{
227+
Name: "nesting HTML blocks in blockquotes",
228+
Source: `
229+
> <!-- a -->
230+
>
231+
> <!-- b -->
232+
`,
233+
Node: func(n ast.Node) ast.Node {
234+
return n.FirstChild().FirstChild().NextSibling()
235+
},
236+
Expected: true,
237+
},
238+
{
239+
Name: "nesting HTML blocks in blockquotes",
240+
Source: `
241+
> <!-- a -->
242+
> <!-- b -->
243+
`,
244+
Node: func(n ast.Node) ast.Node {
245+
return n.FirstChild().FirstChild().NextSibling()
246+
},
247+
Expected: false,
248+
},
249+
{
250+
Name: "nesting loose lists in blockquotes",
251+
Source: `
252+
> - a
253+
>
254+
> - b
255+
`,
256+
Node: func(n ast.Node) ast.Node {
257+
return n.FirstChild().FirstChild().FirstChild().NextSibling()
258+
},
259+
Expected: true,
260+
},
261+
{
262+
Name: "nesting tight lists in blockquotes",
263+
Source: `
264+
> - a
265+
> - b
266+
`,
267+
Node: func(n ast.Node) ast.Node {
268+
return n.FirstChild().FirstChild().FirstChild().NextSibling()
269+
},
270+
Expected: false,
271+
},
272+
{
273+
Name: "nesting paragraphs in lists",
274+
Source: `
275+
- a
276+
277+
b
278+
`,
279+
Node: func(n ast.Node) ast.Node {
280+
return n.FirstChild().FirstChild().FirstChild().NextSibling()
281+
},
282+
Expected: true,
283+
},
284+
}
285+
md := New()
286+
for _, cs := range cases {
287+
t.Run(cs.Name, func(t *testing.T) {
288+
n := md.Parser().Parse(text.NewReader([]byte(cs.Source)))
289+
if cs.Node(n).HasBlankPreviousLines() != cs.Expected {
290+
t.Errorf("expected %v, got %v", cs.Expected, !cs.Expected)
291+
}
292+
})
293+
}
294+
}

parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) {
10961096
// When current node is a container block and has no children,
10971097
// we try to open new child nodes
10981098
if state&HasChildren != 0 && i == lastIndex {
1099-
isBlank = isBlankLine(lineNum-1, i, blankLines)
1099+
isBlank = isBlankLine(lineNum-1, i+1, blankLines)
11001100
p.openBlocks(be.Node, isBlank, reader, pc)
11011101
break
11021102
}

0 commit comments

Comments
 (0)