Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb7a110

Browse files
feat(hyperlinks): Add OSC 8 hyperlink support to links
1 parent d0baf31 commit eb7a110

File tree

1 file changed

+11
-2
lines changed
  • lua/orgmode/colors/highlighter/markup

1 file changed

+11
-2
lines changed

lua/orgmode/colors/highlighter/markup/link.lua

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
local ts_utils = require('orgmode.utils.treesitter')
2+
local utils = require('orgmode.utils')
23

34
---@class OrgLinkHighlighter : OrgMarkupHighlighter
45
---@field private markup OrgMarkupHighlighter
6+
---@field private has_extmark_url_support boolean
57
local OrgLink = {}
68

79
---@param opts { markup: OrgMarkupHighlighter }
810
function OrgLink:new(opts)
911
local data = {
1012
markup = opts.markup,
13+
has_extmark_url_support = utils.has_version_10(),
1114
}
1215
setmetatable(data, self)
1316
self.__index = self
@@ -100,12 +103,18 @@ function OrgLink:highlight(highlights, bufnr)
100103
local alias = link:find('%]%[') or 1
101104
local link_end = link:find('%]%[') or (link:len() - 1)
102105

103-
vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, {
106+
local link_opts = {
104107
ephemeral = ephemeral,
105108
end_col = entry.to.end_col,
106109
hl_group = '@org.hyperlink',
107110
priority = 110,
108-
})
111+
}
112+
113+
if self.has_extmark_url_support then
114+
link_opts.url = alias > 1 and link:sub(3, alias - 1) or link:sub(3, -3)
115+
end
116+
117+
vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, link_opts)
109118

110119
vim.api.nvim_buf_set_extmark(bufnr, namespace, entry.from.line, entry.from.start_col, {
111120
ephemeral = ephemeral,

0 commit comments

Comments
 (0)