Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat: Resolve man:// links #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This neovim plugin allows you to follow markdown links by pressing enter when th
- text-only reference links (e.g. `[example website]. [example website]: https://example.org`)
- web links (e.g. `[wikipedia](https://wikipedia.org)`)
- heading links (e.g. `[chapter 1](#-chapter-1)`
- man page links (e.g. `[printf library](man://printf(3))`)

Local files are opened in neovim and web links are opened with the default browser. Web links need to start with `https://` or `http://` to be identified properly.

Expand Down
5 changes: 5 additions & 0 deletions lua/follow-md-links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ local function resolve_link(link)
elseif link:sub(1, 8) == [[https://]] or link:sub(1, 7) == [[http://]] then
link_type = "web"
return link, link_type
elseif link:sub(1, 6) == [[man://]] then
link_type = "man"
return link, link_type
else
link_type = "local"
return fn.expand("%:p:h") .. [[/]] .. link, link_type
Expand Down Expand Up @@ -151,6 +154,8 @@ function M.follow_link()
follow_local_link(resolved_link)
elseif link_type == "heading" then
follow_heading_link(resolved_link)
elseif link_type == "man" then
vim.cmd.Man(link_destination:gsub("man://", ""))
elseif link_type == "web" then
if is_linux then
vim.fn.system("xdg-open " .. vim.fn.shellescape(resolved_link))
Expand Down