diff options
author | Lennard Hofmann <lennard.hofmann@web.de> | 2024-06-07 21:43:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-07 12:43:17 -0700 |
commit | da6f68ee6966ebf434eee840b22a4f45e61d77dd (patch) | |
tree | d67c695566a18d5162426a13efa1dd40e385d5f3 /runtime/lua | |
parent | f3632e14e3a75114415050ab01c2d04a06036009 (diff) | |
download | rneovim-da6f68ee6966ebf434eee840b22a4f45e61d77dd.tar.gz rneovim-da6f68ee6966ebf434eee840b22a4f45e61d77dd.tar.bz2 rneovim-da6f68ee6966ebf434eee840b22a4f45e61d77dd.zip |
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
Diffstat (limited to 'runtime/lua')
-rw-r--r-- | runtime/lua/man.lua | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 02e841030f..348e502f34 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -35,7 +35,7 @@ local function highlight_line(line, linenr) ---@type string[] local chars = {} local prev_char = '' - local overstrike, escape = false, false + local overstrike, escape, osc8 = false, false, false ---@type table<integer,{attr:integer,start:integer,final:integer}> local hls = {} -- Store highlight groups as { attr, start, final } @@ -139,6 +139,12 @@ local function highlight_line(line, linenr) prev_char = '' byte = byte + #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 -- Use prev_char to store the escape sequence prev_char = prev_char .. char @@ -157,8 +163,11 @@ local function highlight_line(line, linenr) add_attr_hl(match + 0) -- coerce to number end escape = false - elseif not prev_char:match('^%[[\032-\063]*$') then - -- Stop looking if this isn't a partial CSI sequence + elseif prev_char == ']8;' then + 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 end elseif char == '\027' then |