mirror of
https://github.com/golang/go
synced 2024-09-28 23:14:38 -06:00
go/doc/comment: support links in lists in comments
The proposed (#51082) new go doc comment additions supports lists, links, and doc links, but does not support links and doc links inside lists, so implemnent this. Fixes #53610 Change-Id: I4fa17d204fc9efa8f3633133e4a49e56cf1aa9bc Reviewed-on: https://go-review.googlesource.com/c/go/+/415174 Reviewed-by: Ben Golightly <golightly.ben@googlemail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
af725f4286
commit
aad9382e59
@ -326,6 +326,13 @@ func (p *Parser) Parse(text string) *Doc {
|
|||||||
switch b := b.(type) {
|
switch b := b.(type) {
|
||||||
case *Paragraph:
|
case *Paragraph:
|
||||||
b.Text = d.parseLinkedText(string(b.Text[0].(Plain)))
|
b.Text = d.parseLinkedText(string(b.Text[0].(Plain)))
|
||||||
|
case *List:
|
||||||
|
for _, i := range b.Items {
|
||||||
|
for _, c := range i.Content {
|
||||||
|
p := c.(*Paragraph)
|
||||||
|
p.Text = d.parseLinkedText(string(p.Text[0].(Plain)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/go/doc/comment/testdata/linklist.txt
vendored
Normal file
18
src/go/doc/comment/testdata/linklist.txt
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{"DocLinkBaseURL": "https://pkg.go.dev"}
|
||||||
|
-- input --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- [encoding/json.Marshal] is a doc link. So is [encoding/json.Unmarshal].
|
||||||
|
-- text --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- encoding/json.Marshal is a doc link. So is encoding/json.Unmarshal.
|
||||||
|
-- markdown --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- [encoding/json.Marshal](https://pkg.go.dev/encoding/json#Marshal) is a doc link. So is [encoding/json.Unmarshal](https://pkg.go.dev/encoding/json#Unmarshal).
|
||||||
|
-- html --
|
||||||
|
<p>Did you know?
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://pkg.go.dev/encoding/json#Marshal">encoding/json.Marshal</a> is a doc link. So is <a href="https://pkg.go.dev/encoding/json#Unmarshal">encoding/json.Unmarshal</a>.
|
||||||
|
</ul>
|
39
src/go/doc/comment/testdata/linklist2.txt
vendored
Normal file
39
src/go/doc/comment/testdata/linklist2.txt
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{"DocLinkBaseURL": "https://pkg.go.dev"}
|
||||||
|
-- input --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- [testing.T] is one doc link.
|
||||||
|
- So is [testing.M].
|
||||||
|
- So is [testing.B].
|
||||||
|
This is the same list paragraph.
|
||||||
|
|
||||||
|
There is [testing.PB] in this list item, too!
|
||||||
|
-- text --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- testing.T is one doc link.
|
||||||
|
|
||||||
|
- So is testing.M.
|
||||||
|
|
||||||
|
- So is testing.B. This is the same list paragraph.
|
||||||
|
|
||||||
|
There is testing.PB in this list item, too!
|
||||||
|
-- markdown --
|
||||||
|
Did you know?
|
||||||
|
|
||||||
|
- [testing.T](https://pkg.go.dev/testing#T) is one doc link.
|
||||||
|
|
||||||
|
- So is [testing.M](https://pkg.go.dev/testing#M).
|
||||||
|
|
||||||
|
- So is [testing.B](https://pkg.go.dev/testing#B). This is the same list paragraph.
|
||||||
|
|
||||||
|
There is [testing.PB](https://pkg.go.dev/testing#PB) in this list item, too!
|
||||||
|
-- html --
|
||||||
|
<p>Did you know?
|
||||||
|
<ul>
|
||||||
|
<li><p><a href="https://pkg.go.dev/testing#T">testing.T</a> is one doc link.
|
||||||
|
<li><p>So is <a href="https://pkg.go.dev/testing#M">testing.M</a>.
|
||||||
|
<li><p>So is <a href="https://pkg.go.dev/testing#B">testing.B</a>.
|
||||||
|
This is the same list paragraph.
|
||||||
|
<p>There is <a href="https://pkg.go.dev/testing#PB">testing.PB</a> in this list item, too!
|
||||||
|
</ul>
|
31
src/go/doc/comment/testdata/linklist3.txt
vendored
Normal file
31
src/go/doc/comment/testdata/linklist3.txt
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{"DocLinkBaseURL": "https://pkg.go.dev"}
|
||||||
|
-- input --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- [Go]
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
[Go]: https://go.dev/
|
||||||
|
-- text --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- Go
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
[Go]: https://go.dev/
|
||||||
|
-- markdown --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- [Go](https://go.dev/)
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
-- html --
|
||||||
|
<p>Cool things:
|
||||||
|
<ul>
|
||||||
|
<li>Foo
|
||||||
|
<li><a href="https://go.dev/">Go</a>
|
||||||
|
<li>Bar
|
||||||
|
</ul>
|
36
src/go/doc/comment/testdata/linklist4.txt
vendored
Normal file
36
src/go/doc/comment/testdata/linklist4.txt
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{"DocLinkBaseURL": "https://pkg.go.dev"}
|
||||||
|
-- input --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
- [Go] is great
|
||||||
|
|
||||||
|
[Go]: https://go.dev/
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
-- text --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
|
||||||
|
- Go is great
|
||||||
|
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
[Go]: https://go.dev/
|
||||||
|
-- markdown --
|
||||||
|
Cool things:
|
||||||
|
|
||||||
|
- Foo
|
||||||
|
|
||||||
|
- [Go](https://go.dev/) is great
|
||||||
|
|
||||||
|
- Bar
|
||||||
|
|
||||||
|
-- html --
|
||||||
|
<p>Cool things:
|
||||||
|
<ul>
|
||||||
|
<li><p>Foo
|
||||||
|
<li><p><a href="https://go.dev/">Go</a> is great
|
||||||
|
<li><p>Bar
|
||||||
|
</ul>
|
Loading…
Reference in New Issue
Block a user