diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua
index b1d41cf89e..3a384bccf9 100644
--- a/scripts/gen_help_html.lua
+++ b/scripts/gen_help_html.lua
@@ -390,6 +390,18 @@ local function visit_validate(root, level, lang_tree, opt, stats)
end
end
+-- Fix tab alignment issues caused by concealed characters like |, `, * in tags
+-- and code blocks.
+local function fix_tab_after_conceal(text, next_node_text)
+ -- Vim tabs take into account the two concealed characters even though they
+ -- are invisible, so we need to add back in the two spaces if this is
+ -- followed by a tab to make the tab alignment to match Vim's behavior.
+ if string.sub(next_node_text,1,1) == '\t' then
+ text = text .. ' '
+ end
+ return text
+end
+
-- Generates HTML from node `root` recursively.
local function visit_node(root, level, lang_tree, headings, opt, stats)
level = level or 0
@@ -506,12 +518,20 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
if ignored then
return text
end
- return ('%s%s'):format(ws(), helppage, url_encode(tagname), html_esc(tagname))
+ local s = ('%s%s'):format(ws(), helppage, url_encode(tagname), html_esc(tagname))
+ if node_name == 'taglink' and opt.old then
+ s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
+ end
+ return s
elseif vim.tbl_contains({'codespan', 'keycode'}, node_name) then
if root:has_error() then
return text
end
- return ('%s%s
'):format(ws(), trimmed)
+ local s = ('%s%s
'):format(ws(), trimmed)
+ if node_name == 'codespan' and opt.old then
+ s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
+ end
+ return s
elseif node_name == 'argument' then
return ('%s{%s}
'):format(ws(), text)
elseif node_name == 'codeblock' then
@@ -533,6 +553,10 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
end
local el = in_heading and 'span' or 'code'
local s = ('%s<%s class="%s">%s%s>'):format(ws(), url_encode(tagname), el, cssclass, trimmed, el)
+ if opt.old then
+ s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
+ end
+
if in_heading and prev ~= 'tag' then
-- Start the container for tags in a heading.
-- This makes "justify-content:space-between" right-align the tags.