aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_help_html.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gen_help_html.lua')
-rw-r--r--scripts/gen_help_html.lua130
1 files changed, 99 insertions, 31 deletions
diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua
index 06ea1831b0..2563f2f410 100644
--- a/scripts/gen_help_html.lua
+++ b/scripts/gen_help_html.lua
@@ -35,6 +35,7 @@ local spell_dict = {
lua = 'Lua',
VimL = 'Vimscript',
}
+local language = nil
local M = {}
@@ -59,19 +60,34 @@ local exclude_invalid = {
["'previewpopup'"] = "quickref.txt",
["'pvp'"] = "quickref.txt",
["'string'"] = "eval.txt",
- Query = "treesitter.txt",
- ["eq?"] = "treesitter.txt",
- ["lsp-request"] = "lsp.txt",
- matchit = "vim_diff.txt",
- ["matchit.txt"] = "help.txt",
+ Query = 'treesitter.txt',
+ ['eq?'] = 'treesitter.txt',
+ ['lsp-request'] = 'lsp.txt',
+ matchit = 'vim_diff.txt',
+ ['matchit.txt'] = 'help.txt',
["set!"] = "treesitter.txt",
- ["v:_null_blob"] = "builtin.txt",
- ["v:_null_dict"] = "builtin.txt",
- ["v:_null_list"] = "builtin.txt",
- ["v:_null_string"] = "builtin.txt",
- ["vim.lsp.buf_request()"] = "lsp.txt",
- ["vim.lsp.util.get_progress_messages()"] = "lsp.txt",
- ["vim.treesitter.start()"] = "treesitter.txt",
+ ['v:_null_blob'] = 'builtin.txt',
+ ['v:_null_dict'] = 'builtin.txt',
+ ['v:_null_list'] = 'builtin.txt',
+ ['v:_null_string'] = 'builtin.txt',
+ ['vim.lsp.buf_request()'] = 'lsp.txt',
+ ['vim.lsp.util.get_progress_messages()'] = 'lsp.txt',
+}
+
+-- False-positive "invalid URLs".
+local exclude_invalid_urls = {
+ ["http://"] = "usr_23.txt",
+ ["http://."] = "usr_23.txt",
+ ["http://aspell.net/man-html/Affix-Compression.html"] = "spell.txt",
+ ["http://aspell.net/man-html/Phonetic-Code.html"] = "spell.txt",
+ ["http://canna.sourceforge.jp/"] = "mbyte.txt",
+ ["http://gnuada.sourceforge.net"] = "ft_ada.txt",
+ ["http://lua-users.org/wiki/StringLibraryTutorial"] = "lua.txt",
+ ["http://michael.toren.net/code/"] = "pi_tar.txt",
+ ["http://papp.plan9.de"] = "syntax.txt",
+ ["http://wiki.services.openoffice.org/wiki/Dictionaries"] = "spell.txt",
+ ["http://www.adapower.com"] = "ft_ada.txt",
+ ["http://www.jclark.com/"] = "quickfix.txt",
}
local function tofile(fname, text)
@@ -279,9 +295,11 @@ local function ignore_invalid(s)
end
local function ignore_parse_error(s)
- -- Ignore parse errors for unclosed codespan/optionlink/tag.
- -- This is common in vimdocs and is treated as plaintext by :help.
- return s:find("^[`'|*]")
+ return (
+ -- Ignore parse errors for unclosed tag.
+ -- This is common in vimdocs and is treated as plaintext by :help.
+ s:find("^[`'|*]")
+ )
end
local function has_ancestor(node, ancestor_name)
@@ -319,6 +337,17 @@ local function validate_link(node, bufnr, fname)
return helppage, tagname, ignored
end
+-- TODO: port the logic from scripts/check_urls.vim
+local function validate_url(text, fname)
+ local ignored = false
+ if vim.fs.basename(fname) == 'pi_netrw.txt' then
+ ignored = true
+ elseif text:find('http%:') and not exclude_invalid_urls[text] then
+ invalid_urls[text] = vim.fs.basename(fname)
+ end
+ return ignored
+end
+
-- Traverses the tree at `root` and checks that |tag| links point to valid helptags.
local function visit_validate(root, level, lang_tree, opt, stats)
level = level or 0
@@ -353,14 +382,25 @@ local function visit_validate(root, level, lang_tree, opt, stats)
end
end
elseif node_name == 'url' then
- if text:find('http%:') then
- invalid_urls[text] = vim.fs.basename(opt.fname)
- end
+ local fixed_url, _ = fix_url(trim(text))
+ validate_url(fixed_url, opt.fname)
elseif node_name == 'taglink' or node_name == 'optionlink' then
local _, _, _ = validate_link(root, opt.buf, opt.fname)
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
@@ -447,7 +487,7 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
end
return string.format('<div class="help-para">\n%s\n</div>\n', text)
elseif node_name == 'line' then
- if parent ~= 'codeblock' and (is_blank(text) or is_noise(text, stats.noise_lines)) then
+ if (parent ~= 'codeblock' or parent ~= 'code') and (is_blank(text) or is_noise(text, stats.noise_lines)) then
return '' -- Discard common "noise" lines.
end
-- XXX: Avoid newlines (too much whitespace) after block elements in old (preformatted) layout.
@@ -477,19 +517,39 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
if ignored then
return text
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 opt.old and node_name == 'taglink' 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<code>%s</code>'):format(ws(), trimmed)
+ local s = ('%s<code>%s</code>'):format(ws(), trimmed)
+ if opt.old and node_name == 'codespan' then
+ s = fix_tab_after_conceal(s, node_text(root:next_sibling()))
+ end
+ return s
elseif node_name == 'argument' then
return ('%s<code>{%s}</code>'):format(ws(), text)
elseif node_name == 'codeblock' then
+ return text
+ elseif node_name == 'language' then
+ language = node_text(root)
+ return ''
+ elseif node_name == 'code' then
if is_blank(text) then
return ''
end
- return ('<pre>%s</pre>'):format(trim(trim_indent(text), 2))
+ local code
+ if language then
+ code = ('<pre><code class="language-%s">%s</code></pre>'):format(language,trim(trim_indent(text), 2))
+ language = nil
+ else
+ code = ('<pre>%s</pre>'):format(trim(trim_indent(text), 2))
+ end
+ return code
elseif node_name == 'tag' then -- anchor
if root:has_error() then
return text
@@ -504,6 +564,10 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
end
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)
+ 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 <span> container for tags in a heading.
-- This makes "justify-content:space-between" right-align the tags.
@@ -631,6 +695,9 @@ local function gen_one(fname, to_fname, old, commit)
<link href="/css/bootstrap.css" rel="stylesheet">
<link href="/css/main.css" rel="stylesheet">
<link href="help.css" rel="stylesheet">
+ <link href="/highlight/styles/neovim.min.css" rel="stylesheet">
+ <script src="/highlight/highlight.min.js"></script>
+ <script>hljs.highlightAll();</script>
<title>%s - Neovim docs</title>
</head>
<body>
@@ -773,8 +840,14 @@ end
local function gen_css(fname)
local css = [[
:root {
- --code-color: #008B8B;
- --tag-color: gray;
+ --code-color: #004b4b;
+ --tag-color: #095943;
+ }
+ @media (prefers-color-scheme: dark) {
+ :root {
+ --code-color: #00c243;
+ --tag-color: #00b7b7;
+ }
}
@media (min-width: 40em) {
.toc {
@@ -793,11 +866,6 @@ local function gen_css(fname)
display: block;
}
}
- @media (prefers-color-scheme: dark) {
- :root {
- --code-color: cyan;
- }
- }
.toc {
/* max-width: 12rem; */
height: 85%; /* Scroll if there are too many items. https://github.com/neovim/neovim.github.io/issues/297 */
@@ -817,7 +885,7 @@ local function gen_css(fname)
}
h1, h2, h3, h4, h5 {
font-family: sans-serif;
- border-bottom: 1px solid #41464bd6; /*rgba(0, 0, 0, .9);*/
+ border-bottom: 1px solid var(--tag-color); /*rgba(0, 0, 0, .9);*/
}
h3, h4, h5 {
border-bottom-style: dashed;
@@ -892,7 +960,7 @@ local function gen_css(fname)
pre {
/* Tabs are used in codeblocks only for indentation, not alignment, so we can aggressively shrink them. */
tab-size: 2;
- white-space: pre;
+ white-space: pre-wrap;
line-height: 1.3; /* Important for ascii art. */
overflow: visible;
/* font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; */