diff options
author | yayoyuyu <112897090+yayoyuyu@users.noreply.github.com> | 2024-08-20 23:29:27 +0900 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2024-09-08 12:15:50 +0200 |
commit | e37404f7fecc5f57e4f3df4cf5ba0adec67bfbb3 (patch) | |
tree | 3c90172490a572828e7f4fadc00139b54e7babdd /runtime/lua/tohtml.lua | |
parent | b40ec083ae30eb64ddfec2b238c909116e936e99 (diff) | |
download | rneovim-e37404f7fecc5f57e4f3df4cf5ba0adec67bfbb3.tar.gz rneovim-e37404f7fecc5f57e4f3df4cf5ba0adec67bfbb3.tar.bz2 rneovim-e37404f7fecc5f57e4f3df4cf5ba0adec67bfbb3.zip |
fix(tohtml): enclose font-family names in quotation marks
Font-family names must be enclosed in quotation marks to ensure that
fonts are applied correctly when there are spaces in the name.
Fix an issue where multiple fonts specified in `vim.o.guifont` are
inserted as a single element, treating them as a single font.
Support for escaping commas with backslash and ignoring spaces
after a comma.
ref `:help 'guifont'`
Diffstat (limited to 'runtime/lua/tohtml.lua')
-rw-r--r-- | runtime/lua/tohtml.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/runtime/lua/tohtml.lua b/runtime/lua/tohtml.lua index 6a5bd6de9d..ed42b28725 100644 --- a/runtime/lua/tohtml.lua +++ b/runtime/lua/tohtml.lua @@ -1293,9 +1293,25 @@ local function opt_to_global_state(opt, title) local fonts = {} if opt.font then fonts = type(opt.font) == 'string' and { opt.font } or opt.font --[[@as (string[])]] + for i, v in pairs(fonts) do + fonts[i] = ('"%s"'):format(v) + end elseif vim.o.guifont:match('^[^:]+') then - table.insert(fonts, vim.o.guifont:match('^[^:]+')) + -- Example: + -- Input: "Font,Escape\,comma, Ignore space after comma" + -- Output: { "Font","Escape,comma","Ignore space after comma" } + local prev = '' + for name in vim.gsplit(vim.o.guifont:match('^[^:]+'), ',', { trimempty = true }) do + if vim.endswith(name, '\\') then + prev = prev .. vim.trim(name:sub(1, -2) .. ',') + elseif vim.trim(name) ~= '' then + table.insert(fonts, ('"%s%s"'):format(prev, vim.trim(name))) + prev = '' + end + end end + -- Generic family names (monospace here) must not be quoted + -- because the browser recognizes them as font families. table.insert(fonts, 'monospace') --- @type vim.tohtml.state.global local state = { |