Skip to content

Commit

Permalink
Skip go ellipsis as links
Browse files Browse the repository at this point in the history
  • Loading branch information
posener committed Aug 16, 2019
1 parent c390545 commit 5e71e90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/markdown/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func emphasize(w io.Writer, line string, words map[string]string, nice bool) {
}

// If the url ends with a punctuation mark, we will hold it here.
after := make([]byte, 0, 1)
after := ""

if m[2] >= 0 {
// A url
// match against first parenthesized sub-regexp; must be match against urlRx
// A url match against first parenthesized sub-regexp; must be
// match against urlRx.
if !italics {
// no alternative URL in words list, use match instead
url = match
Expand All @@ -124,10 +124,17 @@ func emphasize(w io.Writer, line string, words map[string]string, nice bool) {
}
}

// Skip Go path ellipsis.
if strings.HasSuffix(url, "/...") {
fmt.Fprintf(w, line[1:m[1]])
line = line[m[1]:]
continue
}

// Remove punctuation mark from url/title suffix.
switch url[len(url)-1] {
case '.', ',', ':', ';', '?', '!':
after = append(after, url[len(url)-1])
after = string(url[len(url)-1])
if title[len(title)-1] == url[len(url)-1] {
title = title[:len(title)-1]
}
Expand Down Expand Up @@ -160,7 +167,7 @@ func emphasize(w io.Writer, line string, words map[string]string, nice bool) {
if len(url) > 0 {
fmt.Fprint(w, ")")
}
w.Write(after)
fmt.Fprint(w, after)

// advance
line = line[m[1]:]
Expand Down
1 change: 1 addition & 0 deletions testdata/pkg1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A web page link should just be written as is: [https://goreadme.herokuapp.com](h
A url can also have a [title](http://example.org).
A local path can also have a [title](./pkg.go).
A local path in inline code `go test [./](./)`.
Go path ellipsis (also inline ./...) should not be converted to link ./...

#### Another Section Header

Expand Down
1 change: 1 addition & 0 deletions testdata/pkg1/pkg1.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// A url can also have a (title) http://example.org.
// A local path can also have a (title) ./pkg.go.
// A local path in inline code `go test ./`.
// Go path ellipsis (also inline ./...) should not be converted to link ./...
//
// Another Section Header
//
Expand Down

0 comments on commit 5e71e90

Please sign in to comment.