-
Notifications
You must be signed in to change notification settings - Fork 9
feat(markdown): hide duplicate link destinations #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kocaemre
wants to merge
1
commit into
mochow13:main
Choose a base branch
from
kocaemre:feat/markdown-link-rendering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.ai-interactions/tasks/issue-76-markdown-links/output-1_implementation-summary.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Plan and implementation summary: | ||
|
|
||
| 1. Reproduced the issue with failing tests in internal/cli/repl/markdown/hyperlink_test.go: | ||
| - A relative Markdown link like [internal/cli/repl/repl.go:413](/internal/cli/repl/repl.go#L413) should not show the destination. | ||
| - An external Markdown link like [docs](https://example.com/docs) should keep the URL as the OSC 8 target while hiding it from visible text. | ||
|
|
||
| 2. Added a small Markdown link rewrite layer in internal/cli/repl/markdown/links.go: | ||
| - Relative destinations and anchors are rewritten to label-only Markdown before rendering. | ||
| - External http/https Markdown links are rewritten to label-only Markdown and recorded. | ||
| - After Glamour renders the label, the rendered label is wrapped once with OSC 8 escapes. | ||
|
|
||
| 3. Preserved existing bare URL behavior by leaving bare URLs untouched and continuing to run makeURLsClickable after Markdown link processing. | ||
|
|
||
| 4. Verified with targeted markdown tests, broader REPL tests, gofmt, go mod tidy, and the repository-required race test command. |
14 changes: 14 additions & 0 deletions
14
.ai-interactions/tasks/issue-76-markdown-links/prompt-1_issue-76-markdown-links.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| User prompt: Continue the OSS PR sprint by implementing a focused fix for mochow13/keen-code issue #76, "Render Markdown links without duplicate destinations". | ||
|
|
||
| Requirements from the issue: | ||
| - Relative repository source references and anchors should display their label only. | ||
| - External http/https Markdown links should render the label as an OSC 8 terminal hyperlink without printing a duplicate destination. | ||
| - Bare URLs should retain existing behavior. | ||
| - Add focused tests for relative source references and external URLs. | ||
|
|
||
| Repository instructions followed: | ||
| - Minimal comments only when strictly necessary. | ||
| - Run gofmt on modified Go files. | ||
| - Run go mod tidy after the change. | ||
| - Run go test -race ./... after finalising the change. | ||
| - Include interaction files under .ai-interactions/tasks/. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package markdown | ||
|
|
||
| import "strings" | ||
|
|
||
| type markdownLink struct { | ||
| label string | ||
| dest string | ||
| } | ||
|
|
||
| func rewriteMarkdownLinks(markdown string) (string, []markdownLink) { | ||
| if !strings.Contains(markdown, "](") { | ||
| return markdown, nil | ||
| } | ||
|
|
||
| var links []markdownLink | ||
| var b strings.Builder | ||
| b.Grow(len(markdown)) | ||
| for i := 0; i < len(markdown); { | ||
| if markdown[i] != '[' { | ||
| b.WriteByte(markdown[i]) | ||
| i++ | ||
| continue | ||
| } | ||
|
|
||
| labelEnd := strings.Index(markdown[i+1:], "](") | ||
| if labelEnd == -1 { | ||
| b.WriteByte(markdown[i]) | ||
| i++ | ||
| continue | ||
| } | ||
| labelEnd += i + 1 | ||
| destStart := labelEnd + 2 | ||
| destEnd := strings.IndexByte(markdown[destStart:], ')') | ||
| if destEnd == -1 { | ||
| b.WriteByte(markdown[i]) | ||
| i++ | ||
| continue | ||
| } | ||
| destEnd += destStart | ||
|
|
||
| label := markdown[i+1 : labelEnd] | ||
| dest := markdown[destStart:destEnd] | ||
| switch { | ||
| case strings.HasPrefix(dest, "http://") || strings.HasPrefix(dest, "https://"): | ||
| links = append(links, markdownLink{label: label, dest: dest}) | ||
| b.WriteString(label) | ||
| case isRelativeMarkdownLink(dest): | ||
| b.WriteString(label) | ||
| default: | ||
| b.WriteString(markdown[i : destEnd+1]) | ||
| } | ||
| i = destEnd + 1 | ||
| } | ||
|
|
||
| return b.String(), links | ||
| } | ||
|
|
||
| func makeMarkdownLinksClickable(rendered string, links []markdownLink) string { | ||
| for _, link := range links { | ||
| if link.label == "" || link.dest == "" { | ||
| continue | ||
| } | ||
| rendered = strings.Replace(rendered, link.label, osc8Open+link.dest+osc8ST+link.label+osc8Close, 1) | ||
| } | ||
| return rendered | ||
| } | ||
|
|
||
| func isRelativeMarkdownLink(dest string) bool { | ||
| if dest == "" { | ||
| return false | ||
| } | ||
| if strings.HasPrefix(dest, "#") || strings.HasPrefix(dest, "/") || strings.HasPrefix(dest, "./") || strings.HasPrefix(dest, "../") { | ||
| return true | ||
| } | ||
| return !strings.Contains(dest, ":") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to make arbitrary markdown links clickable. Only making URLs clickable is the desired behaviour.