Permit tags in heading #1316

This commit is contained in:
Tinmarino
2023-03-17 00:03:47 -03:00
parent eab70aedaa
commit 035b2f15c7
2 changed files with 181 additions and 1 deletions
+2 -1
View File
@@ -117,7 +117,8 @@ function! s:scan_tags(lines, page_name) abort
endfor
let current_complete_anchor .= header
endif
continue " tags are not allowed in headers
" See: issue #1316 to allow tags in header
" continue " tags are not allowed in headers
endif
" Scan line for tags. There can be many of them.
+179
View File
@@ -4,6 +4,95 @@
Execute (Setup):
set sw=4
AssertEqual 4, &sw
call system("rm $HOME/testmarkdown/.vimwiki_tags")
######################################################################
Do (Create File Content with default tags {{{1):
:edit $HOME/testmarkdown/Test-Tag-default.md\<CR>
I
:tag1:tag2:\<CR>
\<Esc>
:write\<CR>
:VimwikiRebuildTags!\<CR>
:VimwikiGenerateTagLinks\<CR>
gg
Execute (Generate tags for default):
edit $HOME/testmarkdown/Test-Tag-default.md
AssertEqual 'VimwikiTag', SyntaxAt(1, 2)
1
VimwikiGenerateTagLinks
write
Expect (Tags default):
:tag1:tag2:
# Generated Tags
## tag1
- [Test-Tag-default](Test-Tag-default)
## tag2
- [Test-Tag-default](Test-Tag-default)
Execute (Clean tag file for default):
call system("rm $HOME/testmarkdown/.vimwiki_tags")
Do (Create File Content with default tags):
:edit $HOME/testmarkdown/Test-Tag-default.md\<CR>
ggdG
I
# Generated Tags\<Cr>
\<Cr>
# Heading with my tags\<Cr>
\<Cr>
:tag1:tag2:\<CR>
\<Cr>
Dummy content 1
\<Cr>
# Another heading\<Cr>
\<Cr>
Dummy content 2
\<Esc>
:write\<CR>
:VimwikiRebuildTags!\<CR>
:VimwikiGenerateTagLinks\<CR>
gg
Expect (Tags default with Generated Tags heading):
# Generated Tags
## tag1
- [Heading with my tags](Test-Tag-default#heading-with-my-tags)
## tag2
- [Heading with my tags](Test-Tag-default#heading-with-my-tags)
# Heading with my tags
:tag1:tag2:
Dummy content 1
# Another heading
Dummy content 2
Execute (Clean file for tag default):
call system("rm $HOME/testmarkdown/.vimwiki_tags")
call system("rm $HOME/testmarkdown/Test-Tag-default.md")
######################################################################
@@ -16,6 +105,7 @@ Execute (Change delimiter <tag1|tag2> {{{1):
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
Do (Create File Content with <>):
:edit $HOME/testmarkdown/Test-Tag.md\<CR>
I
@@ -40,6 +130,7 @@ Execute (Generate tags):
VimwikiGenerateTagLinks
set tw=200
Expect (Correctly generated tags section {{{3):
<tag-bar-1>
@@ -77,12 +168,14 @@ Do (Write a quick tag for a quick jump):
ggl\<Cr>A __HERE1__\<Esc>
ggjl\<Cr>A __HERE2__\<Esc>
Expect (Good jump {{{3):
[go1](Test-Tag#tag-bar-1)
[go2](#tag-bar-1)
bla
<tag-bar-1> __HERE1__ __HERE2__
Execute (Clean Test-Tag and .vimwiki_tags -2):
let g:vimwiki_tag_format = {}
unlet g:vimwiki_syntaxlocal_vars
@@ -101,6 +194,7 @@ Execute (Default tag generation {{{1):
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
set tw=200
Do (Single file Part1):
:edit $HOME/testmarkdown/Test-Tag.md\<Cr>
ggdGO
@@ -108,12 +202,14 @@ Do (Single file Part1):
:write\<Cr>
:VimwikiRebuildTags!\<Cr>
Execute (Generate tags):
edit $HOME/testmarkdown/Test-Tag.md
AssertEqual 'VimwikiTag', SyntaxAt(1, 1)
VimwikiGenerateTagLinks
write
Expect (Single tags toc):
:single-tag:
@@ -145,12 +241,14 @@ Do (Create File Content):
:write\<CR>
:VimwikiRebuildTags\<CR>
Execute (Edit tags file):
edit $HOME/testmarkdown/.vimwiki_tags
AssertEqual $HOME . '/testmarkdown/.vimwiki_tags', expand('%')
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
# Note: tags file uses tabs
Expect (Correctly formatted tags file):
!_TAG_FILE_FORMAT 2
@@ -164,10 +262,12 @@ Expect (Correctly formatted tags file):
test-tag Test-Tag.md 5;" vimwiki:Test-Tag\tTest-Tag#a-header\tA header
top-tag Test-Tag.md 1;" vimwiki:Test-Tag\tTest-Tag\tTest-Tag
Execute (Generate tags):
edit $HOME/testmarkdown/Test-Tag.md
VimwikiGenerateTagLinks
Expect (Correctly generated tags section):
:top-tag:
@@ -198,6 +298,7 @@ Expect (Correctly generated tags section):
- [Test-Tag](Test-Tag)
Execute (Clean Test-Tag and .vimwiki_tags -1 ):
call system("rm $HOME/testmarkdown/Test.md")
call system("rm $HOME/testmarkdown/.vimwiki_tags")
@@ -214,6 +315,7 @@ Execute (Check first tags file):
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
Do (Build first tags file):
:edit $HOME/testmarkdown/Test-Tag-1.md\<Cr>
ggI
@@ -228,12 +330,14 @@ Do (Build first tags file):
:write\<Cr>
:VimwikiRebuildTags!\<CR>
Execute (Check second tags file):
edit $HOME/testmarkdown/subdir1/Test-Tag-2.md
AssertEqual $HOME . '/testmarkdown/subdir1/Test-Tag-2.md', expand('%')
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
Do (Build second tags file):
:edit $HOME/testmarkdown/subdir1/Test-Tag-2.md\<Cr>
ggI
@@ -248,6 +352,7 @@ Do (Build second tags file):
:write\<Cr>
:VimwikiRebuildTags!\<CR>
Execute (Build tag links in third file):
edit $HOME/testmarkdown/subdir1/subdir11/Test-Tag-Links.md
AssertEqual $HOME . '/testmarkdown/subdir1/subdir11/Test-Tag-Links.md', expand('%')
@@ -256,6 +361,7 @@ Execute (Build tag links in third file):
VimwikiGenerateTagLinks
write
Expect (Tag links relative to current file):
@@ -276,6 +382,7 @@ Expect (Tag links relative to current file):
- [standalone-tag-1](../../Test-Tag-1#standalone-tag-1)
- [standalone-tag-1](../Test-Tag-2#standalone-tag-1)
Do (Delete some existing links to test updating generated tag links):
:edit $HOME/testmarkdown/subdir1/subdir11/Test-Tag-Links.md\<Cr>
7G
@@ -285,6 +392,7 @@ Do (Delete some existing links to test updating generated tag links):
:write\<Cr>
:call vimwiki#tags#generate_tags(0)\<Cr>
Expect (Only update generated tag links for tags already existing in the file):
@@ -300,6 +408,77 @@ Expect (Only update generated tag links for tags already existing in the file):
- [Another Header](../../Test-Tag-1#another-header)
- [Another Header](../Test-Tag-2#another-header)
Execute (Clean relative tag setup):
call system("rm $HOME/testmarkdown/.vimwiki_tags")
call system("rm -rf $HOME/testmarkdown/subdir1")
call system("rm $HOME/testmarkdown/Test-Tag-1.md")
######################################################################
Execute (Change delimiter #tag1content1|content2#tag2 as for issue #1316 {{{1):
let g:vimwiki_tag_format = {'pre_mark': '#tag1', 'post_mark': '#tag2', 'sep': '|'}
unlet g:vimwiki_syntaxlocal_vars
call vimwiki#vars#init()
edit $HOME/testmarkdown/Test-Tag-1316.md
AssertEqual $HOME . '/testmarkdown/Test-Tag-1316.md', expand('%')
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
Do (Create File Content with #tag1 #tag2 as for issue #1316):
:edit $HOME/testmarkdown/Test-Tag-issue-1316.md\<CR>
I
# Line1: Heading
# A header\<CR>
# Line2: Tag not in header
bla #tag1content01|content02#tag2\<CR>
# Line3: Tag in header
#tag1content11|content12#tag2\<CR>
# Line4: empty
\<CR>
# Line5: dummy content
Words here.
\<Esc>
:write\<CR>
:VimwikiRebuildTags!\<CR>
gg
Execute (Generate tags for issue #1316):
edit $HOME/testmarkdown/Test-Tag-issue-1316.md
AssertEqual 'VimwikiTag', SyntaxAt(2, 5)
1
VimwikiGenerateTagLinks
write
Expect (Single tags toc):
# A header
bla #tag1content01|content02#tag2
#tag1content11|content12#tag2
Words here.
# Generated Tags
## content01
- [A header](Test-Tag-issue-1316#a-header)
## content02
- [A header](Test-Tag-issue-1316#a-header)
## content11
- [tag2](Test-Tag-issue-1316#tag1content11content12tag2)
## content12
- [tag2](Test-Tag-issue-1316#tag1content11content12tag2)
Execute (Clean file for tag #1316):
call system("rm $HOME/testmarkdown/.vimwiki_tags")
call system("rm $HOME/testmarkdown/Test-Tag-issue-1316.md")