mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 11:15:14 -07:00
fix(docs-html): misaligned tabs after conceal #20690
Problem: `gen_help_html.lua` does not properly handle tab characters after "concealed" text (tags, taglinks, codespans). This causes misaligned layout in "old" (preformatted) docs. For text like `*tag*`, |tag_link|, and `code_span`, Vim hides the "*", "|", "`" characters, but Vim still counts those characters for "virtual column" when a tab character follows it. So if you have a tag of say 6 characters long, those two concealed character would lead to the tab character after it start at column 8. gen_help_html.lua doesn't account for that which leads to formatting flaws in the generated output. Solution: Add two spaces after concealed nodes that are followed by a tab char.
This commit is contained in:
parent
3b0777cfa5
commit
10ab7489eb
@ -390,6 +390,18 @@ local function visit_validate(root, level, lang_tree, opt, stats)
|
|||||||
end
|
end
|
||||||
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.
|
-- Generates HTML from node `root` recursively.
|
||||||
local function visit_node(root, level, lang_tree, headings, opt, stats)
|
local function visit_node(root, level, lang_tree, headings, opt, stats)
|
||||||
level = level or 0
|
level = level or 0
|
||||||
@ -506,12 +518,20 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
|
|||||||
if ignored then
|
if ignored then
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
return ('%s<a href="%s#%s">%s</a>'):format(ws(), helppage, url_encode(tagname), html_esc(tagname))
|
local s = ('%s<a href="%s#%s">%s</a>'):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
|
elseif vim.tbl_contains({'codespan', 'keycode'}, node_name) then
|
||||||
if root:has_error() then
|
if root:has_error() then
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
return ('%s<code>%s</code>'):format(ws(), trimmed)
|
local s = ('%s<code>%s</code>'):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
|
elseif node_name == 'argument' then
|
||||||
return ('%s<code>{%s}</code>'):format(ws(), text)
|
return ('%s<code>{%s}</code>'):format(ws(), text)
|
||||||
elseif node_name == 'codeblock' then
|
elseif node_name == 'codeblock' then
|
||||||
@ -533,6 +553,10 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
|
|||||||
end
|
end
|
||||||
local el = in_heading and 'span' or 'code'
|
local el = in_heading and 'span' or 'code'
|
||||||
local s = ('%s<a name="%s"></a><%s class="%s">%s</%s>'):format(ws(), url_encode(tagname), el, cssclass, trimmed, el)
|
local s = ('%s<a name="%s"></a><%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
|
if in_heading and prev ~= 'tag' then
|
||||||
-- Start the <span> container for tags in a heading.
|
-- Start the <span> container for tags in a heading.
|
||||||
-- This makes "justify-content:space-between" right-align the tags.
|
-- This makes "justify-content:space-between" right-align the tags.
|
||||||
|
Loading…
Reference in New Issue
Block a user