blob: 7928cc665ddb38a20ea4a48bf6876b15adad0046 [file] [log] [blame]
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +02001scriptencoding utf-8
2"
3" Language: Pandoc (superset of Markdown)
4" Maintainer: Felipe Morales <hel.sheep@gmail.com>
5" Maintainer: Caleb Maclennan <caleb@alerque.com>
6" Upstream: https://github.com/vim-pandoc/vim-pandoc-syntax
7"
8" Contributor: David Sanson <dsanson@gmail.com>
9" Jorge Israel Peña <jorge.israel.p@gmail.com>
10" Original Author: Jeremy Schultz <taozhyn@gmail.com>
11" Version: 5.0
12" Last Change: 2024 Apr 08
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17" Configuration: {{{1
18"
19" use conceal? {{{2
20if !exists('g:pandoc#syntax#conceal#use')
21 let g:pandoc#syntax#conceal#use = 1
22endif
23"}}}2
24
25" what groups not to use conceal in. works as a blacklist {{{2
26if !exists('g:pandoc#syntax#conceal#blacklist')
27 let g:pandoc#syntax#conceal#blacklist = []
28endif
29" }}}2
30
31" cchars used in conceal rules {{{2
32" utf-8 defaults (preferred)
33if &encoding ==# 'utf-8'
34 let s:cchars = {
35 \'newline': '↵',
36 \'image': '▨',
37 \'super': 'ⁿ',
38 \'sub': 'ₙ',
39 \'strike': 'x̶',
40 \'atx': '§',
41 \'codelang': 'λ',
42 \'codeend': '—',
43 \'abbrev': '→',
44 \'footnote': '†',
45 \'definition': ' ',
46 \'li': '•',
47 \'html_c_s': '‹',
48 \'html_c_e': '›',
49 \'quote_s': '“',
50 \'quote_e': '”'}
51else
52 " ascii defaults
53 let s:cchars = {
54 \'newline': ' ',
55 \'image': 'i',
56 \'super': '^',
57 \'sub': '_',
58 \'strike': '~',
59 \'atx': '#',
60 \'codelang': 'l',
61 \'codeend': '-',
62 \'abbrev': 'a',
63 \'footnote': 'f',
64 \'definition': ' ',
65 \'li': '*',
66 \'html_c_s': '+',
67 \'html_c_e': '+'}
68endif
69" }}}2
70
71" if the user has a dictionary with replacements for the default cchars, use those {{{2
72if exists('g:pandoc#syntax#conceal#cchar_overrides')
73 let s:cchars = extend(s:cchars, g:pandoc#syntax#conceal#cchar_overrides)
74endif
75" }}}2
76
77"should the urls in links be concealed? {{{2
78if !exists('g:pandoc#syntax#conceal#urls')
79 let g:pandoc#syntax#conceal#urls = 0
80endif
81" should backslashes in escapes be concealed? {{{2
82if !exists('g:pandoc#syntax#conceal#backslash')
83 let g:pandoc#syntax#conceal#backslash = 0
84endif
85" }}}2
86
87" leave specified codeblocks as Normal (i.e. 'unhighlighted') {{{2
88if !exists('g:pandoc#syntax#codeblocks#ignore')
89 let g:pandoc#syntax#codeblocks#ignore = []
90endif
91" }}}2
92
93" use embedded highlighting for delimited codeblocks where a language is specifed. {{{2
94if !exists('g:pandoc#syntax#codeblocks#embeds#use')
95 let g:pandoc#syntax#codeblocks#embeds#use = 1
96endif
97" }}}2
98
99" for what languages and using what vim syntax files highlight those embeds. {{{2
100" defaults to None.
101if !exists('g:pandoc#syntax#codeblocks#embeds#langs')
102 let g:pandoc#syntax#codeblocks#embeds#langs = []
103endif
104" }}}2
105
106" use italics ? {{{2
107if !exists('g:pandoc#syntax#style#emphases')
108 let g:pandoc#syntax#style#emphases = 1
109endif
110" if 0, we don't conceal the emphasis marks, otherwise there wouldn't be a way
111" to tell where the styles apply.
112if g:pandoc#syntax#style#emphases == 0
113 call add(g:pandoc#syntax#conceal#blacklist, 'block')
114endif
115" }}}2
116
117" underline subscript, superscript and strikeout? {{{2
118if !exists('g:pandoc#syntax#style#underline_special')
119 let g:pandoc#syntax#style#underline_special = 1
120endif
121" }}}2
122
123" protect code blocks? {{{2
124if !exists('g:pandoc#syntax#protect#codeblocks')
125 let g:pandoc#syntax#protect#codeblocks = 1
126endif
127" }}}2
128
129" use color column? {{{2
130if !exists('g:pandoc#syntax#colorcolumn')
131 let g:pandoc#syntax#colorcolumn = 0
132endif
133" }}}2
134
135" highlight new lines? {{{2
136if !exists('g:pandoc#syntax#newlines')
137 let g:pandoc#syntax#newlines = 1
138endif
139" }}}
140
141" detect roman-numeral list items? {{{2
142if !exists('g:pandoc#syntax#roman_lists')
143 let g:pandoc#syntax#roman_lists = 0
144endif
145" }}}2
146
147" disable syntax highlighting for definition lists? (better performances) {{{2
148if !exists('g:pandoc#syntax#use_definition_lists')
149 let g:pandoc#syntax#use_definition_lists = 1
150endif
151" }}}2
152
153" }}}1
154
155" Functions: {{{1
156" EnableEmbedsforCodeblocksWithLang {{{2
157function! EnableEmbedsforCodeblocksWithLang(entry)
158 " prevent embedded language syntaxes from changing 'foldmethod'
159 if has('folding')
160 let s:foldmethod = &l:foldmethod
161 let s:foldtext = &l:foldtext
162 endif
163
164 try
165 let s:langname = matchstr(a:entry, '^[^=]*')
166 let s:langsyntaxfile = matchstr(a:entry, '[^=]*$')
167 unlet! b:current_syntax
168 exe 'syn include @'.toupper(s:langname).' syntax/'.s:langsyntaxfile.'.vim'
169 " We might have just turned off spellchecking by including the file,
170 " so we turn it back on here.
171 exe 'syntax spell toplevel'
172 exe 'syn region pandocDelimitedCodeBlock_' . s:langname . ' start=/\(\_^\( \+\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>.*\n\)\@<=\_^/' .
173 \' end=/\_$\n\(\( \+\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\_$\n\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock' .
174 \' contains=@' . toupper(s:langname)
175 exe 'syn region pandocDelimitedCodeBlockinBlockQuote_' . s:langname . ' start=/>\s\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>/' .
176 \ ' end=/\(`\{3,}`*\|\~\{3,}\~*\)/ contained containedin=pandocDelimitedCodeBlock' .
177 \' contains=@' . toupper(s:langname) .
178 \',pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd,pandodDelimitedCodeblockLang,pandocBlockQuoteinDelimitedCodeBlock'
179 catch /E484/
180 echo "No syntax file found for '" . s:langsyntaxfile . "'"
181 endtry
182
183 if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod
184 let &l:foldmethod = s:foldmethod
185 endif
186 if exists('s:foldtext') && s:foldtext !=# &l:foldtext
187 let &l:foldtext = s:foldtext
188 endif
189endfunction
190" }}}2
191
192" DisableEmbedsforCodeblocksWithLang {{{2
193function! DisableEmbedsforCodeblocksWithLang(langname)
194 try
195 exe 'syn clear pandocDelimitedCodeBlock_'.a:langname
196 exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.a:langname
197 catch /E28/
198 echo "No existing highlight definitions found for '" . a:langname . "'"
199 endtry
200endfunction
201" }}}2
202
203" WithConceal {{{2
204function! s:WithConceal(rule_group, rule, conceal_rule)
205 let l:rule_tail = ''
206 if g:pandoc#syntax#conceal#use != 0
207 if index(g:pandoc#syntax#conceal#blacklist, a:rule_group) == -1
208 let l:rule_tail = ' ' . a:conceal_rule
209 endif
210 endif
211 execute a:rule . l:rule_tail
212endfunction
213" }}}2
214
215" }}}1
216
217" Commands: {{{1
218command! -buffer -nargs=1 -complete=syntax PandocHighlight call EnableEmbedsforCodeblocksWithLang(<f-args>)
219command! -buffer -nargs=1 -complete=syntax PandocUnhighlight call DisableEmbedsforCodeblocksWithLang(<f-args>)
220" }}}1
221
222" BASE:
223syntax clear
224syntax spell toplevel
225" }}}1
226
227" Syntax Rules: {{{1
228
229" Embeds: {{{2
230
231" prevent embedded language syntaxes from changing 'foldmethod'
232if has('folding')
233 let s:foldmethod = &l:foldmethod
234endif
235
236" HTML: {{{3
237" Set embedded HTML highlighting
238syn include @HTML syntax/html.vim
239syn match pandocHTML /<\/\?\a\_.\{-}>/ contains=@HTML
240" Support HTML multi line comments
241syn region pandocHTMLComment start=/<!--\s\=/ end=/\s\=-->/ keepend contains=pandocHTMLCommentStart,pandocHTMLCommentEnd
242call s:WithConceal('html_c_s', 'syn match pandocHTMLCommentStart /<!--/ contained', 'conceal cchar='.s:cchars['html_c_s'])
243call s:WithConceal('html_c_e', 'syn match pandocHTMLCommentEnd /-->/ contained', 'conceal cchar='.s:cchars['html_c_e'])
244" }}}3
245
246" LaTeX: {{{3
247" Set embedded LaTex (pandoc extension) highlighting
248" Unset current_syntax so the 2nd include will work
249unlet b:current_syntax
250syn include @LATEX syntax/tex.vim
251if index(g:pandoc#syntax#conceal#blacklist, 'inlinemath') == -1
252 " Can't use WithConceal here because it will mess up all other conceals
253 " when dollar signs are used normally. It must be skipped entirely if
254 " inlinemath is blacklisted
255 syn region pandocLaTeXInlineMath start=/\v\\@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@LATEX
256 syn region pandocLaTeXInlineMath start=/\\\@<!\\(/ end=/\\\@<!\\)/ keepend contains=@LATEX
257endif
258syn match pandocEscapedDollar /\\\$/ conceal cchar=$
259syn match pandocProtectedFromInlineLaTeX /\\\@<!\${.*}\(\(\s\|[[:punct:]]\)\([^$]*\|.*\(\\\$.*\)\{2}\)\n\n\|$\)\@=/ display
260" contains=@LATEX
261syn region pandocLaTeXMathBlock start=/\$\$/ end=/\$\$/ keepend contains=@LATEX
262syn region pandocLaTeXMathBlock start=/\\\@<!\\\[/ end=/\\\@<!\\\]/ keepend contains=@LATEX
263syn match pandocLaTeXCommand /\\[[:alpha:]]\+\(\({.\{-}}\)\=\(\[.\{-}\]\)\=\)*/ contains=@LATEX
264syn region pandocLaTeXRegion start=/\\begin{\z(.\{-}\)}/ end=/\\end{\z1}/ keepend contains=@LATEX
265" we rehighlight sectioning commands, because otherwise tex.vim captures all text until EOF or a new sectioning command
266syn region pandocLaTexSection start=/\\\(part\|chapter\|\(sub\)\{,2}section\|\(sub\)\=paragraph\)\*\=\(\[.*\]\)\={/ end=/\}/ keepend
267syn match pandocLaTexSectionCmd /\\\(part\|chapter\|\(sub\)\{,2}section\|\(sub\)\=paragraph\)/ contained containedin=pandocLaTexSection
268syn match pandocLaTeXDelimiter /[[\]{}]/ contained containedin=pandocLaTexSection
269" }}}3
270
271if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod
272 let &l:foldmethod = s:foldmethod
273endif
274
275" }}}2
276
277" Titleblock: {{{2
278syn region pandocTitleBlock start=/\%^%/ end=/\n\n/ contains=pandocReferenceLabel,pandocReferenceURL,pandocNewLine
279call s:WithConceal('titleblock', 'syn match pandocTitleBlockMark /%\ / contained containedin=pandocTitleBlock,pandocTitleBlockTitle', 'conceal')
280syn match pandocTitleBlockTitle /\%^%.*\n/ contained containedin=pandocTitleBlock
281" }}}2
282
283" Blockquotes: {{{2
284syn match pandocBlockQuote /^\s\{,3}>.*\n\(.*\n\@1<!\n\)*/ contains=@Spell,pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted,pandocAmpersandEscape,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion skipnl
285syn match pandocBlockQuoteMark /\_^\s\{,3}>/ contained containedin=pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted
286" }}}2
287
288" Code Blocks: {{{2
289if g:pandoc#syntax#protect#codeblocks == 1
290 syn match pandocCodeblock /\([ ]\{4}\|\t\).*$/
291endif
292syn region pandocCodeBlockInsideIndent start=/\(\(\d\|\a\|*\).*\n\)\@<!\(^\(\s\{8,}\|\t\+\)\).*\n/ end=/.\(\n^\s*\n\)\@=/ contained
293" }}}2
294
295" Links: {{{2
296
297" Base: {{{3
298syn region pandocReferenceLabel matchgroup=pandocOperator start=/!\{,1}\\\@<!\^\@<!\[/ skip=/\(\\\@<!\]\]\@=\|`.*\\\@<!].*`\)/ end=/\\\@<!\]/ keepend display
299if g:pandoc#syntax#conceal#urls == 1
300 syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend conceal
301else
302 syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend
303endif
304" let's not consider "a [label] a" as a label, remove formatting - Note: breaks implicit links
305syn match pandocNoLabel /\]\@1<!\(\s\{,3}\|^\)\[[^\[\]]\{-}\]\(\s\+\|$\)[\[(]\@!/ contains=pandocPCite
306syn match pandocLinkTip /\s*".\{-}"/ contained containedin=pandocReferenceURL contains=@Spell,pandocAmpersandEscape display
307call s:WithConceal('image', 'syn match pandocImageIcon /!\[\@=/ display', 'conceal cchar='. s:cchars['image'])
308" }}}3
309
310" Definitions: {{{3
311syn region pandocReferenceDefinition start=/\[.\{-}\]:/ end=/\(\n\s*".*"$\|$\)/ keepend
312syn match pandocReferenceDefinitionLabel /\[\zs.\{-}\ze\]:/ contained containedin=pandocReferenceDefinition display
313syn match pandocReferenceDefinitionAddress /:\s*\zs.*/ contained containedin=pandocReferenceDefinition
314syn match pandocReferenceDefinitionTip /\s*".\{-}"/ contained containedin=pandocReferenceDefinition,pandocReferenceDefinitionAddress contains=@Spell,pandocAmpersandEscape
315" }}}3
316
317" Automatic_links: {{{3
318syn match pandocAutomaticLink /<\(https\{0,1}.\{-}\|[A-Za-z0-9!#$%&'*+\-/=?^_`{|}~.]\{-}@[A-Za-z0-9\-]\{-}\.\w\{-}\)>/ contains=NONE
319" }}}3
320
321" }}}2
322
323" Citations: {{{2
324" parenthetical citations
325syn match pandocPCite "\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*.\{-}\]" contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display
326" in-text citations with location
327syn match pandocICite "@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\s\[.\{-1,}\]" contains=pandocCiteKey,@Spell display
328" cite keys
329syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display
330syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display
331syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite
332" }}}2
333
334" Text Styles: {{{2
335
336" Emphasis: {{{3
337call s:WithConceal('block', 'syn region pandocEmphasis matchgroup=pandocOperator start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=\*\S\@=/ skip=/\(\*\*\|__\)/ end=/\*\([[:punct:]]\|\s\|\_$\)\@=/ contains=@Spell,pandocNoFormattedInEmphasis,pandocLatexInlineMath,pandocAmpersandEscape', 'concealends')
338call s:WithConceal('block', 'syn region pandocEmphasis matchgroup=pandocOperator start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=_\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@1<=_\([[:punct:]]\|\s\|\_$\)\@=/ contains=@Spell,pandocNoFormattedInEmphasis,pandocLatexInlineMath,pandocAmpersandEscape', 'concealends')
339" }}}3
340
341" Strong: {{{3
342call s:WithConceal('block', 'syn region pandocStrong matchgroup=pandocOperator start=/\(\\\@<!\*\)\{2}/ end=/\(\\\@<!\*\)\{2}/ contains=@Spell,pandocNoFormattedInStrong,pandocLatexInlineMath,pandocAmpersandEscape', 'concealends')
343call s:WithConceal('block', 'syn region pandocStrong matchgroup=pandocOperator start=/__/ end=/__/ contains=@Spell,pandocNoFormattedInStrong,pandocLatexInlineMath,pandocAmpersandEscape', 'concealends')
344" }}}3
345
346" Strong Emphasis: {{{3
347call s:WithConceal('block', 'syn region pandocStrongEmphasis matchgroup=pandocOperator start=/\*\{3}\(\S[^*]*\(\*\S\|\n[^*]*\*\S\)\)\@=/ end=/\S\@<=\*\{3}/ contains=@Spell,pandocAmpersandEscape', 'concealends')
348call s:WithConceal('block', 'syn region pandocStrongEmphasis matchgroup=pandocOperator start=/\(___\)\S\@=/ end=/\S\@<=___/ contains=@Spell,pandocAmpersandEscape', 'concealends')
349" }}}3
350
351" Mixed: {{{3
352call s:WithConceal('block', 'syn region pandocStrongInEmphasis matchgroup=pandocOperator start=/\*\*/ end=/\*\*/ contained containedin=pandocEmphasis contains=@Spell,pandocAmpersandEscape', 'concealends')
353call s:WithConceal('block', 'syn region pandocStrongInEmphasis matchgroup=pandocOperator start=/__/ end=/__/ contained containedin=pandocEmphasis contains=@Spell,pandocAmpersandEscape', 'concealends')
354call s:WithConceal('block', 'syn region pandocEmphasisInStrong matchgroup=pandocOperator start=/\\\@1<!\(\_^\|\s\|[[:punct:]]\)\@<=\*\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@<=\*\([[:punct:]]\|\s\|\_$\)\@=/ contained containedin=pandocStrong contains=@Spell,pandocAmpersandEscape', 'concealends')
355call s:WithConceal('block', 'syn region pandocEmphasisInStrong matchgroup=pandocOperator start=/\\\@<!\(\_^\|\s\|[[:punct:]]\)\@<=_\S\@=/ skip=/\(\*\*\|__\)/ end=/\S\@<=_\([[:punct:]]\|\s\|\_$\)\@=/ contained containedin=pandocStrong contains=@Spell,pandocAmpersandEscape', 'concealends')
356" }}}3
357
358" Inline Code: {{{3
359" Using single back ticks
360call s:WithConceal('inlinecode', 'syn region pandocNoFormatted matchgroup=pandocOperator start=/\\\@<!`/ end=/\\\@<!`/ nextgroup=pandocNoFormattedAttrs', 'concealends')
361call s:WithConceal('inlinecode', 'syn region pandocNoFormattedInEmphasis matchgroup=pandocOperator start=/\\\@<!`/ end=/\\\@<!`/ nextgroup=pandocNoFormattedAttrs contained', 'concealends')
362call s:WithConceal('inlinecode', 'syn region pandocNoFormattedInStrong matchgroup=pandocOperator start=/\\\@<!`/ end=/\\\@<!`/ nextgroup=pandocNoFormattedAttrs contained', 'concealends')
363" Using double back ticks
364call s:WithConceal('inlinecode', 'syn region pandocNoFormatted matchgroup=pandocOperator start=/\\\@<!``/ end=/\\\@<!``/ nextgroup=pandocNoFormattedAttrs', 'concealends')
365call s:WithConceal('inlinecode', 'syn region pandocNoFormattedInEmphasis matchgroup=pandocOperator start=/\\\@<!``/ end=/\\\@<!``/ nextgroup=pandocNoFormattedAttrs contained', 'concealends')
366call s:WithConceal('inlinecode', 'syn region pandocNoFormattedInStrong matchgroup=pandocOperator start=/\\\@<!``/ end=/\\\@<!``/ nextgroup=pandocNoFormattedAttrs contained', 'concealends')
367syn match pandocNoFormattedAttrs /{.\{-}}/ contained
368" }}}3
369
370" Subscripts: {{{3
371syn region pandocSubscript start=/\~\(\([[:graph:]]\(\\ \)\=\)\{-}\~\)\@=/ end=/\~/ keepend
372call s:WithConceal('subscript', 'syn match pandocSubscriptMark /\~/ contained containedin=pandocSubscript', 'conceal cchar='.s:cchars['sub'])
373" }}}3
374
375" Superscript: {{{3
376syn region pandocSuperscript start=/\^\(\([[:graph:]]\(\\ \)\=\)\{-}\^\)\@=/ skip=/\\ / end=/\^/ keepend
377call s:WithConceal('superscript', 'syn match pandocSuperscriptMark /\^/ contained containedin=pandocSuperscript', 'conceal cchar='.s:cchars['super'])
378" }}}3
379
380" Strikeout: {{{3
381syn region pandocStrikeout start=/\~\~/ end=/\~\~/ contains=@Spell,pandocAmpersandEscape keepend
382call s:WithConceal('strikeout', 'syn match pandocStrikeoutMark /\~\~/ contained containedin=pandocStrikeout', 'conceal cchar='.s:cchars['strike'])
383" }}}3
384
385" }}}2
386
387" Headers: {{{2
388syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
389syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@<!#\+\(\s*.*$\)\@=\)/ contained containedin=pandocAtxHeader
390call s:WithConceal('atx', 'syn match pandocAtxStart /#/ contained containedin=pandocAtxHeaderMark', 'conceal cchar='.s:cchars['atx'])
391syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape
392syn match pandocSetexHeader /^.\+\n[-]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape
393syn match pandocHeaderAttr /{.*}/ contained containedin=pandocAtxHeader,pandocSetexHeader
394syn match pandocHeaderID /#[-_:.[:lower:][:upper:]]*/ contained containedin=pandocHeaderAttr
395" }}}2
396
397" Line Blocks: {{{2
398syn region pandocLineBlock start=/^|/ end=/\(^|\(.*\n|\@!\)\@=.*\)\@<=\n/ transparent
399syn match pandocLineBlockDelimiter /^|/ contained containedin=pandocLineBlock
400" }}}2
401
402" Tables: {{{2
403
404" Simple: {{{3
405syn region pandocSimpleTable start=/\%#=2\(^.*[[:graph:]].*\n\)\@<!\(^.*[[:graph:]].*\n\)\(-\{2,}\s*\)\+\n\n\@!/ end=/\n\n/ containedin=ALLBUT,pandocDelimitedCodeBlock,pandocDelimitedCodeBlockStart,pandocYAMLHeader keepend
406syn match pandocSimpleTableDelims /\-/ contained containedin=pandocSimpleTable
407syn match pandocSimpleTableHeader /\%#=2\(^.*[[:graph:]].*\n\)\@<!\(^.*[[:graph:]].*\n\)/ contained containedin=pandocSimpleTable
408
409syn region pandocTable start=/\%#=2^\(-\{2,}\s*\)\+\n\n\@!/ end=/\%#=2^\(-\{2,}\s*\)\+\n\n/ containedin=ALLBUT,pandocDelimitedCodeBlock,pandocYAMLHeader keepend
410syn match pandocTableDelims /\-/ contained containedin=pandocTable
411syn region pandocTableMultilineHeader start=/\%#=2\(^-\{2,}\n\)\@<=./ end=/\%#=2\n-\@=/ contained containedin=pandocTable
412" }}}3
413
414" Grid: {{{3
415syn region pandocGridTable start=/\%#=2\n\@1<=+-/ end=/+\n\n/ containedin=ALLBUT,pandocDelimitedCodeBlock,pandocYAMLHeader keepend
416syn match pandocGridTableDelims /[\|=]/ contained containedin=pandocGridTable
417syn match pandocGridTableDelims /\%#=2\([\-+][\-+=]\@=\|[\-+=]\@1<=[\-+]\)/ contained containedin=pandocGridTable
418syn match pandocGridTableHeader /\%#=2\(^.*\n\)\(+=.*\)\@=/ contained containedin=pandocGridTable
419" }}}3
420
421" Pipe: {{{3
422" with beginning and end pipes
423syn region pandocPipeTable start=/\%#=2\([+|]\n\)\@<!\n\@1<=|\(.*|\)\@=/ end=/|.*\n\(\n\|{\)/ containedin=ALLBUT,pandocDelimitedCodeBlock,pandocYAMLHeader keepend
424" without beginning and end pipes
425syn region pandocPipeTable start=/\%#=2^.*\n-.\{-}|/ end=/|.*\n\n/ keepend
426syn match pandocPipeTableDelims /[\|\-:+]/ contained containedin=pandocPipeTable
427syn match pandocPipeTableHeader /\(^.*\n\)\(|-\)\@=/ contained containedin=pandocPipeTable
428syn match pandocPipeTableHeader /\(^.*\n\)\(-\)\@=/ contained containedin=pandocPipeTable
429" }}}3
430
431syn match pandocTableHeaderWord /\<.\{-}\>/ contained containedin=pandocGridTableHeader,pandocPipeTableHeader contains=@Spell
432" }}}2
433
434" Delimited Code Blocks: {{{2
435" this is here because we can override strikeouts and subscripts
436syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
437syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
438call s:WithConceal('codeblock_start', 'syn match pandocDelimitedCodeBlockStart /\(\(\_^\n\_^\|\%^\)\(>\s\)\?\( \+\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=pandocDelimitedCodeBlock nextgroup=pandocDelimitedCodeBlockLanguage', 'conceal cchar='.s:cchars['codelang'])
439syn match pandocDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained
440call s:WithConceal('codeblock_delim', 'syn match pandocDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock', 'conceal cchar='.s:cchars['codeend'])
441syn match pandocBlockQuoteinDelimitedCodeBlock '^>' contained containedin=pandocDelimitedCodeBlock
442syn match pandocCodePre /<pre>.\{-}<\/pre>/ skipnl
443syn match pandocCodePre /<code>.\{-}<\/code>/ skipnl
444
445" enable highlighting for embedded region in codeblocks if there exists a
446" g:pandoc#syntax#codeblocks#embeds#langs *list*.
447"
448" entries in this list are the language code interpreted by pandoc,
449" if this differs from the name of the vim syntax file, append =vimname
450" e.g. let g:pandoc#syntax#codeblocks#embeds#langs = ["haskell", "literatehaskell=lhaskell"]
451"
452if g:pandoc#syntax#codeblocks#embeds#use != 0
453 for l in g:pandoc#syntax#codeblocks#embeds#langs
454 call EnableEmbedsforCodeblocksWithLang(l)
455 endfor
456endif
457" }}}2
458
459" Abbreviations: {{{2
460syn region pandocAbbreviationDefinition start=/^\*\[.\{-}\]:\s*/ end='$' contains=pandocNoFormatted,@Spell,pandocAmpersandEscape
461call s:WithConceal('abbrev', 'syn match pandocAbbreviationSeparator /:/ contained containedin=pandocAbbreviationDefinition', 'conceal cchar='.s:cchars['abbrev'])
462syn match pandocAbbreviation /\*\[.\{-}\]/ contained containedin=pandocAbbreviationDefinition
463call s:WithConceal('abbrev', 'syn match pandocAbbreviationHead /\*\[/ contained containedin=pandocAbbreviation', 'conceal')
464call s:WithConceal('abbrev', 'syn match pandocAbbreviationTail /\]/ contained containedin=pandocAbbreviation', 'conceal')
465" }}}2
466
467" Footnotes: {{{2
468" we put these here not to interfere with superscripts.
469syn match pandocFootnoteID /\[\^[^\]]\+\]/ nextgroup=pandocFootnoteDef
470
471" Inline footnotes
472syn region pandocFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocStrongEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocEllipses,pandocBeginQuote,pandocEndQuote,@Spell,pandocAmpersandEscape skipnl keepend
473call s:WithConceal('footnote', 'syn match pandocFootnoteDefHead /\^\[/ contained containedin=pandocFootnoteDef', 'conceal cchar='.s:cchars['footnote'])
474call s:WithConceal('footnote', 'syn match pandocFootnoteDefTail /\]/ contained containedin=pandocFootnoteDef', 'conceal')
475
476" regular footnotes
477syn region pandocFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocNewLine,pandocStrongEmphasis,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocAmpersandEscape,@Spell skipnl
478syn match pandocFootnoteBlockSeparator /:/ contained containedin=pandocFootnoteBlock
479syn match pandocFootnoteID /\[\^.\{-}\]/ contained containedin=pandocFootnoteBlock
480call s:WithConceal('footnote', 'syn match pandocFootnoteIDHead /\[\^/ contained containedin=pandocFootnoteID', 'conceal cchar='.s:cchars['footnote'])
481call s:WithConceal('footnote', 'syn match pandocFootnoteIDTail /\]/ contained containedin=pandocFootnoteID', 'conceal')
482" }}}2
483
484" List Items: {{{2
485" Unordered lists
486syn match pandocUListItem /^>\=\s*[*+-]\s\+-\@!.*$/ nextgroup=pandocUListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocReferenceURL,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
487call s:WithConceal('list', 'syn match pandocUListItemBullet /^>\=\s*\zs[*+-]/ contained containedin=pandocUListItem', 'conceal cchar='.s:cchars['li'])
488
489" Ordered lists
490syn match pandocListItem /^\s*(\?\(\d\+\|\l\|\#\|@\)[.)].*$/ nextgroup=pandocListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
491
492" support for roman numerals up to 'c'
493if g:pandoc#syntax#roman_lists != 0
494 syn match pandocListItem /^\s*(\?x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}[.)].*$/ nextgroup=pandocListItem,pandocMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation,pandocAutomaticLink skipempty display
495endif
496syn match pandocListItemBullet /^(\?.\{-}[.)]/ contained containedin=pandocListItem
497syn match pandocListItemBulletId /\(\d\+\|\l\|\#\|@.\{-}\|x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}\)/ contained containedin=pandocListItemBullet
498
499syn match pandocListItemContinuation /^\s\+\([-+*]\s\+\|(\?.\+[).]\)\@<!\([[:upper:][:lower:]_"[]\|\*\S\)\@=.*$/ nextgroup=pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation,pandocListItem contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocReferenceURL,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape contained skipempty display
500" }}}2
501
502" Definitions: {{{2
503if g:pandoc#syntax#use_definition_lists == 1
504 syn region pandocDefinitionBlock start=/^\%(\_^\s*\([`~]\)\1\{2,}\)\@!.*\n\(^\s*\n\)\=\s\{0,2}\([:~]\)\(\3\{2,}\3*\)\@!/ skip=/\n\n\zs\s/ end=/\n\n/ contains=pandocDefinitionBlockMark,pandocDefinitionBlockTerm,pandocCodeBlockInsideIndent,pandocEmphasis,pandocStrong,pandocStrongEmphasis,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocFootnoteID,pandocReferenceURL,pandocReferenceLabel,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocAutomaticLink,pandocEmDash,pandocEnDash,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID
505 syn match pandocDefinitionBlockTerm /^.*\n\(^\s*\n\)\=\(\s*[:~]\)\@=/ contained contains=pandocNoFormatted,pandocEmphasis,pandocStrong,pandocLaTeXInlineMath,pandocEscapedDollar,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID nextgroup=pandocDefinitionBlockMark
506 call s:WithConceal('definition', 'syn match pandocDefinitionBlockMark /^\s*[:~]/ contained', 'conceal cchar='.s:cchars['definition'])
507endif
508" }}}2
509
510" Special: {{{2
511
512" New_lines: {{{3
513if g:pandoc#syntax#newlines == 1
514 call s:WithConceal('newline', 'syn match pandocNewLine /\%(\%(\S\)\@<= \{2,}\|\\\)$/ display containedin=pandocEmphasis,pandocStrong,pandocStrongEmphasis,pandocStrongInEmphasis,pandocEmphasisInStrong', 'conceal cchar='.s:cchars['newline'])
515endif
516" }}}3
517
518" Emdashes: {{{3
519if &encoding ==# 'utf-8'
520 call s:WithConceal('emdashes', 'syn match pandocEllipses /\([^-]\)\@<=---\([^-]\)\@=/ display', 'conceal cchar=—')
521endif
522" }}}3
523
524" Endashes: {{{3
525if &encoding ==# 'utf-8'
526 call s:WithConceal('endashes', 'syn match pandocEllipses /\([^-]\)\@<=--\([^-]\)\@=/ display', 'conceal cchar=–')
527endif
528" }}}3
529
530" Ellipses: {{{3
531if &encoding ==# 'utf-8'
532 call s:WithConceal('ellipses', 'syn match pandocEllipses /\.\.\./ display', 'conceal cchar=…')
533endif
534" }}}3
535
536" Quotes: {{{3
537if &encoding ==# 'utf-8'
538 call s:WithConceal('quotes', 'syn match pandocBeginQuote /"\</ containedin=pandocEmphasis,pandocStrong,pandocListItem,pandocListItemContinuation,pandocUListItem display', 'conceal cchar='.s:cchars['quote_s'])
539 call s:WithConceal('quotes', 'syn match pandocEndQuote /\(\>[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar='.s:cchars['quote_e'])
540endif
541" }}}3
542
543" Hrule: {{{3
544syn match pandocHRule /^\s*\([*\-_]\)\s*\%(\1\s*\)\{2,}$/ display
545" }}}3
546
547" Backslashes: {{{3
548if g:pandoc#syntax#conceal#backslash == 1
549 syn match pandocBackslash /\v\\@<!\\((re)?newcommand)@!/ containedin=ALLBUT,pandocCodeblock,pandocCodeBlockInsideIndent,pandocNoFormatted,pandocNoFormattedInEmphasis,pandocNoFormattedInStrong,pandocDelimitedCodeBlock,pandocLineBlock,pandocYAMLHeader conceal
550endif
551" }}}3
552
553" &-escaped Special Characters: {{{3
554syn match pandocAmpersandEscape /\v\&(#\d+|#x\x+|[[:alnum:]]+)\;/ contains=NoSpell
555" }}}3
556
557" YAML: {{{2
558try
559 unlet! b:current_syntax
560 syn include @YAML syntax/yaml.vim
561catch /E484/
562endtry
563syn region pandocYAMLHeader start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=@YAML containedin=TOP
564" }}}2
565
566" }}}1
567
568" Styling: {{{1
569function! s:SetupPandocHighlights()
570
571 hi def link pandocOperator Operator
572
573 " override this for consistency
574 hi pandocTitleBlock term=italic gui=italic
575 hi def link pandocTitleBlockTitle Directory
576 hi def link pandocAtxHeader Title
577 hi def link pandocAtxStart Operator
578 hi def link pandocSetexHeader Title
579 hi def link pandocHeaderAttr Comment
580 hi def link pandocHeaderID Identifier
581
582 hi def link pandocLaTexSectionCmd texSection
583 hi def link pandocLaTeXDelimiter texDelimiter
584
585 hi def link pandocHTMLComment Comment
586 hi def link pandocHTMLCommentStart Delimiter
587 hi def link pandocHTMLCommentEnd Delimiter
588 hi def link pandocBlockQuote Comment
589 hi def link pandocBlockQuoteMark Comment
590 hi def link pandocAmpersandEscape Special
591
592 " if the user sets g:pandoc#syntax#codeblocks#ignore to contain
593 " a codeblock type, don't highlight it so that it remains Normal
594 if index(g:pandoc#syntax#codeblocks#ignore, 'definition') == -1
595 hi def link pandocCodeBlockInsideIndent String
596 endif
597
598 if index(g:pandoc#syntax#codeblocks#ignore, 'delimited') == -1
599 hi def link pandocDelimitedCodeBlock Special
600 endif
601
602 hi def link pandocDelimitedCodeBlockStart Delimiter
603 hi def link pandocDelimitedCodeBlockEnd Delimiter
604 hi def link pandocDelimitedCodeBlockLanguage Comment
605 hi def link pandocBlockQuoteinDelimitedCodeBlock pandocBlockQuote
606 hi def link pandocCodePre String
607
608 hi def link pandocLineBlockDelimiter Delimiter
609
610 hi def link pandocListItemBullet Operator
611 hi def link pandocUListItemBullet Operator
612 hi def link pandocListItemBulletId Identifier
613
614 hi def link pandocReferenceLabel Label
615 hi def link pandocReferenceURL Underlined
616 hi def link pandocLinkTip Identifier
617 hi def link pandocImageIcon Operator
618
619 hi def link pandocReferenceDefinition Operator
620 hi def link pandocReferenceDefinitionLabel Label
621 hi def link pandocReferenceDefinitionAddress Underlined
622 hi def link pandocReferenceDefinitionTip Identifier
623
624 hi def link pandocAutomaticLink Underlined
625
626 hi def link pandocDefinitionBlockTerm Identifier
627 hi def link pandocDefinitionBlockMark Operator
628
629 hi def link pandocSimpleTableDelims Delimiter
630 hi def link pandocSimpleTableHeader pandocStrong
631 hi def link pandocTableMultilineHeader pandocStrong
632 hi def link pandocTableDelims Delimiter
633 hi def link pandocGridTableDelims Delimiter
634 hi def link pandocGridTableHeader Delimiter
635 hi def link pandocPipeTableDelims Delimiter
636 hi def link pandocPipeTableHeader Delimiter
637 hi def link pandocTableHeaderWord pandocStrong
638
639 hi def link pandocAbbreviationHead Type
640 hi def link pandocAbbreviation Label
641 hi def link pandocAbbreviationTail Type
642 hi def link pandocAbbreviationSeparator Identifier
643 hi def link pandocAbbreviationDefinition Comment
644
645 hi def link pandocFootnoteID Label
646 hi def link pandocFootnoteIDHead Type
647 hi def link pandocFootnoteIDTail Type
648 hi def link pandocFootnoteDef Comment
649 hi def link pandocFootnoteDefHead Type
650 hi def link pandocFootnoteDefTail Type
651 hi def link pandocFootnoteBlock Comment
652 hi def link pandocFootnoteBlockSeparator Operator
653
654 hi def link pandocPCite Operator
655 hi def link pandocICite Operator
656 hi def link pandocCiteKey Label
657 hi def link pandocCiteAnchor Operator
658 hi def link pandocCiteLocator Operator
659
660 if g:pandoc#syntax#style#emphases == 1
661 hi pandocEmphasis gui=italic cterm=italic
662 hi pandocStrong gui=bold cterm=bold
663 hi pandocStrongEmphasis gui=bold,italic cterm=bold,italic
664 hi pandocStrongInEmphasis gui=bold,italic cterm=bold,italic
665 hi pandocEmphasisInStrong gui=bold,italic cterm=bold,italic
666 if !exists('s:hi_tail')
667 let s:fg = '' " Vint can't figure ou these get set dynamically
668 let s:bg = '' " so initialize them manually first
669 for s:i in ['fg', 'bg']
670 let s:tmp_val = synIDattr(synIDtrans(hlID('String')), s:i)
671 let s:tmp_ui = has('gui_running') || (has('termguicolors') && &termguicolors) ? 'gui' : 'cterm'
672 if !empty(s:tmp_val) && s:tmp_val != -1
673 exe 'let s:'.s:i . ' = "'.s:tmp_ui.s:i.'='.s:tmp_val.'"'
674 else
675 exe 'let s:'.s:i . ' = ""'
676 endif
677 endfor
678 let s:hi_tail = ' '.s:fg.' '.s:bg
679 endif
680 exe 'hi pandocNoFormattedInEmphasis gui=italic cterm=italic'.s:hi_tail
681 exe 'hi pandocNoFormattedInStrong gui=bold cterm=bold'.s:hi_tail
682 endif
683 hi def link pandocNoFormatted String
684 hi def link pandocNoFormattedAttrs Comment
685 hi def link pandocSubscriptMark Operator
686 hi def link pandocSuperscriptMark Operator
687 hi def link pandocStrikeoutMark Operator
688 if g:pandoc#syntax#style#underline_special == 1
689 hi pandocSubscript gui=underline cterm=underline
690 hi pandocSuperscript gui=underline cterm=underline
691 hi pandocStrikeout gui=underline cterm=underline
692 endif
693 hi def link pandocNewLine Error
694 hi def link pandocHRule Delimiter
695endfunction
696
697call s:SetupPandocHighlights()
698
699" }}}1
700
701let b:current_syntax = 'pandoc'
702
703syntax sync clear
704syntax sync minlines=1000
705
706let &cpo = s:cpo_save
707unlet s:cpo_save
708
709" vim: set fdm=marker foldlevel=0: