Skip to content

Commit d891f2f

Browse files
authored
passthrough: Upgrade goldmark and fix upstream regression
* passthrough: Upgrade goldmark and fix upstream regression Goldmark v1.7.5 changed the default behaviour of the BaseBlock.Text() function, breaking the block transformer for block math. Later, in Goldmark v1.7.8, the whole Text() function was deprecated. This commit also deprecates PassthroughInline.Text() and removes all calls for Node.Text(), fixing the regression. * passthrough: Add regression test
1 parent ab277a4 commit d891f2f

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

‎passthrough/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ require (
99
github.com/kr/pretty v0.3.1 // indirect
1010
github.com/kr/text v0.2.0 // indirect
1111
github.com/rogpeppe/go-internal v1.12.0 // indirect
12-
github.com/yuin/goldmark v1.7.2
12+
github.com/yuin/goldmark v1.7.8
1313
)

‎passthrough/go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
1212
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1313
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
1414
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
15-
github.com/yuin/goldmark v1.7.2 h1:NjGd7lO7zrUn/A7eKwn5PEOt4ONYGqpxSEeZuduvgxc=
16-
github.com/yuin/goldmark v1.7.2/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
15+
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
16+
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=

‎passthrough/passthrough.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func newPassthroughInline(segment text.Segment, delimiters *Delimiters) *Passthr
4646
}
4747

4848
// Text implements Node.Text.
49+
// Deprecated: Goldmark v1.7.8 deprecates Node.Text
4950
func (n *PassthroughInline) Text(source []byte) []byte {
5051
return n.Segment.Value(source)
5152
}
@@ -55,7 +56,7 @@ func (n *PassthroughInline) Dump(source []byte, level int) {
5556
indent := strings.Repeat(" ", level)
5657
fmt.Printf("%sPassthroughInline {\n", indent)
5758
indent2 := strings.Repeat(" ", level+1)
58-
fmt.Printf("%sSegment: \"%s\"\n", indent2, n.Text(source))
59+
fmt.Printf("%sSegment: \"%s\"\n", indent2, n.Segment.Value(source))
5960
fmt.Printf("%s}\n", indent)
6061
}
6162

@@ -188,7 +189,11 @@ type passthroughInlineRenderer struct{}
188189

189190
func (r *passthroughInlineRenderer) renderRawInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
190191
if entering {
191-
w.WriteString(string(n.Text(source)))
192+
n, ok := n.(*PassthroughInline)
193+
if !ok {
194+
return ast.WalkContinue, nil
195+
}
196+
w.WriteString(string(n.Segment.Value(source)))
192197
}
193198
return ast.WalkContinue, nil
194199
}
@@ -315,7 +320,7 @@ func (p *passthroughInlineTransformer) Transform(
315320

316321
newBlock := newPassthroughBlock(inline.Delimiters)
317322
newBlock.Lines().Append(inline.Segment)
318-
if len(currentParagraph.Text(reader.Source())) > 0 {
323+
if currentParagraph.ChildCount() > 0 {
319324
parent.InsertAfter(parent, insertionPoint, currentParagraph)
320325
// Since we're not removing the original paragraph, we need to ensure
321326
// that this paragraph is not re-processed as the walk continues

‎passthrough/passthrough_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,24 @@ $$a^*=x-b^*$$
567567
c.Assert(actual, qt.Equals, expected)
568568
}
569569

570+
func TestIssue32(t *testing.T) {
571+
input := `line one
572+
$$ a^n + b^n = c^n $$
573+
line two`
574+
575+
// The mid-paragraph new lines are undesirable, but this is how it worked
576+
// with Goldmark v1.7.4.
577+
expected := `<p>line one
578+
</p>
579+
$$ a^n + b^n = c^n $$
580+
<p>
581+
line two</p>`
582+
actual := Parse(t, input)
583+
584+
c := qt.New(t)
585+
c.Assert(actual, qt.Equals, expected)
586+
}
587+
570588
func TestNodeDelimiter(t *testing.T) {
571589
input := `
572590
Block $$a^*=x-b^*$$ equation

0 commit comments

Comments
 (0)