Skip to content

Commit

Permalink
feat(gx): handle links with <caption inside_>_
Browse files Browse the repository at this point in the history
For example, `exits through with-statements <issue 1270_>`_ in the
following snippet:

- Python 3.11 is supported (tested with 3.11.0a2).  One open issue has to do
  with `exits through with-statements <issue 1270_>`_.

.. _issue 1270: nedbat/coveragepy#1270

Closes #10
  • Loading branch information
habamax committed Nov 11, 2021
1 parent ff3b60d commit 24643ad
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions autoload/rst.vim
Expand Up @@ -195,6 +195,7 @@ endfunc
" - `anonymous link`__
" - namedlink_
" - `named link with spaces`_
" - `named link with <actual link name_>`_
" - naked urls
func! rst#gx() abort
" URL regexes
Expand Down Expand Up @@ -253,16 +254,17 @@ func! rst#gx() abort
" ...
" `Google search`_
" .. _Yandex: https://yandex.ru
"
" angle brackets `exits through with-statements <issue 1270_>`_.
"
".. _issue 1270: https://github.com/nedbat/coveragepy/issues/1270
try
let save_view = winsaveview()
let url_start = '\%(^\|[[:space:][\]()"' . "'" . '-:/]\)\zs`\ze[^`[:space:]]'
let url_end = '\S\zs`_\ze\%($\|[[:space:].,:;!?"' . "." . '/\\>)\]}]\)'
let url_name = ''
if expand("<cfile>") =~ '^.*[^_]_$'
let url_name = expand("<cfile>")[:-2]
endif
if empty(url_name)
if getline('.')[col('.') - 2:] =~ '`_'
if col('.') > 2 && getline('.')[col('.') - 2 : col('.') + 2] =~ '`_'
normal! 2h
endif
if searchpair(url_start, '', url_end, 'cbW') > 0
Expand All @@ -275,6 +277,12 @@ func! rst#gx() abort
let url_name = getline(line('.') - 1)[s_pos[2] : ]
let url_name .= ' ' . getline('.')[: e_pos[2] - 2]
endif
" Check for angle brackets `exits through with-statements <issue 1270_>`_
" and use it instead
let url_sub_name = matchstr(url_name, '<\zs.\{-}[^_]\ze_>')
if !empty(url_sub_name)
let url_name = url_sub_name
endif
let url_name = substitute(url_name, '\s\+', '\\s\\+', 'g')
endif
endif
Expand All @@ -287,6 +295,9 @@ func! rst#gx() abort
endif
endif
endif
if empty(url_name) && expand("<cfile>") =~ '^.*[^_]_$'
let url_name = expand("<cfile>")[:-2]
endif
finally
call winrestview(save_view)
endtry
Expand Down

0 comments on commit 24643ad

Please sign in to comment.