preservim / vim-markdown

Markdown Vim Mode
4.69k stars 524 forks source link

Line-headings fails for `code` beginning lines #635

Open KSR-Yasuda opened 1 year ago

KSR-Yasuda commented 1 year ago

Line-headings (==== or ---- line following heading text) does not work for the lines that begin with `code`.

hogefuga (OK)
====

hogefuga (OK)
----

`hoge` fuga (NG)
====

`hoge` fuga (NG)
----

markdown

lggruspe commented 1 year ago

This is also the case with strikethrough text.

Stuff like :Toc and :HeaderDecrease work just fine, but the syntax highlighting is broken.

alerque commented 1 year ago

@lggruspe Curious why you didn't include code markup in #641 ... is there an issue with ATX vs. SetExt headers here or some other holdup? Would extending the list of contains fix this?

lggruspe commented 1 year ago

There's an issue with code span highlighting. The syntax file currently only looks for closing delimiters with 3+ backticks at the start of a line, so code spans like the following don't get closed.

# ```code```

This paragraph gets highlighted as code.
KSR-Yasuda commented 10 months ago

Perhaps just moving htmlH[12] rules for "Line following heading case\n====" after mkdCode rule works fine as "# preceding heading case"?

--- a/syntax/markdown.vim
+++ b/syntax/markdown.vim
@@ -85,16 +85,6 @@ syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+     end=+"+  contained
 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=@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    /  \+$/
 syn region mkdBlockquote   start=/^\s*>/                   end=/$/ contains=mkdLink,mkdInlineURL,mkdLineBreak,@Spell
@@ -117,6 +107,16 @@ 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\)*$/

+"HTML headings
+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
+
 " YAML frontmatter
 if get(g:, 'vim_markdown_frontmatter', 0)
   syn include @yamlTop syntax/yaml.vim