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) let segments = split(anchor, '#', 0)
for segment in segments 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( let anchor_header = s:safesubstitute(
\ vimwiki#vars#get_syntaxlocal('header_match'), \ vimwiki#vars#get_syntaxlocal('header_match'),
\ '__Header__', segment, '') \ '__Header__', segment, '')
@ -864,6 +872,11 @@ endfunction
" Open file (like :e) " 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 function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
let fname = escape(a:filename, '% *|#`') let fname = escape(a:filename, '% *|#`')
let dir = fnamemodify(a:filename, ':p:h') let dir = fnamemodify(a:filename, ':p:h')

View File

@ -1,4 +1,40 @@
# Link internal to a file # 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):
\<Cr>
A__HERE__\<Esc>
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): Given vimwiki (Internal links + one link to filenew):
# Contents # Contents
@ -220,3 +256,5 @@ Expect (Some chars appended at self link):
- [ this_is_18_chars My own file](wiki_test) - [ this_is_18_chars My own file](wiki_test)
- [Test1](#Test1) - [Test1](#Test1)
- [Test2](#Test2) - [Test2](#Test2)
# vim: foldmethod=marker foldlevel=30 sw=2