|
6 | 6 | "testing" |
7 | 7 |
|
8 | 8 | "github.com/yuin/goldmark" |
| 9 | + "github.com/yuin/goldmark/ast" |
9 | 10 | "github.com/yuin/goldmark/text" |
10 | 11 |
|
11 | 12 | qt "github.com/frankban/quicktest" |
@@ -54,6 +55,23 @@ func Parse(t *testing.T, input string) string { |
54 | 55 | return strings.TrimSpace(buf.String()) |
55 | 56 | } |
56 | 57 |
|
| 58 | +func ParseWalk(t testing.TB, input string, cb func(n ast.Node, entering bool) bool) { |
| 59 | + t.Helper() |
| 60 | + md := buildTestParser() |
| 61 | + doc := md.Parser().Parse(text.NewReader([]byte(input))) |
| 62 | + err := ast.Walk( |
| 63 | + doc, |
| 64 | + func(n ast.Node, entering bool) (ast.WalkStatus, error) { |
| 65 | + if cb(n, entering) { |
| 66 | + return ast.WalkSkipChildren, nil |
| 67 | + } |
| 68 | + return ast.WalkContinue, nil |
| 69 | + }) |
| 70 | + if err != nil { |
| 71 | + t.Fatal(err) |
| 72 | + } |
| 73 | +} |
| 74 | + |
57 | 75 | func TestEmphasisOutsideOfMathmode(t *testing.T) { |
58 | 76 | input := "Emph: _wow_" |
59 | 77 | expected := "<p>Emph: <em>wow</em></p>" |
@@ -549,6 +567,30 @@ $$a^*=x-b^*$$ |
549 | 567 | c.Assert(actual, qt.Equals, expected) |
550 | 568 | } |
551 | 569 |
|
| 570 | +func TestNodeDelimiter(t *testing.T) { |
| 571 | + input := ` |
| 572 | +Block $$a^*=x-b^*$$ equation |
| 573 | +Inline $a^*=x-b^*$ equation |
| 574 | +
|
| 575 | +` |
| 576 | + |
| 577 | + c := qt.New(t) |
| 578 | + |
| 579 | + ParseWalk(t, input, func(n ast.Node, entering bool) bool { |
| 580 | + if entering { |
| 581 | + switch nn := n.(type) { |
| 582 | + case *PassthroughBlock: |
| 583 | + c.Assert(nn.Delimiters.Open, qt.Equals, "$$") |
| 584 | + c.Assert(nn.Delimiters.Close, qt.Equals, "$$") |
| 585 | + case *PassthroughInline: |
| 586 | + c.Assert(nn.Delimiters.Open, qt.Equals, "$") |
| 587 | + c.Assert(nn.Delimiters.Close, qt.Equals, "$") |
| 588 | + } |
| 589 | + } |
| 590 | + return false |
| 591 | + }) |
| 592 | +} |
| 593 | + |
552 | 594 | func BenchmarkWithAndWithoutPassthrough(b *testing.B) { |
553 | 595 | const input = ` |
554 | 596 | ## Block |
|
0 commit comments