Handle markdown image links '![]()'.

This commit is contained in:
Rane Brown 2019-05-23 21:23:53 -06:00
parent 6755068152
commit 68233c51eb
4 changed files with 33 additions and 7 deletions

View File

@ -1272,6 +1272,20 @@ function! vimwiki#base#follow_link(split, ...)
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl')) \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif endif
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
" markdown image ![]()
if lnk ==# ''
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxImage')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
if lnk !=# ''
if lnk !~# '\%(\%('.vimwiki#vars#get_global('web_schemes1').'\):\%(\/\/\)\?\)\S\{-1,}'
" prepend file: scheme so link is opened by sytem handler if it isn't a web url
let lnk = 'file:'.lnk
endif
endif
endif
endif
if lnk != "" " cursor is indeed on a link if lnk != "" " cursor is indeed on a link
let processed_by_user_defined_handler = VimwikiLinkHandler(lnk) let processed_by_user_defined_handler = VimwikiLinkHandler(lnk)
if processed_by_user_defined_handler if processed_by_user_defined_handler

View File

@ -827,13 +827,17 @@ function! s:populate_extra_markdown_vars()
\ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator. \ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1EscapeCharsSuffix \ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1EscapeCharsSuffix
" TODO: image links too !! " image ![DESCRIPTION](URL)
let mkd_syntax.rxImage = '!' . mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
let mkd_syntax.rxWeblink1Prefix1 = mkd_syntax.rxWeblink1Prefix let mkd_syntax.rxWeblink1Prefix1 = mkd_syntax.rxWeblink1Prefix
let mkd_syntax.rxWeblink1Suffix1 = mkd_syntax.rxWeblink1Separator. let mkd_syntax.rxWeblink1Suffix1 = mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix \ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
" *a) match ANY weblink " *a) match ANY weblink (exclude image links starting with !)
let mkd_syntax.rxWeblink = ''. let mkd_syntax.rxWeblink = '\(!\)\@<!'.
\ mkd_syntax.rxWeblink1.'\|'. \ mkd_syntax.rxWeblink1.'\|'.
\ mkd_syntax.rxWeblink0 \ mkd_syntax.rxWeblink0
" *b) match URL within ANY weblink " *b) match URL within ANY weblink
@ -846,7 +850,8 @@ function! s:populate_extra_markdown_vars()
\ mkd_syntax.rxWeblinkMatchDescr0 \ mkd_syntax.rxWeblinkMatchDescr0
let mkd_syntax.rxAnyLink = mkd_syntax.rxWikiLink.'\|'. let mkd_syntax.rxAnyLink = mkd_syntax.rxWikiLink.'\|'.
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.mkd_syntax.rxWeblink \ g:vimwiki_global_vars.rxWikiIncl.'\|'.mkd_syntax.rxWeblink .'\|'.
\ mkd_syntax.rxImage
let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'. let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ mkd_syntax.rxWeblink0 \ mkd_syntax.rxWeblink0

View File

@ -1150,9 +1150,6 @@ Inline link: >
Image link: > Image link: >
![Looks like this](URL) ![Looks like this](URL)
The URL can be anything recognized by Vimwiki as a raw URL.
Reference-style links: > Reference-style links: >
a) [Link Name][Id] a) [Link Name][Id]
b) [Id][], using the "implicit link name" shortcut b) [Id][], using the "implicit link name" shortcut
@ -3520,6 +3517,7 @@ Removed:~
point. point.
Fixed:~ Fixed:~
* Properly handle markdown image links `![]()`
* Issue #415: Expand iabbrev entries on <CR>. * Issue #415: Expand iabbrev entries on <CR>.
* Issue #619: allow escaped characters in markdown links. * Issue #619: allow escaped characters in markdown links.
* Issue #240: Fix regex pattern for markdown '[]()' links * Issue #240: Fix regex pattern for markdown '[]()' links

View File

@ -99,6 +99,7 @@ endif
" Weblink " Weblink
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1') call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1')
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxImage'), 'VimwikiImage')
" WikiLink " WikiLink
@ -157,6 +158,12 @@ execute 'syn match VimwikiWeblink1Char "'.
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options \ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
execute 'syn match VimwikiWeblink1Char "'. execute 'syn match VimwikiWeblink1Char "'.
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options \ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
"image
execute 'syn match VimwikiImageChar "!"'.s:options
execute 'syn match VimwikiImageChar "'.
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
execute 'syn match VimwikiImageChar "'.
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
if exists("+conceallevel") if exists("+conceallevel")
syntax conceal off syntax conceal off
@ -186,6 +193,8 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
" syntax group highlighting " syntax group highlighting
hi def link VimwikiImage VimwikiLink
hi def link VimwikiImageT VimwikiLink
hi def link VimwikiWeblink1 VimwikiLink hi def link VimwikiWeblink1 VimwikiLink
hi def link VimwikiWeblink1T VimwikiLink hi def link VimwikiWeblink1T VimwikiLink