mirror of
https://github.com/vim/vim
synced 2025-07-15 16:51:57 +00:00
patch 9.1.1533: helptoc: does not handle code sections in markdown well
Problem: helptoc: does not handle code sections in markdown well (VimWei) Solution: Skip over fenced code sections (lacygoill), add a test. fixes: #17699 closes: #17710 Co-authored-by: lagygoill <lacygoill@lacygoill.me> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@ -1,4 +1,10 @@
|
|||||||
vim9script noclear
|
vim9script noclear
|
||||||
|
|
||||||
|
# the Vim HelpTOC plugin, creates a table of contents in a popup
|
||||||
|
# Maintainer: Vim project
|
||||||
|
# Original Author: @lacygoill
|
||||||
|
# Latest Change: 2025 Jul 09
|
||||||
|
#
|
||||||
# Config {{{1
|
# Config {{{1
|
||||||
# g:helptoc {{{2
|
# g:helptoc {{{2
|
||||||
# Create the g:helptoc dict (used to specify the shell_prompt and other
|
# Create the g:helptoc dict (used to specify the shell_prompt and other
|
||||||
@ -503,6 +509,7 @@ def SetToc() #{{{2
|
|||||||
l[0]->str2nr() - ll[0]->str2nr())
|
l[0]->str2nr() - ll[0]->str2nr())
|
||||||
|
|
||||||
var skip_next: bool = false
|
var skip_next: bool = false
|
||||||
|
var skip_fence: bool = false
|
||||||
|
|
||||||
# Non-help headings processing
|
# Non-help headings processing
|
||||||
for lnum: number in range(1, line('$'))
|
for lnum: number in range(1, line('$'))
|
||||||
@ -516,6 +523,14 @@ def SetToc() #{{{2
|
|||||||
|
|
||||||
# Special handling for markdown filetype using setext headings
|
# Special handling for markdown filetype using setext headings
|
||||||
if g:helptoc.type == 'markdown'
|
if g:helptoc.type == 'markdown'
|
||||||
|
if curline =~ '^```.'
|
||||||
|
skip_fence = true
|
||||||
|
elseif curline =~ '^```$'
|
||||||
|
skip_fence = false
|
||||||
|
endif
|
||||||
|
if skip_fence
|
||||||
|
continue
|
||||||
|
endif
|
||||||
# Check for setext formatted headings (= or - underlined)
|
# Check for setext formatted headings (= or - underlined)
|
||||||
if nextline =~ '^\s\{0,3}=\+$' && curline =~ '\S'
|
if nextline =~ '^\s\{0,3}=\+$' && curline =~ '\S'
|
||||||
# Level 1 heading (one or more =, up to three spaces preceding)
|
# Level 1 heading (one or more =, up to three spaces preceding)
|
||||||
|
@ -242,6 +242,7 @@ NEW_TESTS = \
|
|||||||
test_perl \
|
test_perl \
|
||||||
test_plugin_comment \
|
test_plugin_comment \
|
||||||
test_plugin_glvs \
|
test_plugin_glvs \
|
||||||
|
test_plugin_helptoc \
|
||||||
test_plugin_man \
|
test_plugin_man \
|
||||||
test_plugin_matchparen \
|
test_plugin_matchparen \
|
||||||
test_plugin_termdebug \
|
test_plugin_termdebug \
|
||||||
@ -513,6 +514,7 @@ NEW_TESTS_RES = \
|
|||||||
test_perl.res \
|
test_perl.res \
|
||||||
test_plugin_comment.res \
|
test_plugin_comment.res \
|
||||||
test_plugin_glvs.res \
|
test_plugin_glvs.res \
|
||||||
|
test_plugin_helptoc.res \
|
||||||
test_plugin_man.res \
|
test_plugin_man.res \
|
||||||
test_plugin_matchparen.res \
|
test_plugin_matchparen.res \
|
||||||
test_plugin_termdebug.res \
|
test_plugin_termdebug.res \
|
||||||
|
20
src/testdir/dumps/Test_helptoc_markdown_01.dump
Normal file
20
src/testdir/dumps/Test_helptoc_markdown_01.dump
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|#+0#e000e06#ffffff0| |M|y| |D|o|c|u|m|e|n|t| +0#0000000&@27|┌| |1|/|1| |(|1|/|1|)| @2|p|r|e|s@1| |?| |f|o|r| |h|e|l|p| |─@1|┐
|
||||||
|
| @40|│| |M+0#0000001#e0e0e08|y| |D|o|c|u|m|e|n|t| @18| +0#0000000#ffffff0|│
|
||||||
|
|S|o|m|e| |t|e|x|t|.| @30|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
| @40|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|`+0#e000e06&@2|v|i|m| +0#0000000&@34|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|#| |T|h|i|s| |i|s| |a| |V|i|m|9|S|c|r|i|p|t| |c|o|m@1|e|n|t| @10|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|d|e|f| |M|y|F|u|n|c|(|)| @28|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
| @1|#| |A|n|o|t|h|e|r| |c|o|m@1|e|n|t| @21|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|e|n|d@1|e|f| @34|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|`+0#e000e06&@2| +0#0000000&@37|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
> @40|│| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|│+0#0000000&| | +0#4040ff13&@29| +0#0000000&|│
|
||||||
|
|~+0#4040ff13&| @39|└+0#0000000&|─@31|┘
|
||||||
|
|:|H|e|l|p|T|o|c| @48|1@1|,|0|-|1| @7|A|l@1|
|
32
src/testdir/test_plugin_helptoc.vim
Normal file
32
src/testdir/test_plugin_helptoc.vim
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
" Test for the HelpTOC package
|
||||||
|
|
||||||
|
source util/screendump.vim
|
||||||
|
|
||||||
|
func Test_helptoc_markdown_with_comments()
|
||||||
|
CheckScreendump
|
||||||
|
let lines =<< trim END
|
||||||
|
packadd helptoc
|
||||||
|
e Xmarkdown.md
|
||||||
|
call append(0, [
|
||||||
|
\ '# My Document',
|
||||||
|
\ '', 'Some text.',
|
||||||
|
\ '',
|
||||||
|
\ '```vim',
|
||||||
|
\ '# This is a Vim9Script comment',
|
||||||
|
\ 'def MyFunc()',
|
||||||
|
\ ' # Another comment',
|
||||||
|
\ 'enddef',
|
||||||
|
\ '```'
|
||||||
|
\])
|
||||||
|
END
|
||||||
|
|
||||||
|
let input_file = "Xhelptoc.vim"
|
||||||
|
call writefile(lines, input_file, "D")
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal($"-S {input_file}", {})
|
||||||
|
call term_sendkeys(buf, ":HelpToc\<cr>")
|
||||||
|
call WaitFor({-> term_getline(buf, 1) =~ 'press ? for help'})
|
||||||
|
call VerifyScreenDump(buf, 'Test_helptoc_markdown_01', {})
|
||||||
|
call term_sendkeys(buf, ":qa!\<cr>")
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
@ -719,6 +719,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1533,
|
||||||
/**/
|
/**/
|
||||||
1532,
|
1532,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user