0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/syntax/rmd.vim

124 lines
4.3 KiB
VimL
Raw Normal View History

2014-07-10 22:01:47 +02:00
" markdown Text with R statements
" Language: markdown with R code chunks
2016-03-12 12:57:59 +01:00
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
2017-04-09 20:11:58 +02:00
" Last Change: Sat Jan 28, 2017 10:06PM
2014-07-10 22:01:47 +02:00
"
" CONFIGURATION:
2017-04-09 20:11:58 +02:00
" To highlight chunk headers as R code, put in your vimrc (e.g. .config/nvim/init.vim):
2014-07-10 22:01:47 +02:00
" let rmd_syn_hl_chunk = 1
2017-04-09 20:11:58 +02:00
"
" For highlighting pandoc extensions to markdown like citations and TeX and
" many other advanced features like folding of markdown sections, it is
" recommended to install the vim-pandoc filetype plugin as well as the
" vim-pandoc-syntax filetype plugin from https://github.com/vim-pandoc.
"
" TODO:
" - Provide highlighting for rmarkdown parameters in yaml header
2014-07-10 22:01:47 +02:00
2016-03-12 12:57:59 +01:00
if exists("b:current_syntax")
2014-07-10 22:01:47 +02:00
finish
endif
2017-04-09 20:11:58 +02:00
" load all of pandoc info, e.g. from
" https://github.com/vim-pandoc/vim-pandoc-syntax
2014-07-10 22:01:47 +02:00
runtime syntax/pandoc.vim
if exists("b:current_syntax")
let rmdIsPandoc = 1
unlet b:current_syntax
else
let rmdIsPandoc = 0
runtime syntax/markdown.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
2017-04-09 20:11:58 +02:00
" load all of the yaml syntax highlighting rules into @yaml
syntax include @yaml syntax/yaml.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
" highlight yaml block commonly used for front matter
syntax region rmdYamlBlock matchgroup=rmdYamlBlockDelim start="^---" matchgroup=rmdYamlBlockDelim end="^---" contains=@yaml keepend fold
2014-07-10 22:01:47 +02:00
endif
2017-04-09 20:11:58 +02:00
if !exists("g:rmd_syn_langs")
let g:rmd_syn_langs = ["r"]
2014-07-10 22:01:47 +02:00
else
2017-04-09 20:11:58 +02:00
let s:hasr = 0
for s:lng in g:rmd_syn_langs
if s:lng == "r"
let s:hasr = 1
endif
endfor
if s:hasr == 0
let g:rmd_syn_langs += ["r"]
endif
2014-07-10 22:01:47 +02:00
endif
2017-04-09 20:11:58 +02:00
for s:lng in g:rmd_syn_langs
exe 'syntax include @' . toupper(s:lng) . ' syntax/'. s:lng . '.vim'
if exists("b:current_syntax")
unlet b:current_syntax
endif
exe 'syntax region rmd' . toupper(s:lng) . 'Chunk start="^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" end="^[ \t]*```$" contains=@' . toupper(s:lng) . ',rmd' . toupper(s:lng) . 'ChunkDelim keepend fold'
if exists("g:rmd_syn_hl_chunk") && s:lng == "r"
" highlight R code inside chunk header
syntax match rmdRChunkDelim "^[ \t]*```{r" contained
syntax match rmdRChunkDelim "}$" contained
else
exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\).*}$" contained'
endif
exe 'syntax match rmd' . toupper(s:lng) . 'ChunkDelim "^[ \t]*```$" contained'
endfor
2014-07-10 22:01:47 +02:00
" also match and syntax highlight in-line R code
2017-04-09 20:11:58 +02:00
syntax region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend
" I was not able to highlight rmdrInline inside a pandocLaTeXCommand, although
" highlighting works within pandocLaTeXRegion and yamlFlowString.
syntax cluster texMathZoneGroup add=rmdrInline
2014-07-10 22:01:47 +02:00
" match slidify special marker
syntax match rmdSlidifySpecial "\*\*\*"
if rmdIsPandoc == 0
syn match rmdBlockQuote /^\s*>.*\n\(.*\n\@<!\n\)*/ skipnl
" LaTeX
syntax include @LaTeX syntax/tex.vim
if exists("b:current_syntax")
unlet b:current_syntax
endif
" Inline
syntax match rmdLaTeXInlDelim "\$"
syntax match rmdLaTeXInlDelim "\\\$"
syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" contains=@texMathZoneGroup
" Region
syntax match rmdLaTeXRegDelim "\$\$" contained
syntax match rmdLaTeXRegDelim "\$\$latex$" contained
2017-04-09 20:11:58 +02:00
syntax match rmdLaTeXSt "\\[a-zA-Z]\+"
syntax region rmdLaTeXRegion start="^\$\$" skip="\\\$" end="\$\$$" contains=@LaTeX,rmdLaTeXRegDelim keepend
syntax region rmdLaTeXRegion2 start="^\\\[" end="\\\]" contains=@LaTeX,rmdLaTeXRegDelim keepend
hi def link rmdBlockQuote Comment
2014-07-10 22:01:47 +02:00
hi def link rmdLaTeXSt Statement
hi def link rmdLaTeXInlDelim Special
hi def link rmdLaTeXRegDelim Special
endif
2017-04-09 20:11:58 +02:00
for s:lng in g:rmd_syn_langs
exe 'syn sync match rmd' . toupper(s:lng) . 'SyncChunk grouphere rmd' . toupper(s:lng) . 'Chunk /^[ \t]*``` *{\(' . s:lng . '\|r.*engine\s*=\s*["' . "']" . s:lng . "['" . '"]\)/'
endfor
2014-07-10 22:01:47 +02:00
2017-04-09 20:11:58 +02:00
hi def link rmdYamlBlockDelim Delim
for s:lng in g:rmd_syn_langs
exe 'hi def link rmd' . toupper(s:lng) . 'ChunkDelim Special'
endfor
hi def link rmdInlineDelim Special
2014-07-10 22:01:47 +02:00
hi def link rmdSlidifySpecial Special
let b:current_syntax = "rmd"
" vim: ts=8 sw=2