vim-pandoc / vim-pandoc-syntax

pandoc markdown syntax, to be installed alongside vim-pandoc
MIT License
426 stars 61 forks source link

Subheader without a newline is not detected #391

Open fenuks opened 8 months ago

fenuks commented 8 months ago

Hello, for file

# Bug report
## Description

Description header is not detected.

# Workaround

## Description
Add an empty line before the header.

vim-pandoc-syntax conceals it to conceal.

This problem was introduced in https://github.com/vim-pandoc/vim-pandoc-syntax/commit/634d830b0f73fea73526d4ea294cb3f33a4e79ef. That change fixes incorrect detection of headers in the middle of paragraphs, but is a bit too strict.

fenuks commented 7 months ago

This patch seems to fix the issue without adverse effects:

diff --git i/syntax/pandoc.vim w/syntax/pandoc.vim
index 38df7f1..9cdd83f 100644
--- i/syntax/pandoc.vim
+++ w/syntax/pandoc.vim
@@ -400,7 +400,7 @@ call s:WithConceal('strikeout', 'syn match pandocStrikeoutMark /\~\~/ contained
 " }}}2

 " Headers: {{{2
-syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
+syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\|^#\{1,6}.*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
 syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@<!#\+\(\s*.*$\)\@=\)/ contained containedin=pandocAtxHeader
 call s:WithConceal('atx', 'syn match pandocAtxStart /#/ contained containedin=pandocAtxHeaderMark', 'conceal cchar='.s:cchars['atx'])
 syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape
heyrict commented 4 months ago

Here is a cleaner workaround before this patch can be merged to the upstream. Add these to vimrc:

augroup consecutive_heading
    au!
    au filetype pandoc syn clear pandocAtxHeader
    au filetype pandoc syn match pandocAtxHeader /\(\%^\|<.\+>.*\|^\s*\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
augroup END