Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: conceal backslash if it is a valid escape code leader #515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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