| 1 | " Vim syntax file |
|---|
| 2 | " Language: Genshi |
|---|
| 3 | " Maintainer: Matt Good <matt@matt-good.net> |
|---|
| 4 | " Last Change: Sun Jan 1, 2006 |
|---|
| 5 | " Filenames: *.html,*.htm,*.xml |
|---|
| 6 | " |
|---|
| 7 | " This syntax file covers the Genshi XML template language. |
|---|
| 8 | " Based on Karl Guertin's Kid syntax file |
|---|
| 9 | |
|---|
| 10 | if !exists('b:genshi_type') |
|---|
| 11 | if expand('%:e') =~ 'htm[l]\?' |
|---|
| 12 | let b:genshi_type = 'html' |
|---|
| 13 | else |
|---|
| 14 | let b:genshi_type = 'xml' |
|---|
| 15 | endif |
|---|
| 16 | endif |
|---|
| 17 | if 'html' == b:genshi_type |
|---|
| 18 | doau Syntax xhtml |
|---|
| 19 | elseif 'xml' == b:genshi_type |
|---|
| 20 | doau Syntax xml |
|---|
| 21 | endif |
|---|
| 22 | |
|---|
| 23 | unlet b:current_syntax |
|---|
| 24 | let python_highlight_builtins = 1 |
|---|
| 25 | syn include @pythonCode syntax/python.vim |
|---|
| 26 | syn case match |
|---|
| 27 | |
|---|
| 28 | syn keyword genshiFunctions XML ET defined value_of contained |
|---|
| 29 | |
|---|
| 30 | syn clear pythonString |
|---|
| 31 | syn region pythonString start=+[uU]\='+ end=+'+ skip=+\\\\\|\\'+ |
|---|
| 32 | \ contains=pythonEscape matchgroup=Normal |
|---|
| 33 | syn region pythonString start=+[uU]\="""+ end=+"""+ |
|---|
| 34 | \ contains=pythonEscape matchgroup=Normal |
|---|
| 35 | syn region pythonString start=+[uU]\='''+ end=+'''+ |
|---|
| 36 | \ contains=pythonEscape matchgroup=Normal |
|---|
| 37 | |
|---|
| 38 | " The python string highlighting just doesn't work when the python is in an |
|---|
| 39 | " attr, hence this method. |
|---|
| 40 | syn region npythonString start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ |
|---|
| 41 | \ contains=pythonEscape matchgroup=Normal |
|---|
| 42 | hi def link npythonString String |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | syn match genshiAttr containedin=htmlTag,xmlTag contained |
|---|
| 46 | \ nextgroup=genshiPythonAttr |
|---|
| 47 | \ +[^<]\<py:\(attrs\|choose\|content\|def\|for\|if\|match\|otherwise\|replace\|strip\|when\|with\)\>+hs=s+1 |
|---|
| 48 | |
|---|
| 49 | syn region genshiTag start=+<py:+he=e-3 end=+>+ |
|---|
| 50 | \ contains=genshiTagName,genshiTagAttr,genshiPythonAttr |
|---|
| 51 | syn region genshiEndTag start=+</py:+he=e-3 end=+>+ |
|---|
| 52 | \ contains=genshiTagName |
|---|
| 53 | syn match genshiTagName contained |
|---|
| 54 | \ '\<py:\(choose\|def\|for\|if\|match\|otherwise\|when\|with\)\>' |
|---|
| 55 | syn keyword genshiTagAttr contained each function path test vars |
|---|
| 56 | |
|---|
| 57 | syn match genshiDelims '\${' contained |
|---|
| 58 | syn match genshiDelims '}' contained |
|---|
| 59 | syn match genshiDelims '<?python' contained |
|---|
| 60 | syn match genshiDelims '?>' contained |
|---|
| 61 | |
|---|
| 62 | syn match genshiXmlError "&\%(\S\+;\)\@!\|<\%(?\)\@!\|?\@<!>" contained |
|---|
| 63 | |
|---|
| 64 | syn region genshiPython start="<?python" end="?>" |
|---|
| 65 | \ contains=genshiFunctions,@pythonCode,genshiDelims,npythonString, |
|---|
| 66 | \ genshiXmlError |
|---|
| 67 | \ transparent keepend |
|---|
| 68 | syn region genshiPython start="\${" end="}" |
|---|
| 69 | \ contains=genshiFunctions,@pythonCode,genshiDelims,npythonString, |
|---|
| 70 | \ genshiXmlError |
|---|
| 71 | \ transparent keepend |
|---|
| 72 | \ containedin=htmlString,xmlString,htmlHead,javaScript, |
|---|
| 73 | \ htmlBold,htmlBoldUnderline,htmlBoldItalic, |
|---|
| 74 | \ htmlUnderline,htmlUnderlineItalic,htmlItalic, |
|---|
| 75 | \ htmlBoldUnderlineItalic,htmlH1,htmlH2,htmlH3, |
|---|
| 76 | \ htmlH4,htmlH5,htmlTitle,htmlLink |
|---|
| 77 | |
|---|
| 78 | syn region genshiPythonAttr start=+\%(=\)"+ end=+"+ |
|---|
| 79 | \ contains=genshiFunctions,genshiPython,genshiDelims |
|---|
| 80 | \ transparent keepend contained |
|---|
| 81 | syn region genshiPython start=+"+hs=s+1, end=+"+he=e-1 |
|---|
| 82 | \ contains=genshiFunctions,@pythonCode,genshiXmlError |
|---|
| 83 | \ transparent contained |
|---|
| 84 | |
|---|
| 85 | hi link genshiAttr PreProc |
|---|
| 86 | hi link genshiTagAttr PreProc |
|---|
| 87 | hi link genshiTag Function |
|---|
| 88 | hi link genshiEndTag Identifier |
|---|
| 89 | hi link genshiTagName PreProc |
|---|
| 90 | hi link genshiDelims Delimiter |
|---|
| 91 | hi link genshiXmlError Error |
|---|
| 92 | hi link genshiFunctions Keyword |
|---|
| 93 | |
|---|
| 94 | let b:current_syntax = "genshi" |
|---|