Skip to content

Comments

Auto-link URLs in plain text content#314

Open
pfefferle wants to merge 1 commit intotrunkfrom
fix/303-autolink-urls-in-plain-text
Open

Auto-link URLs in plain text content#314
pfefferle wants to merge 1 commit intotrunkfrom
fix/303-autolink-urls-in-plain-text

Conversation

@pfefferle
Copy link
Member

Summary

  • Uses WordPress's make_clickable() function to automatically convert URLs in plain text content to clickable links
  • Only applies to plain text content, not HTML content which is preserved as-is
  • HTML content with existing links, code blocks, and pre blocks are not modified

Fixes #303

Use WordPress's make_clickable() function to automatically convert
URLs in plain text content to clickable links. This only applies
to plain text content, not HTML content which is preserved as-is.

Fixes #303
@pfefferle pfefferle force-pushed the fix/303-autolink-urls-in-plain-text branch from af535dd to da50f52 Compare January 11, 2026 22:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds automatic URL linking functionality to plain text content submitted via the Micropub endpoint. When users submit posts with plain text content containing URLs, those URLs will now be automatically converted to clickable HTML links using WordPress's make_clickable() function.

Changes:

  • Modified the content processing logic to apply make_clickable() to plain text content after HTML escaping
  • Added comprehensive test coverage for both plain text auto-linking and HTML content preservation scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
includes/rest/class-endpoint-controller.php Updated mp_to_wp() method to apply make_clickable() to plain text content while preserving HTML content as-is
tests/test_endpoint.php Added 6 new test cases covering plain text URL auto-linking, multiple URLs, and verification that HTML content remains unchanged

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -831,7 +831,8 @@ protected function mp_to_wp( $mf2 ) {
$args['post_content'] = $content['html'] ? $content['html'] :
\htmlspecialchars( $content['value'] );
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

When the content array contains HTML with an empty 'html' key (falsy value like empty string or null), this code will fall back to htmlspecialchars of the 'value' field without applying make_clickable. This creates an inconsistency where some plain text content gets auto-linked (line 835) but plain text content coming from the 'value' field in an array doesn't get auto-linked. Consider applying make_clickable to the fallback case as well to ensure consistent behavior.

Suggested change
\htmlspecialchars( $content['value'] );
\make_clickable( \htmlspecialchars( $content['value'] ) );

Copilot uses AI. Check for mistakes.
);
$post = self::check_create( self::create_json_request( $input ) );
// URLs in pre blocks should not be auto-linked.
$this->assertEquals( '<pre>curl https://example.com/api</pre>', $post->post_content );
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

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

Consider adding a test case for content with an array structure where the 'html' key is empty or falsy, forcing fallback to the 'value' field. This would verify that URLs in plain text content are consistently auto-linked regardless of whether content is provided as a string or as an array with a 'value' field.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Auto-link URLs in plain text content

1 participant