From 214ce8d33c11f75b3500212258f09b58b3d42e80 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 8 Oct 2024 07:42:20 -0700 Subject: fix(gen_help_html): first tag in h2 is broken #30720 Problem: In h2 headings, the first tag points to an invalid anchor. This used to work but regressed a few months ago, possibly related to ceea6898a8bdcb6c4cfe06b8dc4739c144e6b1f8. Solution: - Simplify the logic, don't try to be clever: - Always use to_heading_tag() for the h2 `id`. - Also: - Render tags as ``, because `` is unnecessary and doesn't look great in headings. - In the main h1, use "foo.txt" as the anchor `name` (rarely used), prefer the next found tag for the `href`. --- scripts/gen_help_html.lua | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'scripts/gen_help_html.lua') diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index f6e799508b..b5dbce38f6 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -554,11 +554,8 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) return '' -- Spurious "===" or "---" in the help doc. end - -- Use the first *tag* node as the heading anchor, if any. - local tagnode = first(heading_node, 'tag') - -- Use the *tag* as the heading anchor id, if possible. - local tagname = tagnode and url_encode(trim(node_text(tagnode:child(1), false))) - or to_heading_tag(hname) + -- Generate an anchor id from the heading text. + local tagname = to_heading_tag(hname) if node_name == 'h1' or #headings == 0 then ---@type nvim.gen_help_html.heading local heading = { name = hname, subheadings = {}, tag = tagname } @@ -678,7 +675,7 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) table.insert(stats.first_tags, tagname) return '' end - local el = in_heading and 'span' or 'code' + local el = 'span' local encoded_tagname = url_encode(tagname) local s = ('%s<%s id="%s" class="%s">%s'):format( ws(), @@ -694,15 +691,6 @@ local function visit_node(root, level, lang_tree, headings, opt, stats) end if in_heading and prev ~= 'tag' then - -- Don't set "id", let the heading use the tag as its "id" (used by search engines). - s = ('%s<%s class="%s">%s'):format( - ws(), - el, - cssclass, - encoded_tagname, - trimmed, - el - ) -- Start the container for tags in a heading. -- This makes "justify-content:space-between" right-align the tags. --

foo bartag1 tag2

@@ -957,7 +945,7 @@ local function gen_one(fname, text, to_fname, old, commit, parser_path)
-

%s

+

%s

Nvim :help pages, generated @@ -970,8 +958,9 @@ local function gen_one(fname, text, to_fname, old, commit, parser_path)

]]):format( logo_svg, - stats.first_tags[2] or '', stats.first_tags[1] or '', + stats.first_tags[2] or '', + stats.first_tags[2] or '', title, vim.fs.basename(fname), main -- cgit From 3572319b4cb1a4163624a5fe328886f1928dbc4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Oct 2024 11:33:12 +0100 Subject: feat(vim.validate): improve fast form and deprecate spec form Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument. --- scripts/gen_help_html.lua | 52 +++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) (limited to 'scripts/gen_help_html.lua') diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index b5dbce38f6..21d865309d 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -1289,25 +1289,15 @@ end --- --- @return nvim.gen_help_html.gen_result result function M.gen(help_dir, to_dir, include, commit, parser_path) - vim.validate { - help_dir = { - help_dir, - function(d) - return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 - end, - 'valid directory', - }, - to_dir = { to_dir, 's' }, - include = { include, 't', true }, - commit = { commit, 's', true }, - parser_path = { - parser_path, - function(f) - return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1 - end, - 'valid vimdoc.{so,dll} filepath', - }, - } + vim.validate('help_dir', help_dir, function(d) + return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 + end, 'valid directory') + vim.validate('to_dir', to_dir, 'string') + vim.validate('include', include, 'table', true) + vim.validate('commit', commit, 'sring', true) + vim.validate('parser_path', parser_path, function(f) + return vim.fn.filereadable(vim.fs.normalize(f)) == 1 + end, true, 'valid vimdoc.{so,dll} filepath') local err_count = 0 local redirects_count = 0 @@ -1410,23 +1400,13 @@ end --- --- @return nvim.gen_help_html.validate_result result function M.validate(help_dir, include, parser_path) - vim.validate { - help_dir = { - help_dir, - function(d) - return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 - end, - 'valid directory', - }, - include = { include, 't', true }, - parser_path = { - parser_path, - function(f) - return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1 - end, - 'valid vimdoc.{so,dll} filepath', - }, - } + vim.validate('help_dir', help_dir, function(d) + return vim.fn.isdirectory(vim.fs.normalize(d)) == 1 + end, 'valid directory') + vim.validate('include', include, 'table', true) + vim.validate('parser_path', parser_path, function(f) + return vim.fn.filereadable(vim.fs.normalize(f)) == 1 + end, true, 'valid vimdoc.{so,dll} filepath') local err_count = 0 ---@type integer local files_to_errors = {} ---@type table ensure_runtimepath() -- cgit From 3a86b60032bd659c2b12e984abb40cee93568558 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 29 Sep 2024 14:07:21 +0200 Subject: docs: misc Co-authored-by: David Pedersen Co-authored-by: Gregory Anders Co-authored-by: Leo Schlosser Co-authored-by: zeertzjq --- scripts/gen_help_html.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/gen_help_html.lua') diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua index 21d865309d..b8f80e94be 100644 --- a/scripts/gen_help_html.lua +++ b/scripts/gen_help_html.lua @@ -1294,7 +1294,7 @@ function M.gen(help_dir, to_dir, include, commit, parser_path) end, 'valid directory') vim.validate('to_dir', to_dir, 'string') vim.validate('include', include, 'table', true) - vim.validate('commit', commit, 'sring', true) + vim.validate('commit', commit, 'string', true) vim.validate('parser_path', parser_path, function(f) return vim.fn.filereadable(vim.fs.normalize(f)) == 1 end, true, 'valid vimdoc.{so,dll} filepath') -- cgit