Feature: vimwiki#base#linkify() with markdown syntax setting #994

This commit is contained in:
Tinmarino
2021-06-09 09:26:52 -04:00
parent 573e3d1952
commit 0181009dba
2 changed files with 60 additions and 35 deletions
+12 -7
View File
@@ -2884,20 +2884,20 @@ function! vimwiki#base#linkify() abort
" Transform: the url under the cursor to a wiki link
let g:page_title = ''
" save existing value of @u and delete url under the cursor into @u
" Save existing value of @u and delete url under the cursor into @u
let l:save_reg = @u
exe 'normal! "udiW'
" create a scratch buffer and switch to it
" Create a scratch buffer and switch to it
let current_buf = bufnr('')
let scratch_buf = bufnr('scratch', 1)
exe 'sil! ' . scratch_buf . 'buffer'
" load web page into scratch buffer using Nread with mode=2
" Load web page into scratch buffer using Nread with mode=2
" FIXME: on Windows, with vim 7/8 (not with nvim), makes the cmd.exe window show up (annoying)
exe 'sil! :2Nread ' . @u
" extract title from html
" Extract title from html
" Note: if URL cannot be downloaded the buffer is empty or contains a single
" line: 'Not found'
let page_ok=0
@@ -2912,9 +2912,14 @@ function! vimwiki#base#linkify() abort
exe current_buf . 'buffer'
if (page_ok)
" use template [[URL|DESCRIPTION]]
let template = g:vimwiki_global_vars.WikiLinkTemplate2
let link = substitute(template, '__LinkUrl__', @u, '')
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
" [DESC](URL)
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink2Template')
else
" [[URL]]
let link_tpl = g:vimwiki_global_vars.WikiLinkTemplate2
endif
let link = substitute(link_tpl, '__LinkUrl__', @u, '')
let link = substitute(link, '__LinkDescription__', g:page_title==#'' ? @u : g:page_title, '')
exe 'normal! i' . link
else
+20
View File
@@ -4,6 +4,26 @@
# in OS windows, linux
# Seems easy but tests are reaaly needed here
# Linkify function {{{1
# Issue #994
####################
Given vimwiki (abc def ghi jkl):
https://github.com/vimwiki/vimwiki
Do(call linkify):
:call vimwiki#base#linkify()\<CR>
Expect():
[[https://github.com/vimwiki/vimwiki|GitHub - vimwiki/vimwiki: Personal Wiki for Vim]]
Do(md: call linkify):
:call SetSyntax('markdown')\<CR>
:call vimwiki#base#linkify()\<CR>
Expect():
[GitHub - vimwiki/vimwiki: Personal Wiki for Vim](https://github.com/vimwiki/vimwiki)
# Link Normalisation {{{1
# And configuration