Skip to content

Commit

Permalink
fix(gengapic): fix linkParser regexp to support multi-line link tags
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzmo committed Aug 4, 2022
1 parent 983315f commit e4cc62c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/gengapic/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"gitlab.com/golang-commonmark/markdown"
)

var linkParser = regexp.MustCompile(`<a href=["'](.+)["']`)
var linkParser = regexp.MustCompile(`<a\s+href=["'](.+)["']`)
var referenceParser = regexp.MustCompile(`\[([a-zA-Z1-9._]+)\]\[[a-zA-Z1-9._]*\]`)

func mdPlain(s string) string {
Expand Down
9 changes: 9 additions & 0 deletions internal/gengapic/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ func TestMDPlain(t *testing.T) {
in: "html <a href=\"/link/to/some#thing\">\n with a softbreak</a> <br> test",
want: "html with a softbreak (at /link/to/some#thing) \n test",
},
{
in: "html <a \n href=\"/link/to/some#thing\">\n with a linebreak in tag</a> <br> test",
want: "html with a linebreak in tag (at /link/to/some#thing) \n test",
},
{
in: "link to [a search engine](https://www.google.com) with request type [Search][foo.bar_baz.v1.Search], [biz][][buz][baz].",
want: "link to a search engine (at https://www.google.com) with request type Search, bizbuz.",
},
} {
defer func() {
if r := recover(); r != nil {
t.Errorf("%s resulted in a panic: %v", tst.in, r)
}
}()
got := mdPlain(tst.in)
if got != tst.want {
t.Errorf("MDPlain(%q)=%q, want %q", tst.in, got, tst.want)
Expand Down

0 comments on commit e4cc62c

Please sign in to comment.