Skip to content

Commit ca07402

Browse files
committed
Add PassthroughBlock.Delimiters
1 parent f5d3d00 commit ca07402

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

‎passthrough/passthrough.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ func (r *passthroughInlineRenderer) renderRawInline(w util.BufWriter, source []b
199199
// with the matching block delimiters.
200200
type PassthroughBlock struct {
201201
ast.BaseBlock
202+
// The matched delimiters
203+
Delimiters *Delimiters
202204
}
203205

204206
// Dump implements Node.Dump.
@@ -215,9 +217,10 @@ func (n *PassthroughBlock) Kind() ast.NodeKind {
215217
}
216218

217219
// newPassthroughBlock return a new PassthroughBlock node.
218-
func newPassthroughBlock() *PassthroughBlock {
220+
func newPassthroughBlock(delimiters *Delimiters) *PassthroughBlock {
219221
return &PassthroughBlock{
220-
BaseBlock: ast.BaseBlock{},
222+
Delimiters: delimiters,
223+
BaseBlock: ast.BaseBlock{},
221224
}
222225
}
223226

@@ -310,7 +313,7 @@ func (p *passthroughInlineTransformer) Transform(
310313
continue
311314
}
312315

313-
newBlock := newPassthroughBlock()
316+
newBlock := newPassthroughBlock(inline.Delimiters)
314317
newBlock.Lines().Append(inline.Segment)
315318
if len(currentParagraph.Text(reader.Source())) > 0 {
316319
parent.InsertAfter(parent, insertionPoint, currentParagraph)

‎passthrough/passthrough_test.go‎

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

88
"github.com/yuin/goldmark"
9+
"github.com/yuin/goldmark/ast"
910
"github.com/yuin/goldmark/text"
1011

1112
qt "github.com/frankban/quicktest"
@@ -54,6 +55,23 @@ func Parse(t *testing.T, input string) string {
5455
return strings.TrimSpace(buf.String())
5556
}
5657

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+
5775
func TestEmphasisOutsideOfMathmode(t *testing.T) {
5876
input := "Emph: _wow_"
5977
expected := "<p>Emph: <em>wow</em></p>"
@@ -549,6 +567,30 @@ $$a^*=x-b^*$$
549567
c.Assert(actual, qt.Equals, expected)
550568
}
551569

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+
552594
func BenchmarkWithAndWithoutPassthrough(b *testing.B) {
553595
const input = `
554596
## Block

0 commit comments

Comments
 (0)