Skip to content

Commit

Permalink
Inline literal escape support; doc updates
Browse files Browse the repository at this point in the history
Escape character support was disabled for inline literals, which are
handled separately from standard inline highlights, in that escape
characters are unsupported.

Also adding maintainer info to several other language support files.
  • Loading branch information
marshallward committed Apr 30, 2020
1 parent 0cc9be0 commit 88a3297
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ftplugin/rst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
" Maintainer: Marshall Ward <[email protected]>
" Original Maintainer: Nikolai Weibull <[email protected]>
" Website: https://github.com/marshallward/vim-restructuredtext
" Latest Revision: 2018-12-29
" Latest Revision: 2020-03-31

if exists("b:did_ftplugin")
finish
Expand Down
8 changes: 5 additions & 3 deletions indent/rst.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
" Vim indent file
" Language: reStructuredText Documentation Format
" Previous Maintainer: Nikolai Weibull <[email protected]>
" Latest Revision: 2011-08-03
" Vim reST indent file
" Language: reStructuredText Documentation Format
" Maintainer: Marshall Ward <[email protected]>
" Previous Maintainer: Nikolai Weibull <[email protected]>
" Latest Revision: 2020-03-31

if exists("b:did_indent")
finish
Expand Down
30 changes: 20 additions & 10 deletions syntax/rst.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
" Vim syntax file
" Vim reST syntax file
" Language: reStructuredText documentation format
" Maintainer: Marshall Ward <[email protected]>
" Previous Maintainer: Nikolai Weibull <[email protected]>
" Website: https://github.com/marshallward/vim-restructuredtext
" Latest Revision: 2018-12-29
" Latest Revision: 2020-03-31

if exists("b:current_syntax")
finish
Expand Down Expand Up @@ -97,22 +97,32 @@ function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_righ
let first = a:start[0]
endif

execute 'syn match rstEscape'.a:name.' +\\\\\|\\'.first.'+'.' contained'
if a:start != '``'
let rst_contains=' contains=rstEscape' . a:name
execute 'syn match rstEscape'.a:name.' +\\\\\|\\'.first.'+'.' contained'
else
let rst_contains=''
endif

execute 'syn region rst' . a:name .
\ ' start=+' . a:char_left . '\zs' . a:start .
\ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' .
\ a:middle .
\ ' end=+' . a:end . '\ze\%($\|\s\|[''"’)\]}>/:.,;!?\\-]\)+' .
\ ' contains=rstEscape' . a:name
\ rst_contains

execute 'hi def link rstEscape'.a:name.' Special'
if a:start != '``'
execute 'hi def link rstEscape'.a:name.' Special'
endif
endfunction

" TODO: The "middle" argument may no longer be useful here.
function! s:DefineInlineMarkup(name, start, middle, end)
let middle = a:middle != "" ?
\ (' skip=+\\\\\|\\' . a:middle . '\|\s' . a:middle . '+') :
\ ""
if a:middle == '`'
let middle = ' skip=+\s'.a:middle.'+'
else
let middle = ' skip=+\\\\\|\\' . a:middle . '\|\s' . a:middle . '+'
endif

call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'")
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"')
Expand All @@ -121,8 +131,8 @@ function! s:DefineInlineMarkup(name, start, middle, end)
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '{', '}')
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '<', '>')
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '', '')
" TODO: Additional Unicode Pd, Po, Pi, Pf, Ps characters

" TODO: Additional whitespace Unicode characters: Pd, Po, Pi, Pf, Ps
call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|\%ua0\|[/:]\)', '')

execute 'syn match rst' . a:name .
Expand All @@ -136,7 +146,7 @@ endfunction
call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*')
call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*')
call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}')
call s:DefineInlineMarkup('InlineLiteral', '``', "", '``')
call s:DefineInlineMarkup('InlineLiteral', '``', '`', '``')
call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}')
call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`')

Expand Down
7 changes: 7 additions & 0 deletions tests/codeblocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ Fields with a named language (not currently working)
return 0;
}

Code blocks require a blank line after the directive, so this should not
highlight. (Note: currently fails)

.. code::
int main(void) {
return 0;
}
35 changes: 29 additions & 6 deletions tests/escape_delim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ Escape the delimiter:
Delimiters with leading spaces do not act as delimiters:
[space][delim][non-space]...[non-space][delim][space]

start *This delim * is not a delim*
start *This delim *is also not a delim*
start *This token * is not a delim*

Double delimiters?
start *This token *is also not a delim*

Double delimiters must also be supported:

start **This is a double delim** end

Escape a double delimiter?
Double delimiter spaced inside of a double delimiter?

start **This token ** is not a delim** end

start **This token **is also not a delim** end

Single delimiters are escaped inside of double delimiters

start **This is \** two delimiters inside a double delimiter** end
start **This is \** a double delimiters inside a double delimiter** end

start **This one is \*\* escaped twice** end

Escape slashes inside delimiters.

Expand All @@ -35,13 +44,27 @@ Escape slashes inside delimiters.
start *C:\* end

(Putting a delimiter here* to balance the syntax highlighting error.)

But there is an exception for the end of `` tokens:

Inline literal without escape characters:

start ``Text is highlighted`` end

start ``This slash\is unescaped`` end

start ``This has\\two slashes and is not escaped`` end

start ``This slash\`is also not escaped`` end

This renders a single slash and should not be escaped:

start ``C:\`` end

Space-separated inline literal tokens do not terminate the region:

start ``C:\ `` C:\`` end

This renders two slashes:

start ``C:\\`` end
Expand Down

0 comments on commit 88a3297

Please sign in to comment.