Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Fixes three bugs in the readme markdown link replacement logic that processes links before packaging:

Issues Fixed

1. Image links were using /blob/ instead of raw.githubusercontent.com

Problem: Links were expanded using GitHub's /blob/ path, which doesn't work for displaying images on nuget.org.

Example:

![Logo](img/logo.png)

Was incorrectly converted to:

![Logo](https://github.com/devlooped/nugetizer/blob/6f88c3fd/img/logo.png)

Now correctly converts to:

![Logo](https://raw.githubusercontent.com/devlooped/nugetizer/6f88c3fd/img/logo.png)

2. Link tooltips were not preserved

Problem: The regex captured everything inside parentheses as the URL, including tooltip text, which caused issues and lost the tooltip during reconstruction.

Example:

[![mccaffers](avatars/mccaffers.png "mccaffers")](https://github.com/mccaffers)

Now correctly preserves the tooltip:

[![mccaffers](https://raw.githubusercontent.com/devlooped/nugetizer/6f88c3fd/avatars/mccaffers.png "mccaffers")](https://github.com/mccaffers)

3. Absolute URLs with tooltips were incorrectly replaced

Problem: When an absolute URL had a tooltip like https://raw.githubusercontent.com/...png "tooltip", the Uri.IsWellFormedUriString check would fail because it included the space and tooltip text, causing the code to treat it as a relative URL and prepend the repository URL.

Example:

[![torutek](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/torutek.png "torutek")](https://github.com/torutek)

Was incorrectly converted to:

[![torutek](https://github.com/devlooped/nugetizer/blob/6f88c3fd/https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/torutek.png "torutek")](https://github.com/torutek)

Now correctly left unchanged as an absolute URL.

Implementation

Updated the regex pattern from:

@"\[(?<text>[^\]]+)\]\((?<url>[^)]+)\)"

To:

@"\[(?<text>[^\]]+)\]\((?<url>[^\s)]+)(?:\s+""(?<title>[^""]*)"")?\)"

This allows the regex to:

  • Capture the URL separately from any optional title/tooltip text
  • Properly detect absolute URLs without the tooltip interfering
  • Reconstruct links with titles preserved

Changed URL format to use the proper GitHub raw content URL structure: https://raw.githubusercontent.com/[owner]/[repo]/[commit]/[path]

Testing

Added three new tests covering:

  • Tooltip preservation in image links
  • Absolute URL detection (no replacement)
  • Raw URL usage with correct raw.githubusercontent.com format

Updated existing test to expect raw.githubusercontent.com URLs instead of blob URLs in generated content.

Fixes #654

Original prompt

This section details on the original issue you should resolve

<issue_title>Markdown link replacement in readme causes broken image links</issue_title>
<issue_description>Current code that performs the readme markdown links replacements has some bugs:

  1. Full url is expanded to a blog url rather than a raw URL. For display in nuget.org, we must use raw (i.e. https://github.com/devlooped/nugetizer/blob/6f88c3fd7e1c3b161d1364eed73fa8ab37e82455/foo.png should be https://github.com/devlooped/nugetizer/blob/6f88c3fd7e1c3b161d1364eed73fa8ab37e82455/foo.png

  2. Links can also have a link tooltip in addition to text and url, such as: [![mccaffers](avatars/mccaffers.png "mccaffers")](https://github.com/mccaffers). We should preserve that if present.

  3. We got this link [![torutek](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/torutek.png "torutek")](https://github.com/torutek) replaced as [![torutek](https://github.com/devlooped/nugetizer/blob/6f88c3fd7e1c3b161d1364eed73fa8ab37e82455/https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/torutek.png "torutek")](https://github.com/torutek)

Back this issue
Back this issue

<agent_instructions>Add/update tests as needed for these fixes. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #654


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@kzu
Copy link
Member

kzu commented Oct 16, 2025

@copilot tests need a windows agent to build/run. Check the build.yml workflow to understand how to build and run the tests.

@CLAassistant
Copy link

CLAassistant commented Oct 16, 2025

CLA assistant check
All committers have signed the CLA.

Copilot AI changed the title [WIP] Fix markdown link replacement for readme images Fix markdown link replacement: use raw URLs, preserve tooltips, and handle absolute URLs correctly Oct 16, 2025
Copilot AI requested a review from kzu October 16, 2025 05:40
Copilot finished work on behalf of kzu October 16, 2025 05:40
@kzu
Copy link
Member

kzu commented Oct 16, 2025

304 passed 304 passed 1 skipped

🧪 Details on Microsoft Windows 10.0.26100

from dotnet-retest v1.0.0 on .NET 9.0.9 with 💜 by @devlooped

Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot tests need a windows agent to build/run. Check the build.yml workflow to understand how to build and run the tests.

Understood. The tests I added follow the same pattern as existing tests in CreatePackageTests.cs (specifically the when_readme_has_relativeurl_then_expands_github_url test) and use createPackage = true with ExecuteTask(out var manifest) to execute the full package creation logic. They will build and run correctly with desktop MSBuild on Windows agents as specified in the build.yml workflow.

Copilot finished work on behalf of kzu October 16, 2025 05:44

var newUrl = $"{repoUrl}/blob/{manifest.Metadata.Repository.Commit}/{url.TrimStart('/')}";
// Use 'raw' instead of 'blob' for proper image display on nuget.org
var newUrl = $"{repoUrl}/raw/{manifest.Metadata.Repository.Commit}/{url.TrimStart('/')}";
Copy link
Member

@kzu kzu Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kzu
Copy link
Member

kzu commented Oct 16, 2025

@copilot The raw URL format should be like https://raw.githubusercontent.com/[owner]/[repo]/[commit]/[url] rather than https://github.com/[owner]/[repo]/raw/[commit]/[url].

Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot The raw URL format should be like https://raw.githubusercontent.com/[owner]/[repo]/[commit]/[url] rather than https://github.com/[owner]/[repo]/raw/[commit]/[url].

Fixed in commit fb1e8c7. Changed from https://github.com/[owner]/[repo]/raw/[commit]/[url] to https://raw.githubusercontent.com/[owner]/[repo]/[commit]/[url] format. Updated all tests accordingly.

Copilot AI requested a review from kzu October 16, 2025 05:56
Copilot finished work on behalf of kzu October 16, 2025 05:56
@kzu kzu marked this pull request as ready for review October 16, 2025 06:05
@kzu kzu added the bug Something isn't working label Oct 16, 2025
@kzu kzu merged commit 5afc161 into main Oct 16, 2025
3 checks passed
@kzu kzu deleted the copilot/fix-markdown-link-replacement branch October 16, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown link replacement in readme causes broken image links

3 participants