Skip to content

Commit 2326923

Browse files
committed
Remove deprecated node.Text references
1 parent ee57423 commit 2326923

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

internal/mdplain/renderer.go

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,51 @@ func (r *TextRender) Render(w io.Writer, source []byte, n ast.Node) error {
2626
}
2727

2828
switch node := node.(type) {
29-
case *ast.Blockquote, *ast.Heading:
29+
case *ast.Blockquote, *ast.CodeSpan:
30+
return ast.WalkContinue, nil
31+
case *ast.Heading, *ast.CodeBlock, *ast.List:
3032
doubleSpace(out)
31-
out.Write(node.Text(source))
32-
return ast.WalkSkipChildren, nil
33+
return ast.WalkContinue, nil
3334
case *ast.ThematicBreak:
3435
doubleSpace(out)
3536
return ast.WalkSkipChildren, nil
36-
case *ast.CodeBlock:
37-
doubleSpace(out)
38-
for i := 0; i < node.Lines().Len(); i++ {
39-
line := node.Lines().At(i)
40-
out.Write(line.Value(source))
41-
}
42-
return ast.WalkSkipChildren, nil
4337
case *ast.FencedCodeBlock:
4438
doubleSpace(out)
4539
doubleSpace(out)
46-
for i := 0; i < node.Lines().Len(); i++ {
47-
line := node.Lines().At(i)
48-
_, _ = out.Write(line.Value(source))
49-
}
50-
return ast.WalkSkipChildren, nil
51-
case *ast.List:
52-
doubleSpace(out)
40+
out.Write(node.Lines().Value(source))
5341
return ast.WalkContinue, nil
5442
case *ast.Paragraph:
5543
doubleSpace(out)
56-
if node.Text(source)[0] == '|' { // Write tables as-is.
57-
for i := 0; i < node.Lines().Len(); i++ {
58-
line := node.Lines().At(i)
59-
out.Write(line.Value(source))
60-
}
44+
if node.Lines().Value(source)[0] == '|' { // Write tables as-is.
45+
out.Write(node.Lines().Value(source))
6146
return ast.WalkSkipChildren, nil
6247
}
6348
return ast.WalkContinue, nil
6449
case *extAST.Strikethrough:
65-
out.Write(node.Text(source))
50+
out.Write(node.Lines().Value(source))
6651
return ast.WalkContinue, nil
6752
case *ast.AutoLink:
6853
out.Write(node.URL(source))
6954
return ast.WalkSkipChildren, nil
70-
case *ast.CodeSpan:
71-
out.Write(node.Text(source))
72-
return ast.WalkSkipChildren, nil
7355
case *ast.Link:
74-
_, err := out.Write(node.Text(source))
56+
// we want to write the text of the
57+
// link before the url
58+
child := node.FirstChild()
59+
if child != nil {
60+
t, ok := child.(*ast.Text)
61+
if ok {
62+
out.Write(t.Value(source))
63+
}
64+
}
65+
7566
if !isRelativeLink(node.Destination) {
7667
out.WriteString(" ")
7768
out.Write(node.Destination)
7869
}
79-
return ast.WalkSkipChildren, err
70+
71+
return ast.WalkSkipChildren, nil
8072
case *ast.Text:
81-
out.Write(node.Text(source))
73+
out.Write(node.Value(source))
8274
if node.SoftLineBreak() {
8375
doubleSpace(out)
8476
}

internal/provider/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (m *migrator) ExtractCodeExamples(content []byte, newRelDir string, templat
296296
if fencedNode, isFenced := node.(*ast.FencedCodeBlock); isFenced && fencedNode.Info != nil {
297297
var ext, exampleName, examplePath, template string
298298

299-
lang := string(fencedNode.Info.Text(content)[:])
299+
lang := string(fencedNode.Info.Value(content)[:])
300300
switch lang {
301301
case "hcl", "terraform":
302302
exampleCount++

0 commit comments

Comments
 (0)