mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #19294 from mikedanese/link-fix
Auto commit by PR queue bot
This commit is contained in:
commit
9724447456
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -33,11 +34,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func processLink(in string, filePath string) (string, error) {
|
func processLink(in string, filePath string) (string, error) {
|
||||||
var err error
|
var errs []string
|
||||||
out := linkRE.ReplaceAllStringFunc(in, func(in string) string {
|
out := linkRE.ReplaceAllStringFunc(in, func(in string) string {
|
||||||
|
var err error
|
||||||
match := linkRE.FindStringSubmatch(in)
|
match := linkRE.FindStringSubmatch(in)
|
||||||
if match == nil {
|
if match == nil {
|
||||||
err = fmt.Errorf("Detected this line had a link, but unable to parse, %v", in)
|
errs = append(errs, fmt.Sprintf("Detected this line had a link, but unable to parse, %v", in))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// match[0] is the entire expression;
|
// match[0] is the entire expression;
|
||||||
@ -56,8 +58,8 @@ func processLink(in string, filePath string) (string, error) {
|
|||||||
|
|
||||||
u, terr := url.Parse(linkText)
|
u, terr := url.Parse(linkText)
|
||||||
if terr != nil {
|
if terr != nil {
|
||||||
err = fmt.Errorf("link %q is unparsable: %v", linkText, terr)
|
errs = append(errs, fmt.Sprintf("link %q is unparsable: %v", linkText, terr))
|
||||||
return ""
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Host != "" && u.Host != "github.com" {
|
if u.Host != "" && u.Host != "github.com" {
|
||||||
@ -69,8 +71,8 @@ func processLink(in string, filePath string) (string, error) {
|
|||||||
if u.Path != "" && !strings.HasPrefix(linkText, "TODO:") {
|
if u.Path != "" && !strings.HasPrefix(linkText, "TODO:") {
|
||||||
newPath, targetExists := checkPath(filePath, path.Clean(u.Path))
|
newPath, targetExists := checkPath(filePath, path.Clean(u.Path))
|
||||||
if !targetExists {
|
if !targetExists {
|
||||||
err = fmt.Errorf("%q: target not found", linkText)
|
errs = append(errs, fmt.Sprintf("%q: target not found", linkText))
|
||||||
return ""
|
return in
|
||||||
}
|
}
|
||||||
u.Path = newPath
|
u.Path = newPath
|
||||||
if strings.HasPrefix(u.Path, "/") {
|
if strings.HasPrefix(u.Path, "/") {
|
||||||
@ -87,7 +89,8 @@ func processLink(in string, filePath string) (string, error) {
|
|||||||
dir := path.Dir(filePath)
|
dir := path.Dir(filePath)
|
||||||
suggestedVisibleText, err = makeRepoRelative(path.Join(dir, u.Path), filePath)
|
suggestedVisibleText, err = makeRepoRelative(path.Join(dir, u.Path), filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
errs = append(errs, fmt.Sprintf("%q: unable to make path relative", filePath))
|
||||||
|
return in
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
suggestedVisibleText = u.Path
|
suggestedVisibleText = u.Path
|
||||||
@ -109,8 +112,8 @@ func processLink(in string, filePath string) (string, error) {
|
|||||||
|
|
||||||
return fmt.Sprintf("[%s](%s)", visibleText, linkText+altText)
|
return fmt.Sprintf("[%s](%s)", visibleText, linkText+altText)
|
||||||
})
|
})
|
||||||
if out == "" {
|
if len(errs) != 0 {
|
||||||
return in, err
|
return "", errors.New(strings.Join(errs, ","))
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user