Skip to content

Commit 97a73c2

Browse files
committed
chore: rename link content
1 parent c796f84 commit 97a73c2

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

ast/inline.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ func (n *Image) Restore() string {
109109
type Link struct {
110110
BaseInline
111111

112-
Text []Node
113-
URL string
112+
Content []Node
113+
URL string
114114
}
115115

116116
func (*Link) Type() NodeType {
117117
return LinkNode
118118
}
119119

120120
func (n *Link) Restore() string {
121-
text := ""
122-
for _, child := range n.Text {
123-
text += child.Restore()
121+
content := ""
122+
for _, child := range n.Content {
123+
content += child.Restore()
124124
}
125-
return fmt.Sprintf("[%s](%s)", text, n.URL)
125+
return fmt.Sprintf("[%s](%s)", content, n.URL)
126126
}
127127

128128
type AutoLink struct {

parser/link.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ func (*LinkParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
2424
if rightSquareBracketIndex == -1 {
2525
return nil, 0
2626
}
27-
textTokens := matchedTokens[1 : rightSquareBracketIndex+1]
28-
if tokenizer.FindUnescaped(textTokens, tokenizer.LeftSquareBracket) != -1 {
27+
contentTokens := matchedTokens[1 : rightSquareBracketIndex+1]
28+
if tokenizer.FindUnescaped(contentTokens, tokenizer.LeftSquareBracket) != -1 {
2929
return nil, 0
3030
}
31-
if len(textTokens)+4 >= len(matchedTokens) {
31+
if len(contentTokens)+4 >= len(matchedTokens) {
3232
return nil, 0
3333
}
34-
if matchedTokens[2+len(textTokens)].Type != tokenizer.LeftParenthesis {
34+
if matchedTokens[2+len(contentTokens)].Type != tokenizer.LeftParenthesis {
3535
return nil, 0
3636
}
3737
urlTokens, matched := []*tokenizer.Token{}, false
38-
for _, token := range matchedTokens[3+len(textTokens):] {
38+
for _, token := range matchedTokens[3+len(contentTokens):] {
3939
if token.Type == tokenizer.Space {
4040
return nil, 0
4141
}
@@ -49,13 +49,12 @@ func (*LinkParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
4949
return nil, 0
5050
}
5151

52-
textNodes, err := ParseInlineWithParsers(textTokens, []InlineParser{NewEscapingCharacterParser(), NewTextParser()})
52+
contentNodes, err := ParseInlineWithParsers(contentTokens, []InlineParser{NewEscapingCharacterParser(), NewTextParser()})
5353
if err != nil {
5454
return nil, 0
5555
}
56-
5756
return &ast.Link{
58-
Text: textNodes,
59-
URL: tokenizer.Stringify(urlTokens),
60-
}, 4 + len(textTokens) + len(urlTokens)
57+
Content: contentNodes,
58+
URL: tokenizer.Stringify(urlTokens),
59+
}, 4 + len(contentTokens) + len(urlTokens)
6160
}

parser/tests/link_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func TestLinkParser(t *testing.T) {
1717
{
1818
text: "[](https://example.com)",
1919
node: &ast.Link{
20-
Text: []ast.Node{},
21-
URL: "https://example.com",
20+
Content: []ast.Node{},
21+
URL: "https://example.com",
2222
},
2323
},
2424
{
@@ -32,29 +32,29 @@ func TestLinkParser(t *testing.T) {
3232
{
3333
text: "[your/slash](https://example.com)",
3434
node: &ast.Link{
35-
Text: []ast.Node{&ast.Text{Content: "your/slash"}},
36-
URL: "https://example.com",
35+
Content: []ast.Node{&ast.Text{Content: "your/slash"}},
36+
URL: "https://example.com",
3737
},
3838
},
3939
{
4040
text: "[hello world](https://example.com)",
4141
node: &ast.Link{
42-
Text: []ast.Node{&ast.Text{Content: "hello world"}},
43-
URL: "https://example.com",
42+
Content: []ast.Node{&ast.Text{Content: "hello world"}},
43+
URL: "https://example.com",
4444
},
4545
},
4646
{
4747
text: "[hello world](https://example.com)",
4848
node: &ast.Link{
49-
Text: []ast.Node{&ast.Text{Content: "hello world"}},
50-
URL: "https://example.com",
49+
Content: []ast.Node{&ast.Text{Content: "hello world"}},
50+
URL: "https://example.com",
5151
},
5252
},
5353
{
5454
text: `[\[link\]](https://example.com)`,
5555
node: &ast.Link{
56-
Text: []ast.Node{&ast.EscapingCharacter{Symbol: "["}, &ast.Text{Content: `link`}, &ast.EscapingCharacter{Symbol: "]"}},
57-
URL: "https://example.com",
56+
Content: []ast.Node{&ast.EscapingCharacter{Symbol: "["}, &ast.Text{Content: `link`}, &ast.EscapingCharacter{Symbol: "]"}},
57+
URL: "https://example.com",
5858
},
5959
},
6060
}

renderer/html/html.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (r *HTMLRenderer) renderLink(node *ast.Link) {
277277
r.output.WriteString(`<a href="`)
278278
r.output.WriteString(node.URL)
279279
r.output.WriteString(`">`)
280-
r.RenderNodes(node.Text)
280+
r.RenderNodes(node.Content)
281281
r.output.WriteString("</a>")
282282
}
283283

0 commit comments

Comments
 (0)