Allow escaped characters in markdown links.

Fixes #619
This commit is contained in:
Rane Brown 2019-05-08 21:30:06 -06:00
parent cde4703354
commit c05037a490
3 changed files with 13 additions and 9 deletions

View File

@ -117,8 +117,9 @@ function! vimwiki#base#resolve_link(link_text, ...)
let source_file = vimwiki#path#current_wiki_file() let source_file = vimwiki#path#current_wiki_file()
endif endif
let link_text = a:link_text " get rid of '\' in escaped characters in []() style markdown links
" other style links don't allow '\'
let link_text = substitute(a:link_text, '\(\\\)\(\W\)\@=', '', 'g')
let link_infos = { let link_infos = {
\ 'index': -1, \ 'index': -1,

View File

@ -769,6 +769,7 @@ function! s:populate_extra_markdown_vars()
let mkd_syntax.rxWeblink1Prefix = '[' let mkd_syntax.rxWeblink1Prefix = '['
let mkd_syntax.rxWeblink1Suffix = ')' let mkd_syntax.rxWeblink1Suffix = ')'
let mkd_syntax.rxWeblink1EscapeCharsSuffix = '\(\\\)\@<!\()\)'
let mkd_syntax.rxWeblink1Separator = '](' let mkd_syntax.rxWeblink1Separator = ']('
let mkd_syntax.rxWeblink1Ext = '' let mkd_syntax.rxWeblink1Ext = ''
if vimwiki#vars#get_global('markdown_link_ext') if vimwiki#vars#get_global('markdown_link_ext')
@ -787,11 +788,12 @@ function! s:populate_extra_markdown_vars()
\ '#__LinkAnchor__'. mkd_syntax.rxWeblink1Suffix \ '#__LinkAnchor__'. mkd_syntax.rxWeblink1Suffix
let valid_chars = '[^\\\]]' let valid_chars = '[^\\\]]'
" spaces and '\' must be allowed for filename and escaped chars
let valid_chars_url = '[^[:cntrl:]]'
let mkd_syntax.rxWeblink1Prefix = vimwiki#u#escape(mkd_syntax.rxWeblink1Prefix) let mkd_syntax.rxWeblink1Prefix = vimwiki#u#escape(mkd_syntax.rxWeblink1Prefix)
let mkd_syntax.rxWeblink1Suffix = vimwiki#u#escape(mkd_syntax.rxWeblink1Suffix)
let mkd_syntax.rxWeblink1Separator = vimwiki#u#escape(mkd_syntax.rxWeblink1Separator) let mkd_syntax.rxWeblink1Separator = vimwiki#u#escape(mkd_syntax.rxWeblink1Separator)
let mkd_syntax.rxWeblink1Url = valid_chars.'\{-}' let mkd_syntax.rxWeblink1Url = valid_chars_url.'\{-}'
let mkd_syntax.rxWeblink1Descr = valid_chars.'\{-}' let mkd_syntax.rxWeblink1Descr = valid_chars.'\{-}'
let mkd_syntax.WikiLinkMatchUrlTemplate = let mkd_syntax.WikiLinkMatchUrlTemplate =
\ mkd_syntax.rx_wikilink_md_prefix . \ mkd_syntax.rx_wikilink_md_prefix .
@ -809,26 +811,26 @@ function! s:populate_extra_markdown_vars()
\ '.*' . \ '.*' .
\ mkd_syntax.rxWeblink1Separator. \ mkd_syntax.rxWeblink1Separator.
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%('.vimwiki#vars#get_wikilocal('ext').'\)\?'. \ '\zs__LinkUrl__\ze\%(#.*\)\?\%('.vimwiki#vars#get_wikilocal('ext').'\)\?'.
\ mkd_syntax.rxWeblink1Suffix \ mkd_syntax.rxWeblink1EscapeCharsSuffix
" 1. [DESCRIPTION](URL) " 1. [DESCRIPTION](URL)
" 1a) match [DESCRIPTION](URL) " 1a) match [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1 = mkd_syntax.rxWeblink1Prefix. let mkd_syntax.rxWeblink1 = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Separator. \ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1Suffix \ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
" 1b) match URL within [DESCRIPTION](URL) " 1b) match URL within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchUrl = mkd_syntax.rxWeblink1Prefix. let mkd_syntax.rxWeblink1MatchUrl = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Descr. mkd_syntax.rxWeblink1Separator. \ mkd_syntax.rxWeblink1Descr. mkd_syntax.rxWeblink1Separator.
\ '\zs' . mkd_syntax.rxWeblink1Url . '\ze' . mkd_syntax.rxWeblink1Suffix \ '\zs' . mkd_syntax.rxWeblink1Url . '\ze' . mkd_syntax.rxWeblink1EscapeCharsSuffix
" 1c) match DESCRIPTION within [DESCRIPTION](URL) " 1c) match DESCRIPTION within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchDescr = mkd_syntax.rxWeblink1Prefix. let mkd_syntax.rxWeblink1MatchDescr = mkd_syntax.rxWeblink1Prefix.
\ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator. \ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1Suffix \ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1EscapeCharsSuffix
" TODO: image links too !! " TODO: image links too !!
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.rxWeblink1Suffix \ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1EscapeCharsSuffix
" *a) match ANY weblink " *a) match ANY weblink
let mkd_syntax.rxWeblink = ''. let mkd_syntax.rxWeblink = ''.

View File

@ -3487,6 +3487,7 @@ Removed:~
point. point.
Fixed:~ Fixed:~
* Issue #619: allow escaped characters in markdown links.
* Issue #240: Fix regex pattern for markdown '[]()' links * Issue #240: Fix regex pattern for markdown '[]()' links
* Issue #685: Error message for invalid user options fixed. * Issue #685: Error message for invalid user options fixed.
* Issue #481: Allow surrounding URLs with '<' '>' * Issue #481: Allow surrounding URLs with '<' '>'