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

Add syntax highlighting to some elements inside headings #641

Merged
merged 5 commits into from
Sep 20, 2023
Merged
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
17 changes: 9 additions & 8 deletions syntax/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ 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 match htmlH1 /^.\+\n=\+$/ contains=mkdLink,mkdInlineURL,@Spell
syn match htmlH2 /^.\+\n-\+$/ contains=mkdLink,mkdInlineURL,@Spell
syn region htmlH1 matchgroup=mkdHeading start="^\s*#" end="$" contains=@mkdHeadingContent,@Spell
syn region htmlH2 matchgroup=mkdHeading start="^\s*##" end="$" contains=@mkdHeadingContent,@Spell
syn region htmlH3 matchgroup=mkdHeading start="^\s*###" end="$" contains=@mkdHeadingContent,@Spell
syn region htmlH4 matchgroup=mkdHeading start="^\s*####" end="$" contains=@mkdHeadingContent,@Spell
syn region htmlH5 matchgroup=mkdHeading start="^\s*#####" end="$" contains=@mkdHeadingContent,@Spell
syn region htmlH6 matchgroup=mkdHeading start="^\s*######" end="$" contains=@mkdHeadingContent,@Spell
syn match htmlH1 /^.\+\n=\+$/ contains=@mkdHeadingContent,@Spell
syn match htmlH2 /^.\+\n-\+$/ contains=@mkdHeadingContent,@Spell

"define Markdown groups
syn match mkdLineBreak / \+$/
Expand Down Expand Up @@ -156,6 +156,7 @@ if get(g:, 'vim_markdown_strikethrough', 0)
HtmlHiLink mkdStrike htmlStrike
endif

syn cluster mkdHeadingContent contains=htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdLink,mkdInlineURL,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

"highlighting for Markdown groups
Expand Down
41 changes: 41 additions & 0 deletions test/strikethrough.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Before:
let g:vim_markdown_strikethrough = 1
syn off | syn on

After:
unlet! g:vim_markdown_strikethrough

Given markdown;
a ~~b~~ c

Execute (strikethrough):
AssertNotEqual SyntaxOf('a'), 'mkdStrike'
AssertEqual SyntaxOf('b'), 'mkdStrike'
AssertNotEqual SyntaxOf('c'), 'mkdStrike'

Given markdown;
# ~~h1~~
## ~~h2~~
### ~~h3~~
#### ~~h4~~
##### ~~h5~~
###### ~~h6~~

Execute (strikethrough in atx headings):
AssertEqual SyntaxOf('h1'), 'mkdStrike'
AssertEqual SyntaxOf('h2'), 'mkdStrike'
AssertEqual SyntaxOf('h3'), 'mkdStrike'
AssertEqual SyntaxOf('h4'), 'mkdStrike'
AssertEqual SyntaxOf('h5'), 'mkdStrike'
AssertEqual SyntaxOf('h6'), 'mkdStrike'

Given markdown;
~~h1~~
=

~~h2~~
-

Execute (strikethrough in setext headings):
AssertEqual SyntaxOf('h1'), 'mkdStrike'
AssertEqual SyntaxOf('h2'), 'mkdStrike'
224 changes: 224 additions & 0 deletions test/syntax.vader
Original file line number Diff line number Diff line change
Expand Up @@ -1302,3 +1302,227 @@ Execute (HTML tag in text):
AssertEqual SyntaxOf('span'), 'htmlTagName'
AssertEqual SyntaxOf('<span>'), 'htmlTag'
AssertEqual SyntaxOf('</span>'), 'htmlEndTag'

Given markdown;
# _h1_

## _h2_

### _h3_

#### _h4_

##### _h5_

###### _h6_

Execute (underscore italic text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlItalic'
AssertEqual SyntaxOf('h2'), 'htmlItalic'
AssertEqual SyntaxOf('h3'), 'htmlItalic'
AssertEqual SyntaxOf('h4'), 'htmlItalic'
AssertEqual SyntaxOf('h5'), 'htmlItalic'
AssertEqual SyntaxOf('h6'), 'htmlItalic'

Given markdown;
# *h1*

## *h2*

### *h3*

#### *h4*

##### *h5*

###### *h6*

Execute (asterisk italic text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlItalic'
AssertEqual SyntaxOf('h2'), 'htmlItalic'
AssertEqual SyntaxOf('h3'), 'htmlItalic'
AssertEqual SyntaxOf('h4'), 'htmlItalic'
AssertEqual SyntaxOf('h5'), 'htmlItalic'
AssertEqual SyntaxOf('h6'), 'htmlItalic'

Given markdown;
_h1_
=

_h2_
-

Execute (underscore italic text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlItalic'
AssertEqual SyntaxOf('h2'), 'htmlItalic'

Given markdown;
*h1*
=

*h2*
-

Execute (asterisk italic text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlItalic'
AssertEqual SyntaxOf('h2'), 'htmlItalic'

Given markdown;
# __h1__

## __h2__

### __h3__

#### __h4__

##### __h5__

###### __h6__

Execute (underscore bold text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlBold'
AssertEqual SyntaxOf('h2'), 'htmlBold'
AssertEqual SyntaxOf('h3'), 'htmlBold'
AssertEqual SyntaxOf('h4'), 'htmlBold'
AssertEqual SyntaxOf('h5'), 'htmlBold'
AssertEqual SyntaxOf('h6'), 'htmlBold'

Given markdown;
# **h1**

## **h2**

### **h3**

#### **h4**

##### **h5**

###### **h6**

Execute (asterisk bold text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlBold'
AssertEqual SyntaxOf('h2'), 'htmlBold'
AssertEqual SyntaxOf('h3'), 'htmlBold'
AssertEqual SyntaxOf('h4'), 'htmlBold'
AssertEqual SyntaxOf('h5'), 'htmlBold'
AssertEqual SyntaxOf('h6'), 'htmlBold'

Given markdown;
__h1__
=

__h2__
-

Execute (underscore bold text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlBold'
AssertEqual SyntaxOf('h2'), 'htmlBold'

Given markdown;
**h1**
=

**h2**
-

Execute (asterisk bold text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlBold'
AssertEqual SyntaxOf('h2'), 'htmlBold'

Given markdown;
# ___h1___

## ___h2___

### ___h3___

#### ___h4___

##### ___h5___

###### ___h6___

Execute (underscore bold italic text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h3'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h4'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h5'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h6'), 'htmlBoldItalic'

Given markdown;
# ***h1***

## ***h2***

### ***h3***

#### ***h4***

##### ***h5***

###### ***h6***

Execute (asterisk bold italic text in atx headings):
AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h3'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h4'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h5'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h6'), 'htmlBoldItalic'

Given markdown;
___h1___
=

___h2___
-

Execute (underscore bold italic text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'

Given markdown;
***h1***
=

***h2***
-

Execute (asterisk bold italic text in setext headings):
AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'

Given markdown;
# [^h1]

## [^h2]

### [^h3]

#### [^h4]

##### [^h5]

###### [^h6]

Execute (footnotes in atx headings):
AssertEqual SyntaxOf('h1'), 'mkdFootnotes'
AssertEqual SyntaxOf('h2'), 'mkdFootnotes'
AssertEqual SyntaxOf('h3'), 'mkdFootnotes'
AssertEqual SyntaxOf('h4'), 'mkdFootnotes'
AssertEqual SyntaxOf('h5'), 'mkdFootnotes'
AssertEqual SyntaxOf('h6'), 'mkdFootnotes'

Given markdown;
[^h1]
=

[^h2]
-

Execute (footnotes in setext headings):
AssertEqual SyntaxOf('h1'), 'mkdFootnotes'
AssertEqual SyntaxOf('h2'), 'mkdFootnotes'
Loading