I would like to adapt this syntax file so that the formatting in VIM matches more closely what this online Markdown editor (GitLab-flavor) displays (the output on the right is relevant, this is how I want the text to look in VIM). In particular, I am looking at the detection of italics triggered by framing text with asterisks.
I made some progress by simplifying the start and end patterns and by adding "oneline". But actually I would like the region to extend beyond a single line to an entire paragraph. In other words, the region should include subsequent lines until an empty line is encountered. If I omit the "oneline" attribute, the region just goes on and does not stop on an empty line. How can I make this region include subsequent non-empty lines but stop at the first empty line (or, obviously, the end pattern, whatever comes first)?
Note that a piece of text that contains the start pattern, but no end pattern and that is terminated by an empty line should NOT be detected as a region. The empty line is not an alternative end, it should just be interpreted as "stop looking here for the end pattern".
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\*\S\@=" end="\S\@<=\*" keepend oneline contains=markdownLineStart' . s:concealends
Update 2023-09-05
Here is how the relevant section of my markdown.vim
file looks now. It does italics and bold in a style that corresponds more closely to the way Markdown is rendered on Github. I personally don't use markdownBoldItalic or markdownStrike, so I did not bother to change those.
let s:conceal = ''
let s:concealends = ''
if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1
let s:conceal = ' conceal'
let s:concealends = ' concealends'
endif
exe 'syn match markdownItalicDelimiterStart "\*\ze\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\*"' s:conceal
exe 'syn match markdownItalicDelimiterEnd "\(\*\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\)\@<=\*"' s:conceal
syn match markdownItalic "\*\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\*" contains=markdownItalicDelimiterStart,markdownItalicDelimiterEnd
exe 'syn match markdownItalicDelimiterStart "_\ze\S\(\([^\n]\|\n[^\n]\)\{-}\)\S_"' s:conceal
exe 'syn match markdownItalicDelimiterEnd "\(_\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\)\@<=_"' s:conceal
syn match markdownItalic "_\S\(\([^\n]\|\n[^\n]\)\{-}\)\S_" contains=markdownItalicDelimiterStart,markdownItalicDelimiterEnd
exe 'syn match markdownBoldDelimiterStart "\*\*\ze\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\*\*"' s:conceal
exe 'syn match markdownBoldDelimiterEnd "\(\*\*\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\)\@<=\*\*"' s:conceal
syn match markdownBold "\*\*\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\*\*" contains=markdownBoldDelimiterStart,markdownBoldDelimiterEnd
exe 'syn match markdownBoldDelimiterStart "__\ze\S\(\([^\n]\|\n[^\n]\)\{-}\)\S__"' s:conceal
exe 'syn match markdownBoldDelimiterEnd "\(__\S\(\([^\n]\|\n[^\n]\)\{-}\)\S\)\@<=__"' s:conceal
syn match markdownBold "__\S\(\([^\n]\|\n[^\n]\)\{-}\)\S__" contains=markdownBoldDelimiterStart,markdownBoldDelimiterEnd
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\*\*\*\S\@=" end="\S\@<=\*\*\*\|^$" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\w\@<!___\S\@=" end="\S\@<=___\w\@!\|^$" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
exe 'syn region markdownStrike matchgroup=markdownStrikeDelimiter start="\~\~\S\@=" end="\S\@<=\~\~\|^$" contains=markdownLineStart,@Spell' . s:concealends