From 355c1f76b0b0c9cd8c2a39e84b09796c8ef1642f Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Thu, 30 Jul 2020 00:45:28 -0400 Subject: [PATCH] Feature: Follow links: Allow hyphens and case-insensitive (PR #840 from @bratekarate) Brief: Permits: ``` [Link to heading](#heading-example) ``` Issue: Feature Request: Support GFM anchor links inside wiki files #831 Original PR: Allow hyphens instead of spaces and search case-insensitive in jump_to_anchor function #840 Author: @bratekarate (implementation) @tinmarino (test) Related: #666 --- autoload/vimwiki/base.vim | 13 ++++++++ test/link_markdown_multiple_per_file.vader | 38 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 013bfd8..126b982 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -699,6 +699,14 @@ function! s:jump_to_anchor(anchor) abort let segments = split(anchor, '#', 0) for segment in segments + + " Craft segment pattern so that it is case insensitive and also matches dashes + " in anchor link with spaces in heading + " Ignore case + let segment = substitute(segment, '\<\(.\)', '\\c\1', 'g') + " Treat - as [- or space] + let segment = substitute(segment , '-', '[ -]', 'g') + let anchor_header = s:safesubstitute( \ vimwiki#vars#get_syntaxlocal('header_match'), \ '__Header__', segment, '') @@ -864,6 +872,11 @@ endfunction " Open file (like :e) +" :param: command : ':e' +" :param: filename vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext') +" :param: anchor +" :param: (1) vimwiki_prev_link +" :param: (2) vimwiki#u#ft_is_vw() function! vimwiki#base#edit_file(command, filename, anchor, ...) abort let fname = escape(a:filename, '% *|#`') let dir = fnamemodify(a:filename, ':p:h') diff --git a/test/link_markdown_multiple_per_file.vader b/test/link_markdown_multiple_per_file.vader index 34fbd6e..401fa2e 100644 --- a/test/link_markdown_multiple_per_file.vader +++ b/test/link_markdown_multiple_per_file.vader @@ -1,4 +1,40 @@ # Link internal to a file +# See issue #666 for anchor support (then internal links) + + +# Link to anchor with spaces {{{! +# PR #840 +# Issues: #831 + +Given vimwiki (Internal links zith spaces): + [Any ! apparent name @#$](#basic-heading-many-spaces) + One line here + + ## Basic HeAding Many SpacES + + One line here + +Execute (Set markdown): + file wiki_test.md + call SetSyntax('markdown') + +Do (Enter link): + \ + A__HERE__\ + +Expect (Cursor at heading position): + [Any ! apparent name @#$](#basic-heading-many-spaces) + One line here + + ## Basic HeAding Many SpacES__HERE__ + + One line here + +Execute (Clear wiki jumps (alias: prev_links)): + call vimwiki#vars#set_bufferlocal('prev_links', []) + + +# Before {{{1 Given vimwiki (Internal links + one link to filenew): # Contents @@ -220,3 +256,5 @@ Expect (Some chars appended at self link): - [ this_is_18_chars My own file](wiki_test) - [Test1](#Test1) - [Test2](#Test2) + +# vim: foldmethod=marker foldlevel=30 sw=2