aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_help_html.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2022-11-22 21:23:33 +0100
committerChristian Clason <c.clason@uni-graz.at>2022-12-02 16:05:00 +0100
commit9e1187e4896bebb481a3f9595155f2a40adbc45e (patch)
tree5659f23fde4892f80720ac1190704e825fec5272 /scripts/gen_help_html.lua
parent952f19ba38a3c826c268c4f744a332cf90021800 (diff)
downloadrneovim-9e1187e4896bebb481a3f9595155f2a40adbc45e.tar.gz
rneovim-9e1187e4896bebb481a3f9595155f2a40adbc45e.tar.bz2
rneovim-9e1187e4896bebb481a3f9595155f2a40adbc45e.zip
feat(web): syntax highlighting via highlight.js
download from https://highlightjs.org/download/ place `highlight/` directory next to `css/` style needs adapting for Neovim colors
Diffstat (limited to 'scripts/gen_help_html.lua')
-rw-r--r--scripts/gen_help_html.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/scripts/gen_help_html.lua b/scripts/gen_help_html.lua
index e5e99b308a..532e28ebb8 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 = {}
@@ -489,7 +490,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 ~= 'code' 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.
@@ -535,16 +536,23 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
return s
elseif node_name == 'argument' then
return ('%s<code>{%s}</code>'):format(ws(), text)
- -- TODO: use language for proper syntax highlighted code blocks
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
@@ -690,6 +698,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>