Skip to content

Commit f51bac4

Browse files
committed
replace the syntax file with something more minimalistic and opinionated
1 parent bcc78d8 commit f51bac4

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

autoload/pandoc/syntax/color.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function! pandoc#syntax#color#Instrospect(group)
100100
let hi_output = split(hi_output, '\n')[0]
101101
let parts = split(hi_output, '\s\+')[2:]
102102
if parts[0] == 'links'
103-
let info = Hi_Info(parts[2])
103+
let info = pandoc#syntax#color#Instrospect(parts[2])
104104
let info['linked_to'] = parts[2]
105105
else
106106
let info = {}

syntax/pandoc.vim

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,71 @@
11
" Vim syntax file
22
" Filetype: pandoc
3-
" Language: CommonMark
4-
" Maintainer: Caleb Maclennan <[email protected]>
3+
" Language: pandoc markdown, simplified
54
" Maintainer: Felipe Morales <[email protected]>
65

76
scriptencoding utf-8
87

9-
if exists('b:current_syntax')
10-
finish
11-
endif
8+
syntax clear
129

13-
if !exists('b:is_legacy')
14-
let b:is_legacy = exists('g:pandoc_legacy')
15-
endif
10+
syn spell toplevel
1611

17-
if b:is_legacy
18-
syntax clear
19-
else
20-
source pandoc_legacy.vim
21-
endif
12+
" A pandoc markdown document is based on blocks.
2213

23-
let b:current_syntax = b:is_legacy ? 'pandoc' : 'pandoc_legacy'
14+
syn region pdcPar start=/^\s*[[:print:]]/ end=/[[:print:]]\(\n\s*\n\)\@=/ keepend contains=@Spell
15+
16+
" YAML headers
17+
unlet! b:current_syntax
18+
syn include @YAML syntax/yaml.vim
19+
syn region pdcYAML matchgroup=Delimiter start=/^\s*---\(\n\s*[[:print:]]\)\@=/ end=/---\n\s*\n/ keepend contains=@YAML
20+
21+
" LaTeX environments
22+
unlet! b:current_syntax
23+
syn include @LATEX syntax/tex.vim
24+
syn region pdcLaTeXEnv start=/\\begin{\z(.\{-}\)}/ end=/\\end{\z1}/ keepend contains=@LATEX
25+
syn region pdcLaTeXDisplayMath start=/\z(\\\@<!\$\{1,2}\)/ end=/\z1/ keepend contains=@LATEX containedin=pdcPar,pdcBlockQuote,pdcOList,pdcUList,pdcFootnote,pdcFootnotePar
26+
"syn match pdcLaTeXCmd /\\\S\{1,}/ contains=@LATEX keepend containedin=pdcPar
27+
syn match pdcLaTeXCmd /\\[[:alpha:]]\+\(\({.\{-}}\)\=\(\[.\{-}\]\)\=\)*/ contains=@LATEX keepend containedin=pdcPar,pdcBlockQuote,pdcOList,pdcUList,pdcFootnote,pdcFootnotePar
28+
29+
" Code Blocks
30+
syn region pdcCodeblock start=/^\(\s\{4,}\|\t\{1,}\)/ end=/[[:print:]]\zs\n\ze\s*\n/
31+
syn region pdcDelimitedCodeBlock start=/^\z([`~]\{3}\)/ end=/\z1\n\s*\n/
32+
syn region pdcLaTeXCodeBlock matchgroup=Delimiter start=/^```{=latex}/ end=/```\n\s*\n/ keepend contains=@LATEX
33+
34+
" Blockquotes
35+
syn region pdcBlockQuote start=/^\s\{,3}>\s\?/ end=/[[:print:]]\(\n\s*\n\)\@=/ keepend
36+
37+
" Lists
38+
syn region pdcUList start=/^>\=\s*[*=-]\ze\s*[[:print:]]$/ end=/[[:print:]]\(\n\s*\n\)\@=/ keepend
39+
syn region pdcOList start=/^(\?\(\d\+\|\l\|\#\|@.\{-}\|x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}\)[.)]/ end=/[[:print:]]\(\n\s*\n\)\@=/ keepend
40+
41+
" Fenced DIVS
42+
syn region pdcFencedDiv matchgroup=Delimiter start=/^:::.*$/ end=/:::\n\s*\n/ keepend contains=@LATEX,pdcPar contains=@Spell
43+
44+
" Atx headers
45+
syn match pdcAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ keepend contained containedin=pdcPar contains=@Spell
46+
47+
" Footnotes
48+
syn region pdcFootnote start=/^\[\^/ end=/[[:print:]]\zs\n\ze\s*\n/ keepend contains=@Spell
49+
syn region pdcInlineFootnote matchgroup=Delimiter start=/\^\[/ skip=/\[[[:print:]]*\]/ end=/\]/ keepend contained containedin=pdcPar,pdcUList,pdcOList
50+
syn region pdcFootnoteRef matchgroup=Delimiter start=/\[\^/ end=/\]/ contained containedin=pdcPar,pdcBlockQuote,pdcUList,pdcOList,pdcFootnote nextgroup=pdcFootnotePar
51+
syn region pdcFootnotePar start=/^\t[[:print:]]/ end=/[[:print:]]\(\n\s*\n\)\@=/ keepend contains=@Spell nextgroup=pdcFootnotePar
52+
53+
" References.
54+
syn match pdcBibRef /@[[:alnum:]:_-]\{1,}\(\[[[:print:]]\{-}\]\)\?/ containedin=pdcPar,pdcUList,pdcOList,pdcBlockQuote
55+
syn match pdcBibRefIF /@[[:alnum:]:_-]\{1,}\(\[[[:print:]]\{-}\]\)\?/ containedin=pdcInlineFootnote,pdcFootnote,pdcFootnotePar
56+
57+
let b:current_syntax = 'pandoc'
58+
59+
hi def link pdcCodeblock Special
60+
hi def link pdcDelimitedCodeBlock pdcCodeblock
61+
hi def link pdcAtxHeader Directory
62+
hi def link pdcFootnote Comment
63+
hi def link pdcInlineFootnote pdcFootnote
64+
hi def link pdcFootnotePar pdcFootnote
65+
hi def link pdcFootnoteBlockQuote pdcFootnote
66+
hi def pdcBodyLink ctermfg=fg guifg=fg guisp=SteelBlue4 gui=underline cterm=underline
67+
let fn_fg = pandoc#syntax#color#Instrospect('pdcInlineFootnote').guifg
68+
exe 'hi def pdcFootLink guifg='.fn_fg.' guisp=SteelBlue4 gui=underline cterm=underline'
69+
hi def link pdcBibRef pdcBodyLink
70+
hi def link pdcFootnoteRef pdcFootLink
71+
hi def link pdcBibRefIF pdcFootLink

0 commit comments

Comments
 (0)