citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

pdc.vim (10903B)


      1 " Vim syntax file
      2 " Language:	Pandoc (superset of Markdown)
      3 " Maintainer:	Jeremy Schultz <taozhyn@gmail.com> 
      4 " URL:		
      5 " Version:	2
      6 " Changes:	2008-11-04	
      7 "		-   Fixed an issue with Block elements (header) not being highlighted when 
      8 "		    placed on the first or second line of the file
      9 "		-   Fixed multi line HTML comment block
     10 "		-   Fixed lowercase list items
     11 "		-   Fixed list items gobbling to many empty lines
     12 "		-   Added highlight support to identify newline (2 spaces)
     13 "		-   Fixed HTML highlight, ignore if the first character in the
     14 "		    angle brackets is not a letter 
     15 "		-   Fixed Emphasis highlighting when it contained multiple
     16 "		    spaces
     17 " Remark:	Uses HTML and TeX syntax file
     18 
     19 if version < 600
     20   syntax clear
     21 elseif exists("b:current_syntax")
     22   finish
     23 endif
     24 
     25 syn spell toplevel
     26 syn case ignore
     27 syn sync linebreaks=1
     28 
     29 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     30 " Set embedded HTML highlighting
     31 syn include @HTML syntax/html.vim
     32 syn match pdcHTML	/<\a[^>]\+>/	contains=@HTML
     33 
     34 " Support HTML multi line comments
     35 syn region pdcHTMLComment   start=/<!--/ end=/-->/
     36 
     37 
     38 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     39 " Set embedded LaTex (pandox extension) highlighting
     40 " Unset current_syntax so the 2nd include will work
     41 unlet b:current_syntax
     42 syn include @LATEX syntax/tex.vim
     43 
     44 "   Single Tex command
     45 syn match pdcLatex	/\\\w\+{[^}]\+}/	contains=@LATEX
     46 
     47 "   Tex Block (begin-end)
     48 syn region pdcLatex start=/\\begin{[^}]\+}\ze/ end=/\ze\\end{[^}]\+}/ contains=@LATEX 
     49 
     50 "   Math Tex
     51 syn match pdcLatex	/$[^$]\+\$/	   contains=@LATEX
     52 
     53 
     54 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     55 " Block Elements
     56 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     57 
     58 " Needed by other elements 
     59 syn match pdcBlankLine   /\(^\s*\n\|\%^\)/    nextgroup=pdcHeader,pdcCodeBlock,pdcListItem,pdcListItem1,pdcHRule,pdcTableHeader,pdcTableMultiStart,pdcBlockquote transparent
     60 
     61 
     62 """""""""""""""""""""""""""""""""""""""
     63 " Title Block:
     64 syn match pandocTitleBlock /\%^\(%.*\n\)\{1,3}$/ 
     65 
     66 
     67 """""""""""""""""""""""""""""""""""""""
     68 " Headers:
     69 
     70 "   Underlined, using == or --
     71 syn match  pdcHeader    /^.\+\n[=-]\+$/ contains=@Spell nextgroup=pdcHeader contained skipnl
     72 
     73 "   Atx-style, Hash marks
     74 syn region pdcHeader    start="^\s*#\{1,6}[^#]*" end="\($\|#\+\)" contains=@Spell contained nextgroup=pdcHeader skipnl
     75 
     76 
     77 """""""""""""""""""""""""""""""""""""""
     78 " Blockquotes:
     79 
     80 syn match pdcBlockquote	    /\s*>.*$/  nextgroup=pdcBlockquote,pdcBlockquote2 contained skipnl 
     81 syn match pdcBlockquote2    /[^>].*/  nextgroup=pdcBlockquote2 skipnl contained
     82 
     83 
     84 """""""""""""""""""""""""""""""""""""""
     85 " Code Blocks:
     86 
     87 "   Indent with at least 4 space or 1 tab
     88 "   This rule must appear for pdcListItem, or highlighting gets messed up
     89 syn match pdcCodeBlock   /\(\s\{4,}\|\t\{1,}\).*\n/ contained nextgroup=pdcCodeBlock  
     90 
     91 "   HTML code blocks, pre and code
     92 syn match pdcCodeStartPre	/<pre>/ nextgroup=pdcCodeHTMLPre skipnl transparent
     93 syn match pdcCodeHTMLPre   /.*/  contained nextgroup=pdcCodeHTMLPre,pdcCodeEndPre skipnl
     94 syn match pdcCodeEndPre  /\s*<\/pre>/ contained transparent
     95 
     96 "   HTML code blocks, code
     97 syn match pdcCodeStartCode	/<code>/ nextgroup=pdcCodeHTMLCode skipnl transparent
     98 syn match pdcCodeHTMLCode   /.*/  contained nextgroup=pdcCodeHTMLCode,pdcCodeEndCode skipnl
     99 syn match pdcCodeEndCode  /\s*<\/code>/ contained transparent
    100 
    101 
    102 """""""""""""""""""""""""""""""""""""""
    103 " Lists:
    104 
    105 "   These first two rules need to be first or the highlighting will be
    106 "   incorrect
    107 
    108 "   Continue a list on the next line
    109 syn match pdcListCont /\s*[^-+*].*\n/ contained nextgroup=pdcListCont,pdcListItem,pdcListSkipNL transparent
    110 
    111 "   Skip empty lines
    112 syn match pdcListSkipNL /\s*\n/ contained nextgroup=pdcListItem,pdcListSkipNL 
    113 
    114 "   Unorder list
    115 syn match  pdcListItem /\s*[-*+]\s\+/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl 
    116 
    117 "   Order list, numeric
    118 syn match  pdcListItem  /\s*(\?\(\d\+\|#\)[\.)]\s\+/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl
    119 
    120 "   Order list, roman numerals (does not guarantee correct roman numerals)
    121 syn match  pdcListItem  /\s*(\?[ivxlcdm]\+[\.)]\s\+/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl
    122 
    123 "   Order list, lowercase letters
    124 syn match  pdcListItem  /\s*(\?\l[\.)]\s\+/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl
    125 
    126 "   Order list, uppercase letters, does not include '.' 
    127 syn match  pdcListItem  /\s*(\?\u[\)]\s\+/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl
    128 
    129 "   Order list, uppercase letters, special case using '.' and two or more spaces
    130 syn match  pdcListItem  /\s*\u\.\([ ]\{2,}\|\t\+\)/ contained nextgroup=pdcListSkipNL,pdcListCont skipnl
    131 
    132 
    133 """""""""""""""""""""""""""""""""""""""
    134 " Horizontal Rules:
    135 
    136 "   3 or more * on a line
    137 syn match pdcHRule  /\s\{0,3}\(-\s*\)\{3,}\n/	contained nextgroup=pdcHRule
    138 
    139 "   3 or more - on a line
    140 syn match pdcHRule  /\s\{0,3}\(\*\s*\)\{3,}\n/	contained nextgroup=pdcHRule
    141 
    142 
    143 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    144 " Span Elements
    145 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    146 
    147 """""""""""""""""""""""""""""""""""""""
    148 " Links:
    149 
    150 "   Link Text 
    151 syn match pdcLinkText /\[\zs[^\]]*\ze\]/ contains=@Spell
    152 
    153 "   Link ID
    154 syn match pdcLinkID /\][ ]\{0,1}\[\zs[^\]]*\ze\]/
    155 
    156 "   Skip [ so we do not highlight it
    157 syn match pdcSkip /^[ ]\{0,3}\[/ nextgroup=pdcLinkID 
    158 
    159 "   Link ID - definition
    160 syn match pdcLinkID /[^\]]*\ze\]:/ nextgroup=pdcSkip skipwhite contained
    161 
    162 "   Skip ]: so we do not highlight it
    163 syn match pdcSkip /\]:/ contained nextgroup=pdcLinkURL skipwhite
    164 
    165 "   Link URL
    166 syn region pdcLinkURL  start=/\](\zs/	end=/)/me=e-1 
    167 
    168 "   Link URL on ID definition line
    169 syn match pdcLinkURL /\s\+.*\s\+\ze[("']/ nextgroup=pdcLinkTitle skipwhite  contained
    170 syn match pdcLinkURL /\s*.*\s*[^)"']\s*$/ contained 
    171 syn match pdcLinkURL /\s*.*\s*[^)"']\s*\n\s*\ze[("']/ contained nextgroup=pdcLinkTitle skipwhite
    172 
    173 "   Link URL for inline <> links
    174 syn match pdcLinkURL /<http[^>]*>/
    175 syn match pdcLinkURL /<[^>]*@[^>]*.[^>]*>/
    176 
    177 " Link Title
    178 syn match pdcLinkTitle /\s*[("'].*[)"']/ contained contains=@Spell
    179 
    180 
    181 """""""""""""""""""""""""""""""""""""""
    182 " Emphasis:
    183 
    184 "   Using underscores
    185 syn match pdcEmphasis   / \(_\|__\)\([^_ ]\|[^_]\( [^_]\)\+\)\+\1/    contains=@Spell
    186 
    187 "   Using Asterisks
    188 syn match pdcEmphasis   / \(\*\|\*\*\)\([^\* ]\|[^\*]\( [^\*]\)\+\)\+\1/    contains=@Spell
    189 
    190 
    191 """""""""""""""""""""""""""""""""""""""
    192 " Inline Code:
    193    
    194 "   Using single back ticks
    195 syn region pdcCode start=/`/		end=/`\|^\s*$/ 
    196 
    197 "   Using double back ticks
    198 syn region pdcCode start=/``[^`]*/      end=/``\|^\s*$/
    199 
    200 
    201 """""""""""""""""""""""""""""""""""""""
    202 " Images:
    203 "   Handled by link syntax
    204 
    205 
    206 """""""""""""""""""""""""""""""""""""""
    207 " Misc:
    208 
    209 "   Pandoc escapes all characters after a backslash
    210 syn match NONE /\\\W/
    211 
    212 
    213 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    214 " Span Elements
    215 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    216 
    217 """""""""""""""""""""""""""""""""""""""
    218 " Subscripts:
    219 syn match pdcSubscript   /\~\([^\~\\ ]\|\(\\ \)\)\+\~/   contains=@Spell
    220 
    221 """""""""""""""""""""""""""""""""""""""
    222 " Superscript:
    223 syn match pdcSuperscript /\^\([^\^\\ ]\|\(\\ \)\)\+\^/   contains=@Spell
    224 
    225 """""""""""""""""""""""""""""""""""""""
    226 " Strikeout:
    227 syn match pdcStrikeout   /\~\~[^\~ ]\([^\~]\|\~ \)*\~\~/ contains=@Spell
    228 
    229 
    230 """""""""""""""""""""""""""""""""""""""
    231 " Definitions:
    232 syn match pdcDefinitions /:\(\t\|[ ]\{3,}\)/  nextgroup=pdcListItem,pdcCodeBlock,pdcBlockquote,pdcHRule
    233 
    234 """""""""""""""""""""""""""""""""""""""
    235 " Footnote:
    236 syn match pdcFootnoteID /\[\^[^\]]\+\]/ nextgroup=pdcFootnoteDef
    237 
    238 "   This does not work correctly
    239 syn region pdcFootnoteDef  start=/:/ end=/^\n\+\(\(\t\+\|[ ]\{4,}\)\S\)\@!/ contained contains=pdcFootnoteDef
    240 
    241 "   Inline footnotes
    242 syn region pdcFootnoteDef matchgroup=pdcFootnoteID start=/\^\[/ matchgroup=pdcFootnoteID end=/\]/
    243 
    244 
    245 """""""""""""""""""""""""""""""""""""""
    246 " Tables:
    247 "
    248 "   Regular Table
    249 syn match pdcTableHeader /\s*\w\+\(\s\+\w\+\)\+\s*\n\s*-\+\(\s\+-\+\)\+\s*\n/ contained nextgroup=pdcTableBody
    250 syn match pdcTableBody	 /\s*\w\+\(\s\+\w\+\)\+\s*\n/ contained nextgroup=pdcTableBody,pdcTableCaption skipnl
    251 syn match pdcTableCaption /\n\+\s*Table.*\n/ contained nextgroup=pdcTableCaptionCont 
    252 syn match pdcTableCaptionCont /\s*\S.\+\n/ contained nextgroup=pdcTableCaptionCont 
    253 
    254 "   Multi-line Table
    255 syn match pdcTableMultiStart /^\s\{0,3}-\+\s*\n\ze\(\s*\w\+\(\s\+\w\+\)\+\s*\n\)\+\s*-\+\(\s\+-\+\)\+\s*\n/ contained nextgroup=pdcTableMultiHeader
    256 syn match pdcTableMultiEnd /^\s\{0,3}-\+/ contained nextgroup=pdcTableMultiCaption skipnl
    257 syn match pdcTableMultiHeader /\(\s*\w\+\(\s\+\w\+\)\+\s*\n\)\+\s*-\+\(\s\+-\+\)\+\s*\n/ contained nextgroup=pdcTableMultiBody 
    258 syn match pdcTableMultiBody /^\(\s\{3,}[^-]\|[^-\s]\).*$/ contained nextgroup=pdcTableMultiBody,pdcTableMultiSkipNL,pdcTableMultiEnd skipnl
    259 syn match pdcTableMultiSkipNL /^\s*\n/ contained nextgroup=pdcTableMultiBody,pdcTableMultiEnd skipnl
    260 syn match pdcTableMultiCaption /\n*\s*Table.*\n/ contained nextgroup=pdcTableCaptionCont 
    261 
    262 
    263 
    264 """""""""""""""""""""""""""""""""""""""
    265 " Delimited Code Block: (added in 1.0)
    266 syn region pdcCodeBlock matchgroup=pdcCodeStart start=/^\z(\~\{3,}\) \( {[^}]\+}\)\?/ matchgroup=pdcCodeEnd end=/^\z1\~*/ 
    267 
    268 
    269 """""""""""""""""""""""""""""""""""""""
    270 " Newline, 2 spaces at the end of line means newline
    271 syn match pdcNewLine /  $/
    272 
    273 
    274 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    275 " Highlight groups
    276 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    277 hi link pdcHeader		Title
    278 hi link pdcBlockquote	    	Comment
    279 hi link pdcBlockquote2	    	Comment
    280 
    281 hi link pdcHTMLComment		Comment
    282 
    283 hi link pdcHRule		Underlined
    284 "hi link pdcHRule		Special
    285 
    286 hi link pdcListItem		Operator
    287 hi link pdcDefinitions		Operator
    288 
    289 hi link pdcEmphasis		Special
    290 hi link pdcSubscript		Special
    291 hi link pdcSuperscript		Special
    292 hi link pdcStrikeout	 	Special
    293 
    294 hi link pdcLinkText		Underlined
    295 hi link pdcLinkID		Identifier
    296 hi link pdcLinkURL		Type
    297 hi link pdcLinkTitle		Comment
    298 
    299 hi link pdcFootnoteID		Identifier
    300 hi link pdcFootnoteDef		Comment
    301 hi link pandocFootnoteCont 	Error
    302 
    303 hi link pdcCodeBlock		String
    304 hi link pdcCodeHTMLPre		String
    305 hi link pdcCodeHTMLCode		String
    306 hi link pdcCode			String
    307 hi link pdcCodeStart		Comment
    308 hi link pdcCodeEnd		Comment
    309 
    310 hi link pandocTitleBlock	Comment
    311 
    312 hi link pdcTableMultiStart	Comment
    313 hi link pdcTableMultiEnd	Comment
    314 hi link pdcTableHeader		Define
    315 hi link pdcTableMultiHeader	Define
    316 hi link pdcTableBody		Identifier
    317 hi link pdcTableMultiBody	Identifier
    318 hi link pdcTableCaption		Label
    319 hi link pdcTableMultiCaption	Label
    320 hi link pdcTableCaptionCont	Label
    321 
    322 hi link pdcNewLine		Error
    323 
    324 
    325 " For testing
    326 hi link pdctest		Error
    327 
    328 
    329 let b:current_syntax = "pandoc"
    330