Skip to content

Add URL to Link conversion feature with toLink function#27

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-26
Draft

Add URL to Link conversion feature with toLink function#27
Copilot wants to merge 2 commits intomainfrom
copilot/fix-26

Conversation

Copy link

Copilot AI commented Jun 17, 2025

This PR implements URL to Link conversion functionality following the CommonMark specification for links. The feature adds a new toLink function that converts URLs to properly formatted Markdown links.

Features Added

  • toLink(url: string) - Converts a URL to a markdown link using the URL as both text and destination
  • toLink(text: string, url: string) - Converts to a markdown link with custom text and URL destination

Usage Examples

import { toLink } from 'x2md';

// URL as both text and destination
const link1 = toLink('https://example.com'); 
// → "[https://example.com](https://example.com)"

const link2 = toLink('mailto:user@example.com'); 
// → "[mailto:user@example.com](mailto:user@example.com)"

// Custom text with URL destination
const link3 = toLink('Example Website', 'https://example.com'); 
// → "[Example Website](https://example.com)"

const link4 = toLink('Contact Us', 'mailto:support@example.com'); 
// → "[Contact Us](mailto:support@example.com)"

Implementation Details

  • Follows the CommonMark link specification
  • Uses function overloading with optional parameters for flexible usage
  • Maintains consistency with existing codebase patterns
  • Includes comprehensive TypeScript documentation and examples
  • Supports various URL schemes (https, http, mailto, ftp, file, etc.)
  • Handles edge cases like empty strings, special characters, and relative URLs

Testing

  • Added 23 comprehensive test cases covering all functionality
  • Tests edge cases including empty strings, special characters, and various URL formats
  • Maintains 100% test coverage
  • All existing tests continue to pass

Code Quality

  • Passes all linting rules
  • Follows existing code style and documentation patterns
  • Properly exported through main index.ts
  • Updated index tests to verify export availability

Fixes #26.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • spec.commonmark.org
    • Triggering command: curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link

changeset-bot bot commented Jun 17, 2025

⚠️ No Changeset found

Latest commit: 0f0723d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Co-authored-by: F88 <685250+F88@users.noreply.github.com>
Copilot AI changed the title [WIP] Add features to convert URLs to Links Add URL to Link conversion feature with toLink function Jun 17, 2025
Copilot AI requested a review from F88 June 17, 2025 05:49
Copilot finished work on behalf of F88 June 17, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add features to convert URLs to Links

2 participants