mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
feat(help): highlighted codeblocks
cherry-picked from 5093f38c9f
(omit partial doc change)
This commit is contained in:
parent
b840eb6945
commit
342312b8ad
@ -210,8 +210,8 @@ set(TREESITTER_LUA_SHA256 564594fe0ffd2f2fb3578a15019b723e1bc94ac82cb6a0103a6b3b
|
||||
set(TREESITTER_VIM_URL https://github.com/vigoux/tree-sitter-viml/archive/v0.2.0.tar.gz)
|
||||
set(TREESITTER_VIM_SHA256 608dcc31a7948cb66ae7f45494620e2e9face1af75598205541f80d782ec4501)
|
||||
|
||||
set(TREESITTER_HELP_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v1.2.2.tar.gz)
|
||||
set(TREESITTER_HELP_SHA256 d33b9447dae04f19e1ac50c94b78e305574c07f942791f70aea96fe266447c18)
|
||||
set(TREESITTER_HELP_URL https://github.com/neovim/tree-sitter-vimdoc/archive/ce20f13c3f12506185754888feaae3f2ad54c287.tar.gz)
|
||||
set(TREESITTER_HELP_SHA256 2b8b166438cce66064aab56a744430b1f44871f43e47f70b51246d14bb826609)
|
||||
|
||||
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.7.tar.gz)
|
||||
set(TREESITTER_SHA256 b355e968ec2d0241bbd96748e00a9038f83968f85d822ecb9940cbe4c42e182e)
|
||||
|
@ -14,6 +14,10 @@
|
||||
"`" @conceal (#set! conceal "")
|
||||
text: (_) @text.literal)
|
||||
(codeblock) @text.literal
|
||||
(codeblock
|
||||
[">" (language)] @conceal (#set! conceal ""))
|
||||
(block
|
||||
"<" @conceal (#set! conceal ""))
|
||||
(argument) @parameter
|
||||
(keycode) @string.special
|
||||
(url) @text.uri
|
||||
|
3
runtime/queries/help/injections.scm
Normal file
3
runtime/queries/help/injections.scm
Normal file
@ -0,0 +1,3 @@
|
||||
(codeblock
|
||||
(language) @language
|
||||
(code) @content)
|
@ -14,10 +14,11 @@ set cpo&vim
|
||||
syn match helpHeadline "^[-A-Z .][-A-Z0-9 .()_]*\ze\(\s\+\*\|$\)"
|
||||
syn match helpSectionDelim "^===.*===$"
|
||||
syn match helpSectionDelim "^---.*--$"
|
||||
" Neovim: support language annotation in codeblocks
|
||||
if has("conceal")
|
||||
syn region helpExample matchgroup=helpIgnore start=" >$" start="^>$" end="^[^ \t]"me=e-1 end="^<" concealends
|
||||
syn region helpExample matchgroup=helpIgnore start=" >[a-z0-9]*$" start="^[a-z0-9]*>$" end="^[^ \t]"me=e-1 end="^<" concealends
|
||||
else
|
||||
syn region helpExample matchgroup=helpIgnore start=" >$" start="^>$" end="^[^ \t]"me=e-1 end="^<"
|
||||
syn region helpExample matchgroup=helpIgnore start=" >[a-z0-9]*$" start="^[a-z0-9]*>$" end="^[^ \t]"me=e-1 end="^<"
|
||||
endif
|
||||
syn match helpHyperTextJump "\\\@<!|[#-)!+-~]\+|" contains=helpBar
|
||||
syn match helpHyperTextEntry "\*[#-)!+-~]\+\*\s"he=e-1 contains=helpStar
|
||||
|
@ -475,7 +475,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 ~= '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.
|
||||
@ -513,7 +513,12 @@ local function visit_node(root, level, lang_tree, headings, opt, stats)
|
||||
return ('%s<code>%s</code>'):format(ws(), trimmed)
|
||||
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
|
||||
return ''
|
||||
elseif node_name == 'code' then
|
||||
if is_blank(text) then
|
||||
return ''
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user