From e37404f7fecc5f57e4f3df4cf5ba0adec67bfbb3 Mon Sep 17 00:00:00 2001 From: yayoyuyu <112897090+yayoyuyu@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:29:27 +0900 Subject: 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'` --- test/functional/plugin/tohtml_spec.lua | 85 +++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index dbf385c0c3..8cb7105660 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -136,6 +136,53 @@ local function run_tohtml_and_assert(screen, func) screen:expect({ grid = expected.grid, attr_ids = expected.attr_ids }) end +---@param guifont boolean +local function test_generates_html(guifont) + insert([[line]]) + exec('set termguicolors') + local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') + local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') + if guifont then + exec_lua [[ + vim.o.guifont="Font,Escape\\,comma, Ignore space after comma" + local outfile = vim.fn.tempname() .. '.html' + local html = require('tohtml').tohtml(0,{title="title"}) + vim.fn.writefile(html, outfile) + vim.cmd.split(outfile) + ]] + else + exec_lua [[ + local outfile = vim.fn.tempname() .. '.html' + local html = require('tohtml').tohtml(0,{title="title",font={ "dumyfont","anotherfont" }}) + vim.fn.writefile(html, outfile) + vim.cmd.split(outfile) + ]] + end + local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) + eq({ + '', + '', + '', + '', + 'title', + (''):format(api.nvim_get_var('colors_name')), + '', + '', + '', + '
',
+    'line',
+    '',
+    '
', + '', + '', + }, fn.readfile(out_file)) +end + describe(':TOhtml', function() --- @type test.functional.ui.screen local screen @@ -146,38 +193,12 @@ describe(':TOhtml', function() exec('colorscheme default') end) - it('expected internal html generated', function() - insert([[line]]) - exec('set termguicolors') - local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') - local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') - exec_lua [[ - local outfile = vim.fn.tempname() .. '.html' - local html = require('tohtml').tohtml(0,{title="title",font="dumyfont"}) - vim.fn.writefile(html, outfile) - vim.cmd.split(outfile) - ]] - local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) - eq({ - '', - '', - '', - '', - 'title', - (''):format(api.nvim_get_var('colors_name')), - '', - '', - '', - '
',
-      'line',
-      '',
-      '
', - '', - '', - }, fn.readfile(out_file)) + it('generates html', function() + test_generates_html(false) + end) + + it("generates html, respects 'guifont'", function() + test_generates_html(true) end) it('expected internal html generated from range', function() -- cgit From 95b65a7554f1b1041e4f1e7427e540993b68e47e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Sep 2024 12:15:13 +0200 Subject: test(tohtml): simplify font test --- test/functional/plugin/tohtml_spec.lua | 48 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 8cb7105660..98a422935c 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -137,27 +137,26 @@ local function run_tohtml_and_assert(screen, func) end ---@param guifont boolean -local function test_generates_html(guifont) +local function test_generates_html(guifont, expect_font) insert([[line]]) exec('set termguicolors') local bg = fn.synIDattr(fn.hlID('Normal'), 'bg#', 'gui') local fg = fn.synIDattr(fn.hlID('Normal'), 'fg#', 'gui') - if guifont then - exec_lua [[ - vim.o.guifont="Font,Escape\\,comma, Ignore space after comma" - local outfile = vim.fn.tempname() .. '.html' - local html = require('tohtml').tohtml(0,{title="title"}) - vim.fn.writefile(html, outfile) - vim.cmd.split(outfile) - ]] - else - exec_lua [[ - local outfile = vim.fn.tempname() .. '.html' - local html = require('tohtml').tohtml(0,{title="title",font={ "dumyfont","anotherfont" }}) - vim.fn.writefile(html, outfile) - vim.cmd.split(outfile) - ]] - end + local tmpfile = t.tmpname() + + exec_lua( + [[ + local guifont, outfile = ... + local html = (guifont + and require('tohtml').tohtml(0,{title="title"}) + or require('tohtml').tohtml(0,{title="title",font={ "dumyfont","anotherfont" }})) + vim.fn.writefile(html, outfile) + vim.cmd.split(outfile) + ]], + guifont, + tmpfile + ) + local out_file = api.nvim_buf_get_name(api.nvim_get_current_buf()) eq({ '', @@ -167,9 +166,7 @@ local function test_generates_html(guifont) 'title', (''):format(api.nvim_get_var('colors_name')), '', '', @@ -193,15 +190,16 @@ describe(':TOhtml', function() exec('colorscheme default') end) - it('generates html', function() - test_generates_html(false) + it('generates html with given font', function() + test_generates_html(false, '"dumyfont","anotherfont"') end) it("generates html, respects 'guifont'", function() - test_generates_html(true) + exec_lua [[vim.o.guifont='Font,Escape\\,comma, Ignore space after comma']] + test_generates_html(true, '"Font","Escape,comma","Ignore space after comma"') end) - it('expected internal html generated from range', function() + it('generates html from range', function() insert([[ line1 line2 @@ -239,7 +237,7 @@ describe(':TOhtml', function() }, fn.readfile(out_file)) end) - it('highlight attributes generated', function() + it('generates highlight attributes', function() --Make sure to uncomment the attribute in `html_syntax_match()` exec('hi LINE guisp=#00ff00 gui=' .. table.concat({ 'bold', -- cgit