Skip to content

Commit 99faef7

Browse files
committed
remove workaround on iterating texts in TableCell for context
availability code generation
1 parent e150502 commit 99faef7

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

scripts/generate-availability/main.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ const theURL = "https://raw.githubusercontent.com/github/docs/main/content/actio
2626
var dbg = log.New(io.Discard, "", log.LstdFlags)
2727
var reReplaceholder = regexp.MustCompile("{%[^%]+%}")
2828

29-
// `ast.Walk` doesn't work for `TableCell`'s children.
30-
func buildTextOf(n ast.Node, src []byte, b *strings.Builder) {
31-
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
32-
if t, ok := c.(*ast.Text); ok {
33-
b.Write(t.Value(src))
34-
} else {
35-
buildTextOf(c, src, b)
36-
}
37-
}
38-
}
39-
4029
// `Node.Text` method was deprecated. This is alternative to it.
4130
// https://github.com/yuin/goldmark/issues/471
4231
func textOf(n ast.Node, src []byte) string {
4332
var b strings.Builder
44-
buildTextOf(n, src, &b)
33+
ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
34+
if entering {
35+
if t, ok := n.(*ast.Text); ok {
36+
b.Write(t.Value(src))
37+
}
38+
}
39+
return ast.WalkContinue, nil
40+
})
4541
return b.String()
4642
}
4743

scripts/generate-webhook-events/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func textOf(n ast.Node, src []byte) string {
2929

3030
ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
3131
if !entering {
32-
return ast.WalkStop, nil
32+
return ast.WalkContinue, nil
3333
}
3434
if t, ok := n.(*ast.Text); ok {
3535
b.Write(t.Value(src))
@@ -44,7 +44,7 @@ func getFirstLinkText(n ast.Node, src []byte) (string, bool) {
4444
var link *ast.Link
4545
ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
4646
if !entering {
47-
return ast.WalkStop, nil
47+
return ast.WalkContinue, nil
4848
}
4949

5050
if l, ok := n.(*ast.Link); ok {

0 commit comments

Comments
 (0)