From 832d004c9ad644d4d145ef6d0955184e3bef4cd4 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 30 Sep 2024 10:32:27 +0900 Subject: [PATCH] refactor function names for auto ref links --- reflink.go | 13 +++++-------- reflink_test.go | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/reflink.go b/reflink.go index 4073d5b..f339dd4 100644 --- a/reflink.go +++ b/reflink.go @@ -191,9 +191,7 @@ func (l *Reflinker) linkCommitSHA(begin, end int) int { return begin + hashLen } -// DetectLinksInText detects reference links in given markdown text and remembers them to replace all -// references later. -func (l *Reflinker) DetectLinksInText(t *ast.Text) { +func (l *Reflinker) linkGitHubRefs(t *ast.Text) { o := t.Segment.Start // start offset for o < t.Segment.Stop-1 { // `-1` means the last character is not checked @@ -216,7 +214,7 @@ func (l *Reflinker) DetectLinksInText(t *ast.Text) { var reGitHubCommitURL = regexp.MustCompile(`^https://github\.com/([^/]+/[^/]+)/commit/([[:xdigit:]]{7,})`) -func (l *Reflinker) detectGitHubURLInAutoLink(n *ast.AutoLink, src []byte) { +func (l *Reflinker) linkGitHubURL(n *ast.AutoLink, src []byte) { start := 0 p := n.PreviousSibling() if p != nil { @@ -261,8 +259,7 @@ func (l *Reflinker) detectGitHubURLInAutoLink(n *ast.AutoLink, src []byte) { }) } -// BuildLinkedText builds a markdown text where all references are replaced with links. The links were -// detected by DetectLinksInText() method calls. +// BuildLinkedText builds a markdown text linking all references. func (l *Reflinker) BuildLinkedText() string { if len(l.links) == 0 { return string(l.src) @@ -300,10 +297,10 @@ func LinkRefs(input string, repoURL string) string { case *ast.CodeSpan, *ast.Link: return ast.WalkSkipChildren, nil case *ast.AutoLink: - l.detectGitHubURLInAutoLink(n, src) + l.linkGitHubURL(n, src) return ast.WalkSkipChildren, nil case *ast.Text: - l.DetectLinksInText(n) + l.linkGitHubRefs(n) return ast.WalkContinue, nil default: return ast.WalkContinue, nil diff --git a/reflink_test.go b/reflink_test.go index 008e997..253a021 100644 --- a/reflink_test.go +++ b/reflink_test.go @@ -415,8 +415,8 @@ func TestLinkRefs(t *testing.T) { }, { what: "commit URL at end of text", - input: "https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe test", - want: "[`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe) test", + input: "test https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe", + want: "tes [`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)", }, { what: "commit URL with explicit auto link",