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
This commit is contained in:
Tinmarino
2020-07-30 00:45:28 -04:00
parent 2332dc1514
commit 355c1f76b0
2 changed files with 51 additions and 0 deletions

View File

@ -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 <string>: ':e'
" :param: filename <strign> 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')