@@ -22,19 +22,36 @@ const theURL = "https://raw.githubusercontent.com/github/docs/main/content/actio
22
22
23
23
var dbg = log .New (io .Discard , "" , log .LstdFlags )
24
24
25
- func getFirstLinkText (n ast.Node , src []byte ) (string , bool ) {
26
- var link ast.Node
25
+ // `Node.Text` method was deprecated. This is alternative to it.
26
+ // https://github.com/yuin/goldmark/issues/471
27
+ func textOf (n ast.Node , src []byte ) string {
28
+ var b strings.Builder
29
+
27
30
ast .Walk (n , func (n ast.Node , entering bool ) (ast.WalkStatus , error ) {
28
31
if ! entering {
29
32
return ast .WalkStop , nil
30
33
}
34
+ if t , ok := n .(* ast.Text ); ok {
35
+ b .Write (t .Value (src ))
36
+ }
37
+ return ast .WalkContinue , nil
38
+ })
39
+
40
+ return b .String ()
41
+ }
31
42
32
- if n .Kind () != ast .KindLink {
33
- return ast .WalkContinue , nil
43
+ func getFirstLinkText (n ast.Node , src []byte ) (string , bool ) {
44
+ var link * ast.Link
45
+ ast .Walk (n , func (n ast.Node , entering bool ) (ast.WalkStatus , error ) {
46
+ if ! entering {
47
+ return ast .WalkStop , nil
34
48
}
35
49
36
- link = n // Found
37
- return ast .WalkStop , nil
50
+ if l , ok := n .(* ast.Link ); ok {
51
+ link = l
52
+ return ast .WalkStop , nil
53
+ }
54
+ return ast .WalkContinue , nil
38
55
})
39
56
40
57
if link == nil {
@@ -43,28 +60,23 @@ func getFirstLinkText(n ast.Node, src []byte) (string, bool) {
43
60
44
61
// Note: All text pieces must be collected. For example the text "pull_request" is pieces of
45
62
// "pull_" and "request" since an underscore is delimiter of italic/bold text.
46
- var b strings.Builder
47
- for c := link .FirstChild (); c != nil ; c = c .NextSibling () {
48
- b .Write (c .Text (src ))
49
- }
50
-
51
- return b .String (), true
63
+ return textOf (link , src ), true
52
64
}
53
65
54
66
func collectCodeSpans (n ast.Node , src []byte ) []string {
55
67
spans := []string {}
56
68
ast .Walk (n , func (n ast.Node , entering bool ) (ast.WalkStatus , error ) {
57
69
kind := n .Kind ()
58
70
if entering && kind == ast .KindCodeSpan {
59
- spans = append (spans , string ( n . Text ( src ) ))
71
+ spans = append (spans , textOf ( n , src ))
60
72
}
61
73
return ast .WalkContinue , nil
62
74
})
63
75
return spans
64
76
}
65
77
66
78
func getWebhookTypes (table ast.Node , src []byte ) ([]string , bool , error ) {
67
- dbg .Printf ("Table: %s " , table . Text ( src ))
79
+ dbg .Println ("Table:" , textOf ( table , src ))
68
80
69
81
sawHeader := false
70
82
for c := table .FirstChild (); c != nil ; c = c .NextSibling () {
@@ -74,7 +86,7 @@ func getWebhookTypes(table ast.Node, src []byte) ([]string, bool, error) {
74
86
sawHeader = true
75
87
76
88
cell := c .FirstChild ()
77
- if string (cell . Text ( src ) ) != "Webhook event payload" {
89
+ if textOf (cell , src ) != "Webhook event payload" {
78
90
dbg .Println (" Skip this table because it is not for Webhook event payload" )
79
91
return nil , false , nil
80
92
}
@@ -95,7 +107,7 @@ func getWebhookTypes(table ast.Node, src []byte) ([]string, bool, error) {
95
107
cell := c .FirstChild ()
96
108
name , ok := getFirstLinkText (cell , src )
97
109
if ! ok {
98
- return nil , false , fmt .Errorf ("\" Webhook event payload\" table was found, but first cell did not contain hook name: %q" , cell . Text ( src ))
110
+ return nil , false , fmt .Errorf ("\" Webhook event payload\" table was found, but first cell did not contain hook name: %q" , textOf ( cell , src ))
99
111
}
100
112
101
113
// Second cell
@@ -138,15 +150,15 @@ Toplevel:
138
150
k := n .Kind ()
139
151
if ! sawAbout {
140
152
// When '## About events that trigger workflows'
141
- if h , ok := n .(* ast.Heading ); ok && h .Level == 2 && string ( h . Text ( src ) ) == "About events that trigger workflows" {
153
+ if h , ok := n .(* ast.Heading ); ok && h .Level == 2 && textOf ( h , src ) == "About events that trigger workflows" {
142
154
sawAbout = true
143
155
dbg .Println ("Found \" About events that trigger workflows\" heading" )
144
156
}
145
157
continue
146
158
}
147
159
148
160
if h , ok := n .(* ast.Heading ); ok && h .Level == 2 {
149
- currentHook = string ( h . Text ( src ) )
161
+ currentHook = textOf ( h , src )
150
162
dbg .Printf ("Found new hook %q\n " , currentHook )
151
163
continue
152
164
}
0 commit comments