Allow markdown syntax to have tags at top of file.
Previously tags that did not fall under a header caused errors because the generation code expected an anchor. Update tags test case. Closes #790
This commit is contained in:
parent
b9eec79cc6
commit
b4e0f738a3
@ -354,16 +354,18 @@ function! vimwiki#tags#generate_tags(create, ...) abort
|
|||||||
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template')
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template')
|
||||||
let link_infos = vimwiki#base#resolve_link(taglink)
|
let link_infos = vimwiki#base#resolve_link(taglink)
|
||||||
if empty(link_infos.anchor)
|
if empty(link_infos.anchor)
|
||||||
echom 'Vimwiki Error: Tags must appear after a header.'
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
|
||||||
return []
|
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', taglink, '')
|
||||||
endif
|
let entry = s:safesubstitute(entry, '__LinkDescription__', taglink, '')
|
||||||
|
else
|
||||||
let link_caption = split(link_infos.anchor, '#', 0)[-1]
|
let link_caption = split(link_infos.anchor, '#', 0)[-1]
|
||||||
let link_text = split(taglink, '#', 1)[0]
|
let link_text = split(taglink, '#', 1)[0]
|
||||||
|
|
||||||
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link_text, '')
|
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link_text, '')
|
||||||
let entry = s:safesubstitute(entry, '__LinkAnchor__', link_infos.anchor, '')
|
let entry = s:safesubstitute(entry, '__LinkAnchor__', link_infos.anchor, '')
|
||||||
let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '')
|
let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '')
|
||||||
call add(lines, bullet.entry)
|
endif
|
||||||
|
|
||||||
|
call add(lines, bullet . entry)
|
||||||
else
|
else
|
||||||
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
|
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
|
||||||
call add(lines, bullet . substitute(link_tpl, '__LinkUrl__', taglink, ''))
|
call add(lines, bullet . substitute(link_tpl, '__LinkUrl__', taglink, ''))
|
||||||
|
@ -1,67 +1,90 @@
|
|||||||
Include: vader_includes/vader_setup.vader
|
Include: vader_includes/vader_setup.vader
|
||||||
|
|
||||||
|
|
||||||
Execute (Copy Wiki's Resources):
|
Execute (Copy Wiki's Resources):
|
||||||
Log "Start: Copy Resources"
|
Log "Start: Copy Resources"
|
||||||
call CopyResources()
|
call CopyResources()
|
||||||
|
|
||||||
|
Execute (Setup):
|
||||||
# 1 VimwikiRebuildTags
|
|
||||||
######################
|
|
||||||
|
|
||||||
Execute (New Command):
|
|
||||||
Log "1 Testing VimwikiRebuildTags"
|
|
||||||
set sw=4
|
set sw=4
|
||||||
AssertEqual 4, &sw
|
AssertEqual 4, &sw
|
||||||
|
|
||||||
|
|
||||||
Execute (Edit Test-Tag.md):
|
Execute (Edit Test-Tag.md):
|
||||||
edit $HOME/testmarkdown/Test-Tag.md
|
edit $HOME/testmarkdown/Test-Tag.md
|
||||||
AssertEqual $HOME . '/testmarkdown/Test-Tag.md', expand('%')
|
AssertEqual $HOME . '/testmarkdown/Test-Tag.md', expand('%')
|
||||||
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
|
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
|
||||||
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
|
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||||
|
|
||||||
Do (Add tag <- with `Do` trick to save file):
|
Do (Create File Content):
|
||||||
:edit $HOME/testmarkdown/Test-Tag.md\<CR>
|
:edit $HOME/testmarkdown/Test-Tag.md\<CR>
|
||||||
:call append(0, ":test-tag:")\<CR>
|
I
|
||||||
:set bt=\<CR>
|
:top-tag:\<CR>
|
||||||
:write %\<CR>
|
\<CR>
|
||||||
|
# A header\<CR>
|
||||||
|
\<CR>
|
||||||
|
:test-tag:\<CR>
|
||||||
|
\<CR>
|
||||||
|
# Another header\<CR>
|
||||||
|
\<CR>
|
||||||
|
Words here.\<CR>
|
||||||
|
If tag isn't within 2 lines of header then it has a direct link instead of\<CR>
|
||||||
|
a link to the header.\<CR>
|
||||||
|
\<CR>
|
||||||
|
:second-tag:
|
||||||
|
\<Esc>
|
||||||
|
:write\<CR>
|
||||||
:VimwikiRebuildTags\<CR>
|
:VimwikiRebuildTags\<CR>
|
||||||
|
|
||||||
Execute (Edit .vimwiki_tags):
|
Execute (Edit tags file):
|
||||||
edit $HOME/testmarkdown/.vimwiki_tags
|
edit $HOME/testmarkdown/.vimwiki_tags
|
||||||
AssertEqual $HOME . '/testmarkdown/.vimwiki_tags', expand('%')
|
AssertEqual $HOME . '/testmarkdown/.vimwiki_tags', expand('%')
|
||||||
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
|
AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax')
|
||||||
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
|
AssertEqual 1, vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||||
|
|
||||||
# Carefull, following 2 lines have tabs: `this is the way`
|
# Note: tags file uses tabs
|
||||||
Expect (Tag file with test-tag):
|
Expect (Correctly formatted tags file):
|
||||||
|
!_TAG_FILE_FORMAT 2
|
||||||
!_TAG_FILE_SORTED 1
|
!_TAG_FILE_SORTED 1
|
||||||
test-tag Test-Tag.md 1;" vimwiki:Test-Tag\tTest-Tag
|
!_TAG_OUTPUT_MODE vimwiki-tags
|
||||||
|
!_TAG_PROGRAM_AUTHOR Vimwiki
|
||||||
|
!_TAG_PROGRAM_NAME Vimwiki Tags
|
||||||
|
!_TAG_PROGRAM_URL https://github.com/vimwiki/vimwiki
|
||||||
|
!_TAG_PROGRAM_VERSION 2.4.1
|
||||||
|
second-tag Test-Tag.md 13;" vimwiki:Test-Tag\tTest-Tag#second-tag
|
||||||
|
test-tag Test-Tag.md 5;" vimwiki:Test-Tag\tTest-Tag#A header
|
||||||
|
top-tag Test-Tag.md 1;" vimwiki:Test-Tag\tTest-Tag
|
||||||
|
|
||||||
|
Execute (Generate tags):
|
||||||
|
edit $HOME/testmarkdown/Test-Tag.md
|
||||||
|
VimwikiGenerateTags
|
||||||
|
|
||||||
# 2 VimwikiGenerateTags
|
Expect (Correctly generated tags section):
|
||||||
#########################
|
:top-tag:
|
||||||
|
|
||||||
Execute (New Command):
|
# A header
|
||||||
Log "2 Testing VimwikiGenerateTags TODO"
|
|
||||||
set sw=4
|
|
||||||
AssertEqual 4, &sw
|
|
||||||
|
|
||||||
Given (Void):
|
:test-tag:
|
||||||
|
|
||||||
Do (Edit Test-Tag && GenerateTags):
|
# Another header
|
||||||
:edit $HOME/testmarkdown/Test-Tag.md\<CR>
|
|
||||||
:call append(0, ':Tag:')\<Cr>
|
|
||||||
:call append(0, '')\<Cr>
|
|
||||||
:call append(0, 'Test Here')\<Cr>
|
|
||||||
:call append(0, '')\<Cr>
|
|
||||||
:call append(0, '# A header')\<Cr>
|
|
||||||
:call WriteMe()\<CR>
|
|
||||||
:VimwikiRebuildTags\<CR>
|
|
||||||
:VimwikiGenerateTags\<CR>
|
|
||||||
:Log "TODO give the expect block when VimwikigenerateTags is working"\<CR>
|
|
||||||
|
|
||||||
|
Words here.
|
||||||
|
If tag isn't within 2 lines of header then it has a direct link instead of
|
||||||
|
a link to the header.
|
||||||
|
|
||||||
|
:second-tag:
|
||||||
|
|
||||||
|
# Generated Tags
|
||||||
|
|
||||||
|
## second-tag
|
||||||
|
|
||||||
|
- [second-tag](Test-Tag#second-tag)
|
||||||
|
|
||||||
|
## test-tag
|
||||||
|
|
||||||
|
- [A header](Test-Tag#A header)
|
||||||
|
|
||||||
|
## top-tag
|
||||||
|
|
||||||
|
- [Test-Tag](Test-Tag)
|
||||||
|
|
||||||
Execute (Clean Test-Tag and .vimwiki_tags):
|
Execute (Clean Test-Tag and .vimwiki_tags):
|
||||||
Log "End: Clean"
|
Log "End: Clean"
|
||||||
@ -70,6 +93,4 @@ Execute (Clean Test-Tag and .vimwiki_tags):
|
|||||||
call system("rm $HOME/testmarkdown/Test-Tag.md")
|
call system("rm $HOME/testmarkdown/Test-Tag.md")
|
||||||
call DeleteHiddenBuffers()
|
call DeleteHiddenBuffers()
|
||||||
|
|
||||||
|
|
||||||
Include: vader_includes/vader_teardown.vader
|
Include: vader_includes/vader_teardown.vader
|
||||||
# vim: sw=2 foldmethod=indent foldlevel=30 foldignore=
|
|
||||||
|
Loading…
Reference in New Issue
Block a user