Skip to content

Commit 6cf1671

Browse files
authored
Merge branch 'master' into patch-syntax-highlighting
2 parents 72d9553 + 16939cd commit 6cf1671

File tree

2 files changed

+178
-134
lines changed

2 files changed

+178
-134
lines changed

doc/pandoc-syntax.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CONFIGURATION *vim-pandoc-syntax-configuration*
3838
- ellipses
3939
- quotes
4040
- inlinecode
41+
- inlinemath
4142

4243
To review what are the rules for, look for the call to |s:WithConceal| in
4344
syntax/pandoc.vim that takes the corresponding rulename as first argument.
@@ -75,7 +76,7 @@ CONFIGURATION *vim-pandoc-syntax-configuration*
7576
you couldn't tell where the styles are applied.
7677

7778
+ *g:pandoc#syntax#style#underline_special*
78-
Undeline subscript, superscript and strikeout text styles. Default = 1
79+
Underline subscript, superscript and strikeout text styles. Default = 1
7980

8081
+ *g:pandoc#syntax#style#use_definition_lists*
8182
Detect and highlight definition lists. Disabling this can improve

syntax/pandoc.vim

+176-133
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ if &encoding ==# 'utf-8'
5151
\'definition': ' ',
5252
\'li': '•',
5353
\'html_c_s': '‹',
54-
\'html_c_e': '›'}
54+
\'html_c_e': '›',
55+
\'quote_s': '“',
56+
\'quote_e': '”'}
5557
else
5658
" ascii defaults
5759
let s:cchars = {
@@ -170,6 +172,9 @@ function! EnableEmbedsforCodeblocksWithLang(entry)
170172
let s:langsyntaxfile = matchstr(a:entry, '[^=]*$')
171173
unlet! b:current_syntax
172174
exe 'syn include @'.toupper(s:langname).' syntax/'.s:langsyntaxfile.'.vim'
175+
" We might have just turned off spellchecking by including the file,
176+
" so we turn it back on here.
177+
exe 'syntax spell toplevel'
173178
exe 'syn region pandocDelimitedCodeBlock_' . s:langname . ' start=/\(\_^\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*[.=]\)\=' . s:langname . '\>.*\n\)\@<=\_^/' .
174179
\' end=/\_$\n\(\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\_$\n\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock' .
175180
\' contains=@' . toupper(s:langname)
@@ -258,8 +263,13 @@ call s:WithConceal('html_c_e', 'syn match pandocHTMLCommentEnd /-->/ contained',
258263
" Unset current_syntax so the 2nd include will work
259264
unlet b:current_syntax
260265
syn include @LATEX syntax/tex.vim
261-
syn region pandocLaTeXInlineMath start=/\v\\@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@LATEX
262-
syn region pandocLaTeXInlineMath start=/\\\@<!\\(/ end=/\\\@<!\\)/ keepend contains=@LATEX
266+
if index(g:pandoc#syntax#conceal#blacklist, 'inlinemath') == -1
267+
" Can't use WithConceal here because it will mess up all other conceals
268+
" when dollar signs are used normally. It must be skipped entirely if
269+
" inlinemath is blacklisted
270+
syn region pandocLaTeXInlineMath start=/\v\\@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@LATEX
271+
syn region pandocLaTeXInlineMath start=/\\\@<!\\(/ end=/\\\@<!\\)/ keepend contains=@LATEX
272+
endif
263273
syn match pandocEscapedDollar /\\\$/ conceal cchar=$
264274
syn match pandocProtectedFromInlineLaTeX /\\\@<!\${.*}\(\(\s\|[[:punct:]]\)\([^$]*\|.*\(\\\$.*\)\{2}\)\n\n\|$\)\@=/ display
265275
" contains=@LATEX
@@ -313,7 +323,7 @@ call s:WithConceal('image', 'syn match pandocImageIcon /!\[\@=/ display', 'conce
313323
" }}}3
314324

315325
" Definitions: {{{3
316-
syn region pandocReferenceDefinition start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" keepend
326+
syn region pandocReferenceDefinition start=/\[.\{-}\]:/ end=/\(\n\s*".*"$\|$\)/ keepend
317327
syn match pandocReferenceDefinitionLabel /\[\zs.\{-}\ze\]:/ contained containedin=pandocReferenceDefinition display
318328
syn match pandocReferenceDefinitionAddress /:\s*\zs.*/ contained containedin=pandocReferenceDefinition
319329
syn match pandocReferenceDefinitionTip /\s*".\{-}"/ contained containedin=pandocReferenceDefinition,pandocReferenceDefinitionAddress contains=@Spell,pandocAmpersandEscape
@@ -438,9 +448,9 @@ syn match pandocTableHeaderWord /\<.\{-}\>/ contained containedin=pandocGridTabl
438448

439449
" Delimited Code Blocks: {{{2
440450
" this is here because we can override strikeouts and subscripts
441-
syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
442-
syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
443-
call s:WithConceal('codeblock_start', 'syn match pandocDelimitedCodeBlockStart /\(\(\_^\n\_^\|\%^\)\(>\s\)\?\([ ]\{4,}\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=pandocDelimitedCodeBlock nextgroup=pandocDelimitedCodeBlockLanguage', 'conceal cchar='.s:cchars['codelang'])
451+
syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
452+
syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\+\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
453+
call s:WithConceal('codeblock_start', 'syn match pandocDelimitedCodeBlockStart /\(\(\_^\n\_^\|\%^\)\(>\s\)\?\( \+\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=pandocDelimitedCodeBlock nextgroup=pandocDelimitedCodeBlockLanguage', 'conceal cchar='.s:cchars['codelang'])
444454
syn match pandocDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained
445455
call s:WithConceal('codeblock_delim', 'syn match pandocDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock', 'conceal cchar='.s:cchars['codeend'])
446456
syn match pandocBlockQuoteinDelimitedCodeBlock '^>' contained containedin=pandocDelimitedCodeBlock
@@ -540,8 +550,8 @@ endif
540550

541551
" Quotes: {{{3
542552
if &encoding ==# 'utf-8'
543-
call s:WithConceal('quotes', 'syn match pandocBeginQuote /"\</ containedin=pandocEmphasis,pandocStrong,pandocListItem,pandocListItemContinuation,pandocUListItem display', 'conceal cchar=')
544-
call s:WithConceal('quotes', 'syn match pandocEndQuote /\(\>[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=')
553+
call s:WithConceal('quotes', 'syn match pandocBeginQuote /"\</ containedin=pandocEmphasis,pandocStrong,pandocListItem,pandocListItemContinuation,pandocUListItem display', 'conceal cchar='.s:cchars['quote_s'])
554+
call s:WithConceal('quotes', 'syn match pandocEndQuote /\(\>[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/ containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar='.s:cchars['quote_e'])
545555
endif
546556
" }}}3
547557

@@ -571,130 +581,163 @@ syn region pandocYAMLHeader start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/
571581
" }}}1
572582

573583
" Styling: {{{1
574-
hi link pandocOperator Operator
575-
576-
" override this for consistency
577-
hi pandocTitleBlock term=italic gui=italic
578-
hi link pandocTitleBlockTitle Directory
579-
hi link pandocAtxHeader Title
580-
hi link pandocAtxStart Operator
581-
hi link pandocSetexHeader Title
582-
hi link pandocHeaderAttr Comment
583-
hi link pandocHeaderID Identifier
584-
585-
hi link pandocLaTexSectionCmd texSection
586-
hi link pandocLaTeXDelimiter texDelimiter
587-
588-
hi link pandocHTMLComment Comment
589-
hi link pandocHTMLCommentStart Delimiter
590-
hi link pandocHTMLCommentEnd Delimiter
591-
hi link pandocBlockQuote Comment
592-
hi link pandocBlockQuoteMark Comment
593-
hi link pandocAmpersandEscape Special
594-
595-
" if the user sets g:pandoc#syntax#codeblocks#ignore to contain
596-
" a codeblock type, don't highlight it so that it remains Normal
597-
if index(g:pandoc#syntax#codeblocks#ignore, 'definition') == -1
598-
hi link pandocCodeBlockInsideIndent String
599-
endif
600-
601-
if index(g:pandoc#syntax#codeblocks#ignore, 'delimited') == -1
602-
hi link pandocDelimitedCodeBlock Special
603-
endif
604-
605-
hi link pandocDelimitedCodeBlockStart Delimiter
606-
hi link pandocDelimitedCodeBlockEnd Delimiter
607-
hi link pandocDelimitedCodeBlockLanguage Comment
608-
hi link pandocBlockQuoteinDelimitedCodeBlock pandocBlockQuote
609-
hi link pandocCodePre String
610-
611-
hi link pandocLineBlockDelimiter Delimiter
612-
613-
hi link pandocListItemBullet Operator
614-
hi link pandocUListItemBullet Operator
615-
hi link pandocListItemBulletId Identifier
616-
617-
hi link pandocReferenceLabel Label
618-
hi link pandocReferenceURL Underlined
619-
hi link pandocLinkTip Identifier
620-
hi link pandocImageIcon Operator
621-
622-
hi link pandocReferenceDefinition Operator
623-
hi link pandocReferenceDefinitionLabel Label
624-
hi link pandocReferenceDefinitionAddress Underlined
625-
hi link pandocReferenceDefinitionTip Identifier
626-
627-
hi link pandocAutomaticLink Underlined
628-
629-
hi link pandocDefinitionBlockTerm Identifier
630-
hi link pandocDefinitionBlockMark Operator
631-
632-
hi link pandocSimpleTableDelims Delimiter
633-
hi link pandocSimpleTableHeader pandocStrong
634-
hi link pandocTableMultilineHeader pandocStrong
635-
hi link pandocTableDelims Delimiter
636-
hi link pandocGridTableDelims Delimiter
637-
hi link pandocGridTableHeader Delimiter
638-
hi link pandocPipeTableDelims Delimiter
639-
hi link pandocPipeTableHeader Delimiter
640-
hi link pandocTableHeaderWord pandocStrong
641-
642-
hi link pandocAbbreviationHead Type
643-
hi link pandocAbbreviation Label
644-
hi link pandocAbbreviationTail Type
645-
hi link pandocAbbreviationSeparator Identifier
646-
hi link pandocAbbreviationDefinition Comment
647-
648-
hi link pandocFootnoteID Label
649-
hi link pandocFootnoteIDHead Type
650-
hi link pandocFootnoteIDTail Type
651-
hi link pandocFootnoteDef Comment
652-
hi link pandocFootnoteDefHead Type
653-
hi link pandocFootnoteDefTail Type
654-
hi link pandocFootnoteBlock Comment
655-
hi link pandocFootnoteBlockSeparator Operator
656-
657-
hi link pandocPCite Operator
658-
hi link pandocICite Operator
659-
hi link pandocCiteKey Label
660-
hi link pandocCiteAnchor Operator
661-
hi link pandocCiteLocator Operator
662-
663-
if g:pandoc#syntax#style#emphases == 1
664-
hi pandocEmphasis gui=italic cterm=italic
665-
hi pandocStrong gui=bold cterm=bold
666-
hi pandocStrongEmphasis gui=bold,italic cterm=bold,italic
667-
hi pandocStrongInEmphasis gui=bold,italic cterm=bold,italic
668-
hi pandocEmphasisInStrong gui=bold,italic cterm=bold,italic
669-
if !exists('s:hi_tail')
670-
let s:fg = '' " Vint can't figure ou these get set dynamically
671-
let s:bg = '' " so initialize them manually first
672-
for s:i in ['fg', 'bg']
673-
let s:tmp_val = synIDattr(synIDtrans(hlID('String')), s:i)
674-
let s:tmp_ui = has('gui_running') || (has('termguicolors') && &termguicolors) ? 'gui' : 'cterm'
675-
if !empty(s:tmp_val) && s:tmp_val != -1
676-
exe 'let s:'.s:i . ' = "'.s:tmp_ui.s:i.'='.s:tmp_val.'"'
677-
else
678-
exe 'let s:'.s:i . ' = ""'
679-
endif
680-
endfor
681-
let s:hi_tail = ' '.s:fg.' '.s:bg
682-
endif
683-
exe 'hi pandocNoFormattedInEmphasis gui=italic cterm=italic'.s:hi_tail
684-
exe 'hi pandocNoFormattedInStrong gui=bold cterm=bold'.s:hi_tail
685-
endif
686-
hi link pandocNoFormatted String
687-
hi link pandocNoFormattedAttrs Comment
688-
hi link pandocSubscriptMark Operator
689-
hi link pandocSuperscriptMark Operator
690-
hi link pandocStrikeoutMark Operator
691-
if g:pandoc#syntax#style#underline_special == 1
692-
hi pandocSubscript gui=underline cterm=underline
693-
hi pandocSuperscript gui=underline cterm=underline
694-
hi pandocStrikeout gui=underline cterm=underline
695-
endif
696-
hi link pandocNewLine Error
697-
hi link pandocHRule Delimiter
584+
function! s:SetupPandocHighlights()
585+
586+
hi link pandocOperator Operator
587+
588+
" override this for consistency
589+
hi pandocTitleBlock term=italic gui=italic
590+
hi link pandocTitleBlockTitle Directory
591+
hi link pandocAtxHeader Title
592+
hi link pandocAtxStart Operator
593+
hi link pandocSetexHeader Title
594+
hi link pandocHeaderAttr Comment
595+
hi link pandocHeaderID Identifier
596+
597+
hi link pandocLaTexSectionCmd texSection
598+
hi link pandocLaTeXDelimiter texDelimiter
599+
600+
hi link pandocHTMLComment Comment
601+
hi link pandocHTMLCommentStart Delimiter
602+
hi link pandocHTMLCommentEnd Delimiter
603+
hi link pandocBlockQuote Comment
604+
hi link pandocBlockQuoteMark Comment
605+
hi link pandocAmpersandEscape Special
606+
607+
" if the user sets g:pandoc#syntax#codeblocks#ignore to contain
608+
" a codeblock type, don't highlight it so that it remains Normal
609+
if index(g:pandoc#syntax#codeblocks#ignore, 'definition') == -1
610+
hi link pandocCodeBlockInsideIndent String
611+
endif
612+
613+
if index(g:pandoc#syntax#codeblocks#ignore, 'delimited') == -1
614+
hi link pandocDelimitedCodeBlock Special
615+
endif
616+
617+
hi link pandocDelimitedCodeBlockStart Delimiter
618+
hi link pandocDelimitedCodeBlockEnd Delimiter
619+
hi link pandocDelimitedCodeBlockLanguage Comment
620+
hi link pandocBlockQuoteinDelimitedCodeBlock pandocBlockQuote
621+
hi link pandocCodePre String
622+
623+
hi link pandocLineBlockDelimiter Delimiter
624+
625+
hi link pandocListItemBullet Operator
626+
hi link pandocUListItemBullet Operator
627+
hi link pandocListItemBulletId Identifier
628+
629+
hi link pandocReferenceLabel Label
630+
hi link pandocReferenceURL Underlined
631+
hi link pandocLinkTip Identifier
632+
hi link pandocImageIcon Operator
633+
634+
hi link pandocReferenceDefinition Operator
635+
hi link pandocReferenceDefinitionLabel Label
636+
hi link pandocReferenceDefinitionAddress Underlined
637+
hi link pandocReferenceDefinitionTip Identifier
638+
639+
hi link pandocAutomaticLink Underlined
640+
641+
hi link pandocDefinitionBlockTerm Identifier
642+
hi link pandocDefinitionBlockMark Operator
643+
644+
hi link pandocSimpleTableDelims Delimiter
645+
hi link pandocSimpleTableHeader pandocStrong
646+
hi link pandocTableMultilineHeader pandocStrong
647+
hi link pandocTableDelims Delimiter
648+
hi link pandocGridTableDelims Delimiter
649+
hi link pandocGridTableHeader Delimiter
650+
hi link pandocPipeTableDelims Delimiter
651+
hi link pandocPipeTableHeader Delimiter
652+
hi link pandocTableHeaderWord pandocStrong
653+
654+
hi link pandocAbbreviationHead Type
655+
hi link pandocAbbreviation Label
656+
hi link pandocAbbreviationTail Type
657+
hi link pandocAbbreviationSeparator Identifier
658+
hi link pandocAbbreviationDefinition Comment
659+
660+
hi link pandocFootnoteID Label
661+
hi link pandocFootnoteIDHead Type
662+
hi link pandocFootnoteIDTail Type
663+
hi link pandocFootnoteDef Comment
664+
hi link pandocFootnoteDefHead Type
665+
hi link pandocFootnoteDefTail Type
666+
hi link pandocFootnoteBlock Comment
667+
hi link pandocFootnoteBlockSeparator Operator
668+
669+
hi link pandocPCite Operator
670+
hi link pandocICite Operator
671+
hi link pandocCiteKey Label
672+
hi link pandocCiteAnchor Operator
673+
hi link pandocCiteLocator Operator
674+
675+
if g:pandoc#syntax#style#emphases == 1
676+
hi pandocEmphasis gui=italic cterm=italic
677+
hi pandocStrong gui=bold cterm=bold
678+
hi pandocStrongEmphasis gui=bold,italic cterm=bold,italic
679+
hi pandocStrongInEmphasis gui=bold,italic cterm=bold,italic
680+
hi pandocEmphasisInStrong gui=bold,italic cterm=bold,italic
681+
if !exists('s:hi_tail')
682+
let s:fg = '' " Vint can't figure ou these get set dynamically
683+
let s:bg = '' " so initialize them manually first
684+
for s:i in ['fg', 'bg']
685+
let s:tmp_val = synIDattr(synIDtrans(hlID('String')), s:i)
686+
let s:tmp_ui = has('gui_running') || (has('termguicolors') && &termguicolors) ? 'gui' : 'cterm'
687+
if !empty(s:tmp_val) && s:tmp_val != -1
688+
exe 'let s:'.s:i . ' = "'.s:tmp_ui.s:i.'='.s:tmp_val.'"'
689+
else
690+
exe 'let s:'.s:i . ' = ""'
691+
endif
692+
endfor
693+
let s:hi_tail = ' '.s:fg.' '.s:bg
694+
endif
695+
exe 'hi pandocNoFormattedInEmphasis gui=italic cterm=italic'.s:hi_tail
696+
exe 'hi pandocNoFormattedInStrong gui=bold cterm=bold'.s:hi_tail
697+
endif
698+
hi link pandocNoFormatted String
699+
hi link pandocNoFormattedAttrs Comment
700+
hi link pandocSubscriptMark Operator
701+
hi link pandocSuperscriptMark Operator
702+
hi link pandocStrikeoutMark Operator
703+
if g:pandoc#syntax#style#underline_special == 1
704+
hi pandocSubscript gui=underline cterm=underline
705+
hi pandocSuperscript gui=underline cterm=underline
706+
hi pandocStrikeout gui=underline cterm=underline
707+
endif
708+
hi link pandocNewLine Error
709+
hi link pandocHRule Delimiter
710+
711+
endfunction
712+
713+
" Whenever the colorscheme changes, all highlights are cleared.
714+
"
715+
" The most common circumstance is that the vimrc picks a colorscheme *at
716+
" startup*, then a file is opened and the syntax is set based on that file. So
717+
" the most common situation is that the colorscheme runs, then the syntax
718+
" runs, and that's that. So if the code for the syntax (e.g., this code here
719+
" in vim-pandoc-syntax) *adds* new highlighting groups that weren't defined in
720+
" the colorscheme, that's almost always fine because the colorscheme rarely
721+
" changes after startup.
722+
"
723+
" But the colorscheme *can* change after startup. This happens for example any
724+
" time the user toggles their background (:set bg=light or :set bg=dark), or
725+
" picks another colorscheme (:colorscheme something_else). In these cases, the
726+
" new colorscheme calls `:highlight clear`, clearing any custom pandoc
727+
" highlighting groups.
728+
"
729+
" The solution is to register an autocommand that runs whenever the
730+
" ColorScheme changes, so that we can re-register vim-pandoc-syntax's custom
731+
" highlighting groups, after the new colorscheme has cleared them.
732+
"
733+
" (This also affects popular plugins like goyo.vim, which call `:colorscheme`
734+
" with your chosen colorscheme to approximate undoing any custom highlighting
735+
" modifications that they've made.)
736+
augroup vim-pandoc-syntax
737+
autocmd!
738+
autocmd ColorScheme * call s:SetupPandocHighlights()
739+
augroup end
740+
call s:SetupPandocHighlights()
698741

699742
" }}}1
700743

0 commit comments

Comments
 (0)