vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit b4e0f738a32e0dbfdad6c74e22721d1872932ef8
parent b9eec79cc629aebf48a67d32b67cc1c4db953a65
Author: Rane Brown <rane.brown@gmail.com>
Date:   Mon, 30 Dec 2019 10:08:28 -0700

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

Diffstat:
Mautoload/vimwiki/tags.vim | 18++++++++++--------
Mtest/command_generate_tags.vader | 95++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
2 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/autoload/vimwiki/tags.vim b/autoload/vimwiki/tags.vim @@ -354,16 +354,18 @@ function! vimwiki#tags#generate_tags(create, ...) abort let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template') let link_infos = vimwiki#base#resolve_link(taglink) if empty(link_infos.anchor) - echom 'Vimwiki Error: Tags must appear after a header.' - return [] + let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template') + let entry = s:safesubstitute(link_tpl, '__LinkUrl__', taglink, '') + let entry = s:safesubstitute(entry, '__LinkDescription__', taglink, '') + else + let link_caption = split(link_infos.anchor, '#', 0)[-1] + let link_text = split(taglink, '#', 1)[0] + let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link_text, '') + let entry = s:safesubstitute(entry, '__LinkAnchor__', link_infos.anchor, '') + let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '') endif - let link_caption = split(link_infos.anchor, '#', 0)[-1] - let link_text = split(taglink, '#', 1)[0] - let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link_text, '') - let entry = s:safesubstitute(entry, '__LinkAnchor__', link_infos.anchor, '') - let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '') - call add(lines, bullet.entry) + call add(lines, bullet . entry) else let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1') call add(lines, bullet . substitute(link_tpl, '__LinkUrl__', taglink, '')) diff --git a/test/command_generate_tags.vader b/test/command_generate_tags.vader @@ -1,67 +1,90 @@ Include: vader_includes/vader_setup.vader - Execute (Copy Wiki's Resources): Log "Start: Copy Resources" call CopyResources() - -# 1 VimwikiRebuildTags -###################### - -Execute (New Command): - Log "1 Testing VimwikiRebuildTags" +Execute (Setup): set sw=4 AssertEqual 4, &sw - Execute (Edit Test-Tag.md): edit $HOME/testmarkdown/Test-Tag.md AssertEqual $HOME . '/testmarkdown/Test-Tag.md', expand('%') AssertEqual 'markdown', vimwiki#vars#get_wikilocal('syntax') 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> - :call append(0, ":test-tag:")\<CR> - :set bt=\<CR> - :write %\<CR> + I + :top-tag:\<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> -Execute (Edit .vimwiki_tags): +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') -# Carefull, following 2 lines have tabs: `this is the way` -Expect (Tag file with test-tag): - !_TAG_FILE_SORTED 1 - test-tag Test-Tag.md 1;" vimwiki:Test-Tag\tTest-Tag +# Note: tags file uses tabs +Expect (Correctly formatted tags file): + !_TAG_FILE_FORMAT 2 + !_TAG_FILE_SORTED 1 + !_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 +Expect (Correctly generated tags section): + :top-tag: -# 2 VimwikiGenerateTags -######################### + # A header -Execute (New Command): - Log "2 Testing VimwikiGenerateTags TODO" - set sw=4 - AssertEqual 4, &sw + :test-tag: -Given (Void): + # Another header -Do (Edit Test-Tag && GenerateTags): - :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): Log "End: Clean" @@ -70,6 +93,4 @@ Execute (Clean Test-Tag and .vimwiki_tags): call system("rm $HOME/testmarkdown/Test-Tag.md") call DeleteHiddenBuffers() - Include: vader_includes/vader_teardown.vader -# vim: sw=2 foldmethod=indent foldlevel=30 foldignore=