Skip to content

Commit 401a6c9

Browse files
feat: support bare URLs in angle brackets
## Details Request: #244 Bare URLs in angle brackets are parsed by treesitter into a uri_autolink node. Add support for this node type in our link renderer. Use the icon based on the destination. Functions similarly to emails in that the angle brackets are hidden while the link contents are still displayed with the addition of the icon.
1 parent 61850bf commit 401a6c9

File tree

8 files changed

+62
-19
lines changed

8 files changed

+62
-19
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- footnote text superscript rendering [#241](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/241)
88
[634acd5](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/634acd5da964c32f6947cd0c7802d7a116662665)
99
[1b5d117](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/1b5d11734122d9451d2e5e2e567fd61a62822293)
10+
- code border none [#246](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/246)
11+
[f3cda24](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/f3cda24c71261f6a52f5ddafb95786684d862d87)
12+
- expand default custom links [#245](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/245)
13+
[61850bf](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/61850bf7df4af8398e97559a35b62378ba8435b1)
1014

1115
### Bug Fixes
1216

doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 December 02
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 December 03
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/handler/markdown_inline.lua

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function Handler.new(buf)
3131
(full_reference_link)
3232
(image)
3333
(inline_link)
34+
(uri_autolink)
3435
] @link
3536
3637
((inline) @inline_highlight

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.6.5'
7+
M.version = '7.6.6'
88

99
function M.check()
1010
M.start('version')

lua/render-markdown/render/link.lua

+40-7
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,52 @@ function Render:setup()
1818
return false
1919
end
2020

21-
local text, highlight, conceal = self.link.hyperlink, nil, false
2221
if self.node.type == 'email_autolink' then
23-
text, conceal = self.link.email .. self.node.text:sub(2, -2), true
22+
local email = self.node.text:sub(2, -2)
23+
self.data = {
24+
text = self.link.email .. email,
25+
highlight = self.link.highlight,
26+
conceal = true,
27+
}
28+
elseif self.node.type == 'full_reference_link' then
29+
self.data = {
30+
text = self.link.hyperlink,
31+
highlight = self.link.highlight,
32+
conceal = false,
33+
}
2434
elseif self.node.type == 'image' then
25-
text = self.link.image
35+
self.data = {
36+
text = self.link.image,
37+
highlight = self.link.highlight,
38+
conceal = false,
39+
}
2640
elseif self.node.type == 'inline_link' then
2741
local destination = self.node:child('link_destination')
28-
local link_component = destination ~= nil and self:link_component(destination.text) or nil
29-
if link_component ~= nil then
30-
text, highlight = link_component.icon, link_component.highlight
42+
local component = destination ~= nil and self:link_component(destination.text) or nil
43+
local text, highlight = self.link.hyperlink, nil
44+
if component ~= nil then
45+
text, highlight = component.icon, component.highlight
3146
end
47+
self.data = {
48+
text = text,
49+
highlight = highlight or self.link.highlight,
50+
conceal = false,
51+
}
52+
elseif self.node.type == 'uri_autolink' then
53+
local destination = self.node.text:sub(2, -2)
54+
local component = self:link_component(destination)
55+
local text, highlight = self.link.hyperlink, nil
56+
if component ~= nil then
57+
text, highlight = component.icon, component.highlight
58+
end
59+
self.data = {
60+
text = text .. destination,
61+
highlight = highlight or self.link.highlight,
62+
conceal = true,
63+
}
64+
else
65+
return false
3266
end
33-
self.data = { text = text, highlight = highlight or self.link.highlight, conceal = conceal }
3467

3568
return true
3669
end

lua/render-markdown/render/shortcut.lua

+4-6
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ function Render:wiki_link()
9999
end
100100

101101
local parts = Str.split(self.node.text:sub(2, -2), '|')
102-
local link_component = self:link_component(parts[1])
102+
local component = self:link_component(parts[1])
103103
local icon, highlight = self.link.wiki.icon, nil
104-
if link_component ~= nil then
105-
icon, highlight = link_component.icon, link_component.highlight
104+
if component ~= nil then
105+
icon, highlight = component.icon, component.highlight
106106
end
107-
highlight = highlight or self.link.wiki.highlight
108-
local link_text = icon .. parts[#parts]
109107
self.marks:add_over('link', self.node, {
110-
virt_text = { { link_text, highlight } },
108+
virt_text = { { icon .. parts[#parts], highlight or self.link.wiki.highlight } },
111109
virt_text_pos = 'inline',
112110
conceal = '',
113111
}, { 0, -1, 0, 1 })

tests/ad_hoc_spec.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ describe('ad_hoc.md', function()
7474
link(row:get(), 2, 20, '󰀓 [email protected]', 'Link', ''),
7575
})
7676

77+
vim.list_extend(expected, {
78+
util.bullet(row:increment(), 0, 1),
79+
link(row:get(), 2, 26, '󰊤 http://www.github.com/', 'Link', ''),
80+
})
81+
7782
vim.list_extend(expected, {
7883
util.bullet(row:increment(), 0, 1),
7984
link(row:get(), 2, 61, '󰗃 ', 'Link', nil),
@@ -96,10 +101,11 @@ describe('ad_hoc.md', function()
96101
' 8 ● 󱗖 Basic One Then normal text',
97102
' 9 ● 󱗖 With Alias Something important',
98103
' 10 ● 󰀓 [email protected] Email',
99-
' 11 ● 󰗃 Youtube Link',
100-
' 12 ● Footnote Link ¹ ᴵⁿᶠᵒ',
101-
' 13',
102-
' 14 ¹ ᴵⁿᶠᵒ: Some Info',
104+
' 11 ● 󰊤 http://www.github.com/ Bare URL',
105+
' 12 ● 󰗃 Youtube Link',
106+
' 13 ● Footnote Link ¹ ᴵⁿᶠᵒ',
107+
' 14',
108+
' 15 ¹ ᴵⁿᶠᵒ: Some Info',
103109
})
104110
end)
105111
end)

tests/data/ad_hoc.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Heading 2 Line 2
88
- [[Basic One]] Then normal text
99
- [[Nickname|With Alias]] Something important
1010
11+
- <http://www.github.com/> Bare URL
1112
- [Youtube Link](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
1213
- Footnote Link [^1 Info]
1314

0 commit comments

Comments
 (0)