Skip to content

Commit

Permalink
Highlight italics in headings
Browse files Browse the repository at this point in the history
  • Loading branch information
lggruspe authored and alerque committed Sep 20, 2023
1 parent cc82d88 commit 2b9e32e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
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,mkdLink,mkdInlineURL
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
64 changes: 64 additions & 0 deletions test/syntax.vader
Original file line number Diff line number Diff line change
Expand Up @@ -1302,3 +1302,67 @@ 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'

0 comments on commit 2b9e32e

Please sign in to comment.