mirror of
https://github.com/neovim/neovim
synced 2025-07-17 09:41:46 +00:00
fix(man): filter OSC 8 hyperlink markup #29171
Problem: `man cmake` shows "8;;https://cmake.orghttps://cmake.org8;;" Solution: Remove noise so that it shows as "https://cmake.org". See also: https://en.wikipedia.org/wiki/ANSI_escape_code#OSC
This commit is contained in:
@ -35,7 +35,7 @@ local function highlight_line(line, linenr)
|
|||||||
---@type string[]
|
---@type string[]
|
||||||
local chars = {}
|
local chars = {}
|
||||||
local prev_char = ''
|
local prev_char = ''
|
||||||
local overstrike, escape = false, false
|
local overstrike, escape, osc8 = false, false, false
|
||||||
|
|
||||||
---@type table<integer,{attr:integer,start:integer,final:integer}>
|
---@type table<integer,{attr:integer,start:integer,final:integer}>
|
||||||
local hls = {} -- Store highlight groups as { attr, start, final }
|
local hls = {} -- Store highlight groups as { attr, start, final }
|
||||||
@ -139,6 +139,12 @@ local function highlight_line(line, linenr)
|
|||||||
prev_char = ''
|
prev_char = ''
|
||||||
byte = byte + #char
|
byte = byte + #char
|
||||||
chars[#chars + 1] = char
|
chars[#chars + 1] = char
|
||||||
|
elseif osc8 then
|
||||||
|
-- eat characters until String Terminator or bell
|
||||||
|
if (prev_char == '\027' and char == '\\') or char == '\a' then
|
||||||
|
osc8 = false
|
||||||
|
end
|
||||||
|
prev_char = char
|
||||||
elseif escape then
|
elseif escape then
|
||||||
-- Use prev_char to store the escape sequence
|
-- Use prev_char to store the escape sequence
|
||||||
prev_char = prev_char .. char
|
prev_char = prev_char .. char
|
||||||
@ -157,8 +163,11 @@ local function highlight_line(line, linenr)
|
|||||||
add_attr_hl(match + 0) -- coerce to number
|
add_attr_hl(match + 0) -- coerce to number
|
||||||
end
|
end
|
||||||
escape = false
|
escape = false
|
||||||
elseif not prev_char:match('^%[[\032-\063]*$') then
|
elseif prev_char == ']8;' then
|
||||||
-- Stop looking if this isn't a partial CSI sequence
|
osc8 = true
|
||||||
|
escape = false
|
||||||
|
elseif not prev_char:match('^[][][\032-\063]*$') then
|
||||||
|
-- Stop looking if this isn't a partial CSI or OSC sequence
|
||||||
escape = false
|
escape = false
|
||||||
end
|
end
|
||||||
elseif char == '\027' then
|
elseif char == '\027' then
|
||||||
|
@ -117,6 +117,29 @@ describe(':Man', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('clears OSC 8 hyperlink markup from text', function()
|
||||||
|
feed(
|
||||||
|
[[
|
||||||
|
ithis <C-v><ESC>]8;;http://example.com<C-v><ESC>\Link Title<C-v><ESC>]8;;<C-v><ESC>\<ESC>]]
|
||||||
|
)
|
||||||
|
|
||||||
|
screen:expect {
|
||||||
|
grid = [=[
|
||||||
|
this {c:^[}]8;;http://example.com{c:^[}\Link Title{c:^[}]8;;{c:^[}^\ |
|
||||||
|
{eob:~ }|*3
|
||||||
|
|
|
||||||
|
]=],
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_lua [[require'man'.init_pager()]]
|
||||||
|
|
||||||
|
screen:expect([[
|
||||||
|
^this Link Title |
|
||||||
|
{eob:~ }|*3
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('highlights multibyte text', function()
|
it('highlights multibyte text', function()
|
||||||
feed(
|
feed(
|
||||||
[[
|
[[
|
||||||
|
Reference in New Issue
Block a user