Skip to content

feat(links): add smart paste feature#191

Merged
YousefHadder merged 9 commits intomainfrom
feat/smart-paste
Jan 2, 2026
Merged

feat(links): add smart paste feature#191
YousefHadder merged 9 commits intomainfrom
feat/smart-paste

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

Summary

Add a "smart paste" feature to the links module that automatically converts clipboard URLs into markdown links with fetched page titles.

  • Async: Non-blocking fetch using vim.system() (no UI freeze)
  • Configurable: links.smart_paste.enabled option (disabled by default, opt-in)
  • Fallback: Prompts user for title when fetch fails; canceling replaces placeholder with raw URL
  • Trigger: <Plug>(MarkdownPlusSmartPaste) mapping (default: <leader>mp)

How it works

  1. User copies a URL to clipboard
  2. User triggers <leader>mp in a markdown buffer
  3. Placeholder [⏳ Loading...](url) appears immediately
  4. Title is fetched asynchronously via curl
  5. Placeholder updates to [Page Title](url)

Configuration

require("markdown-plus").setup({
  links = {
    smart_paste = {
      enabled = true,   -- Enable smart paste (default: false)
      timeout = 5,      -- Fetch timeout in seconds (default: 5)
    },
  },
})

Requirements

  • curl must be installed
  • Neovim 0.10+ (for vim.system() async API)

Health check (:checkhealth markdown-plus) verifies these requirements when smart paste is enabled.

Changes

  • Add links.smart_paste config types and validation
  • Add lua/markdown-plus/links/smart_paste.lua module
  • Add <Plug>(MarkdownPlusSmartPaste) keymap
  • Add health check for curl and Neovim version
  • Add comprehensive tests for helper functions
  • Add vimdoc documentation

Test plan

  • Run make check - all tests pass
  • Manual testing with various URLs (GitHub, Google, YouTube, etc.)
  • Test failure case (invalid URL prompts for title)
  • Test cancel behavior (replaces with raw URL)
  • Test disabled state (shows warning)
  • Test health check reports curl status

Closes #190

- Add smart_paste module require
- Call smart_paste.setup() in M.setup()
- Add <Plug>(MarkdownPlusSmartPaste) keymap with default <leader>mp
Add comprehensive tests for smart_paste helper functions:
- _is_url: URL detection (http/https, paths, queries, fragments)
- _html_unescape: HTML entity decoding
- _parse_title: HTML title extraction (og:title, twitter:title, <title>)
- Add smart paste feature description to vimdoc
- Add configuration options to config section
- Add <Plug>(MarkdownPlusSmartPaste) to plug mappings
- Add smart_paste API documentation
- Add curl health check for smart paste feature
- Minor stylua formatting in validate.lua
Some sites (like lua.org) use uppercase <TITLE> tags. The title
extraction pattern now handles any case combination.

Add tests for uppercase and mixed-case title tags.
Copilot AI review requested due to automatic review settings December 31, 2025 01:55
Copy link
Copy Markdown
Contributor

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 PR adds a smart paste feature to the links module that automatically converts clipboard URLs into markdown links by asynchronously fetching their page titles. The feature is opt-in (disabled by default) and includes comprehensive helper function tests, configuration validation, health checks, and documentation.

Key changes:

  • Asynchronous title fetching using vim.system() with curl and HTML parsing for og:title, twitter:title, and <title> tags
  • User fallback prompts when title fetch fails, with option to cancel and insert raw URL
  • Configuration options for enabling the feature and setting fetch timeout

Reviewed changes

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

Show a summary per file
File Description
lua/markdown-plus/types.lua Adds type definitions for links and smart_paste configuration
lua/markdown-plus/config/validate.lua Adds validation for links.smart_paste config including positive timeout check
lua/markdown-plus/links/smart_paste.lua Core implementation with HTML parsing, async fetching, and placeholder management
lua/markdown-plus/links/init.lua Integrates smart_paste module and sets up keymaps
lua/markdown-plus/init.lua Adds default configuration for smart_paste (disabled by default, 5s timeout)
lua/markdown-plus/health.lua Adds health checks for curl availability and Neovim 0.10+ version requirement
spec/markdown-plus/links_spec.lua Adds comprehensive unit tests for helper functions (_is_url, _html_unescape, _parse_title)
doc/markdown-plus.txt Documents smart paste feature, configuration, usage, and requirements

- Add buffer modifiability check before initial placeholder insertion
- Add buffer modifiability check in cancel path of prompt_for_title
- Handle URLs with special characters (parentheses, spaces) by wrapping
  in angle brackets per markdown spec
- Add url_needs_brackets and format_url_for_markdown helper functions
- Add 13 new tests for URL formatting helpers
@YousefHadder YousefHadder merged commit 642a338 into main Jan 2, 2026
15 checks passed
@YousefHadder YousefHadder deleted the feat/smart-paste branch January 2, 2026 17:36
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.

[IDEA] markdown smart paste?

2 participants