Skip to content

Commit

Permalink
Feat: conceal backslash if it is a valid escape code leader
Browse files Browse the repository at this point in the history
This should close preservim#510
  • Loading branch information
flw-cn committed Sep 14, 2020
1 parent 8e5d86f commit a635953
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions syntax/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained

"HTML headings
syn region htmlH1 matchgroup=mkdHeading start="^\s*#" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH2 matchgroup=mkdHeading start="^\s*##" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH3 matchgroup=mkdHeading start="^\s*###" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH4 matchgroup=mkdHeading start="^\s*####" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH5 matchgroup=mkdHeading start="^\s*#####" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH6 matchgroup=mkdHeading start="^\s*######" end="$" contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH1 matchgroup=mkdHeading start="^\s*#" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn region htmlH2 matchgroup=mkdHeading start="^\s*##" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn region htmlH3 matchgroup=mkdHeading start="^\s*###" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn region htmlH4 matchgroup=mkdHeading start="^\s*####" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn region htmlH5 matchgroup=mkdHeading start="^\s*#####" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn region htmlH6 matchgroup=mkdHeading start="^\s*######" end="$" contains=mkdEscape,mkdLink,mkdInlineURL,@Spell
syn match htmlH1 /^.\+\n=\+$/ contains=mkdLink,mkdInlineURL,@Spell
syn match htmlH2 /^.\+\n-\+$/ contains=mkdLink,mkdInlineURL,@Spell

Expand All @@ -116,6 +116,9 @@ syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*\(\*\|\s\)*$/
syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-\(-\|\s\)*$/
syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_\(_\|\s\)*$/

syntax region mkdEscape matchgroup=mkdEscape start=/\\\ze[\\\x60*{}\[\]()#+\-,.!_>~|"$%&'\/:;<=?@^]/ end=/.\zs/ keepend contains=mkdEscapeCh contained oneline concealends
syntax match mkdEscapeCh /./ contained

" YAML frontmatter
if get(g:, 'vim_markdown_frontmatter', 0)
syn include @yamlTop syntax/yaml.vim
Expand Down Expand Up @@ -155,7 +158,7 @@ if get(g:, 'vim_markdown_strikethrough', 0)
HtmlHiLink mkdStrike htmlStrike
endif

syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath,mkdStrike
syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath,mkdStrike,mkdEscape

"highlighting for Markdown groups
HtmlHiLink mkdString String
Expand All @@ -177,6 +180,7 @@ HtmlHiLink mkdLinkDef mkdID
HtmlHiLink mkdLinkDefTarget mkdURL
HtmlHiLink mkdLinkTitle htmlString
HtmlHiLink mkdDelimiter Delimiter
HtmlHiLink mkdEscape Special

let b:current_syntax = "mkd"

Expand Down
7 changes: 7 additions & 0 deletions test/escapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Escapes:

text: \\ \` \* \{ \} \[ \] \( \) \# \+ \- \. \! \_ \< \> \~ \| \" \$ \% \& \' \/ \: \; \= \? \@ \^

## Header: \\ \` \* \{ \} \[ \] \( \) \# \+ \- \. \! \_ \< \> \~ \| \" \$ \% \& \' \/ \: \; \= \? \@ \^

Non Escapes: \a \b \c \f \n \r \t \v \x \o

0 comments on commit a635953

Please sign in to comment.