2014-07-10 21:05:51 -07:00
|
|
|
" markdown Text with R statements
|
|
|
|
" Language: markdown with R code chunks
|
2016-06-20 07:37:19 -07:00
|
|
|
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
|
2021-05-02 09:45:09 -07:00
|
|
|
" Last Change: Wed Apr 21, 2021 09:55AM
|
2017-11-06 17:09:09 -07: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.
|
2018-10-29 15:38:41 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2016-06-20 07:37:19 -07:00
|
|
|
if exists("b:current_syntax")
|
2014-07-10 21:05:51 -07:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2021-05-02 09:45:09 -07:00
|
|
|
" Highlight the header of the chunks as R code
|
|
|
|
let g:rmd_syn_hl_chunk = get(g:, 'rmd_syn_hl_chunk', 0)
|
2018-10-29 15:38:41 -07:00
|
|
|
|
|
|
|
" Pandoc-syntax has more features, but it is slower.
|
2017-11-06 17:09:09 -07:00
|
|
|
" https://github.com/vim-pandoc/vim-pandoc-syntax
|
2018-10-29 15:38:41 -07:00
|
|
|
let g:pandoc#syntax#codeblocks#embeds#langs = get(g:, 'pandoc#syntax#codeblocks#embeds#langs', ['r'])
|
2014-07-10 21:05:51 -07:00
|
|
|
runtime syntax/pandoc.vim
|
|
|
|
if exists("b:current_syntax")
|
2021-05-02 09:45:09 -07:00
|
|
|
" Recognize inline R code
|
2018-10-29 15:38:41 -07:00
|
|
|
syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@R containedin=pandocLaTeXRegion,yamlFlowString keepend
|
|
|
|
hi def link rmdInlineDelim Delimiter
|
2021-05-02 09:45:09 -07:00
|
|
|
|
|
|
|
" Fix recognition of language chunks (code adapted from pandoc, 2021-03-28)
|
|
|
|
" Knitr requires braces in the block's header
|
|
|
|
for s:lng in g:pandoc#syntax#codeblocks#embeds#langs
|
|
|
|
let s:nm = matchstr(s:lng, '^[^=]*')
|
|
|
|
exe 'syn clear pandocDelimitedCodeBlock_'.s:nm
|
|
|
|
exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.s:nm
|
|
|
|
if g:rmd_syn_hl_chunk
|
|
|
|
exe 'syn region rmd'.s:nm.'ChunkDelim matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>" matchgroup=rmdCodeDelim end="}$" keepend containedin=rmd'.s:nm.'Chunk contains=@R'
|
|
|
|
exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=rmd'.s:nm.'ChunkDelim,@'.toupper(s:nm)
|
|
|
|
else
|
|
|
|
exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@'.toupper(s:nm)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
unlet s:lng
|
|
|
|
unlet s:nm
|
|
|
|
hi def link rmdInlineDelim Delimiter
|
|
|
|
hi def link rmdCodeDelim Delimiter
|
2018-10-29 15:38:41 -07:00
|
|
|
let b:current_syntax = "rmd"
|
|
|
|
finish
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
|
2021-05-02 09:45:09 -07:00
|
|
|
" Configuration if not using pandoc syntax:
|
|
|
|
" Add syntax highlighting of YAML header
|
|
|
|
let g:rmd_syn_hl_yaml = get(g:, 'rmd_syn_hl_yaml', 1)
|
|
|
|
" Add syntax highlighting of citation keys
|
|
|
|
let g:rmd_syn_hl_citations = get(g:, 'rmd_syn_hl_citations', 1)
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
" R chunks will not be highlighted by syntax/markdown because their headers
|
|
|
|
" follow a non standard pattern: "```{lang" instead of "^```lang".
|
|
|
|
" Make a copy of g:markdown_fenced_languages to highlight the chunks later:
|
|
|
|
if exists('g:markdown_fenced_languages')
|
|
|
|
if !exists('g:rmd_fenced_languages')
|
|
|
|
let g:rmd_fenced_languages = deepcopy(g:markdown_fenced_languages)
|
|
|
|
let g:markdown_fenced_languages = []
|
2017-11-06 17:09:09 -07:00
|
|
|
endif
|
2018-10-29 15:38:41 -07:00
|
|
|
else
|
|
|
|
let g:rmd_fenced_languages = ['r']
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
2017-11-06 17:09:09 -07:00
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
runtime syntax/markdown.vim
|
2017-11-06 17:09:09 -07:00
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
" Now highlight chunks:
|
|
|
|
for s:type in g:rmd_fenced_languages
|
|
|
|
if s:type =~ '='
|
2019-08-01 14:21:22 -07:00
|
|
|
let s:ft = substitute(s:type, '.*=', '', '')
|
|
|
|
let s:nm = substitute(s:type, '=.*', '', '')
|
2017-11-06 17:09:09 -07:00
|
|
|
else
|
2019-08-01 14:21:22 -07:00
|
|
|
let s:ft = s:type
|
2018-10-29 15:38:41 -07:00
|
|
|
let s:nm = s:type
|
2017-11-06 17:09:09 -07:00
|
|
|
endif
|
2018-10-29 15:38:41 -07:00
|
|
|
unlet! b:current_syntax
|
2019-08-01 14:21:22 -07:00
|
|
|
exe 'syn include @Rmd'.s:nm.' syntax/'.s:ft.'.vim'
|
2018-10-29 15:38:41 -07:00
|
|
|
if g:rmd_syn_hl_chunk
|
2021-05-02 09:45:09 -07:00
|
|
|
exe 'syn region rmd'.s:nm.'ChunkDelim matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>" matchgroup=rmdCodeDelim end="}$" keepend containedin=rmd'.s:nm.'Chunk contains=@Rmdr'
|
2018-10-29 15:38:41 -07:00
|
|
|
exe 'syn region rmd'.s:nm.'Chunk start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=rmd'.s:nm.'ChunkDelim,@Rmd'.s:nm
|
|
|
|
else
|
|
|
|
exe 'syn region rmd'.s:nm.'Chunk matchgroup=rmdCodeDelim start="^\s*```\s*{\s*'.s:nm.'\>.*$" matchgroup=rmdCodeDelim end="^\s*```\ze\s*$" keepend contains=@Rmd'.s:nm
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
2017-11-06 17:09:09 -07:00
|
|
|
endfor
|
2018-10-29 15:38:41 -07:00
|
|
|
unlet! s:type
|
|
|
|
|
2021-05-02 09:45:09 -07:00
|
|
|
" Recognize inline R code
|
|
|
|
syn region rmdrInline matchgroup=rmdInlineDelim start="`r " end="`" contains=@Rmdr keepend
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
hi def link rmdInlineDelim Delimiter
|
|
|
|
hi def link rmdCodeDelim Delimiter
|
|
|
|
|
|
|
|
" You don't need this if either your markdown/syntax.vim already highlights
|
|
|
|
" the YAML header or you are writing standard markdown
|
|
|
|
if g:rmd_syn_hl_yaml
|
|
|
|
" Minimum highlighting of yaml header
|
|
|
|
syn match rmdYamlFieldTtl /^\s*\zs\w*\ze:/ contained
|
|
|
|
syn match rmdYamlFieldTtl /^\s*-\s*\zs\w*\ze:/ contained
|
|
|
|
syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' contains=yamlEscape,rmdrInline contained
|
|
|
|
syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" contains=yamlSingleEscape,rmdrInline contained
|
|
|
|
syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
|
|
|
|
syn match yamlSingleEscape contained "''"
|
|
|
|
syn region pandocYAMLHeader matchgroup=rmdYamlBlockDelim start=/\%(\%^\|\_^\s*\n\)\@<=\_^-\{3}\ze\n.\+/ end=/^\([-.]\)\1\{2}$/ keepend contains=rmdYamlFieldTtl,yamlFlowString
|
|
|
|
hi def link rmdYamlBlockDelim Delimiter
|
|
|
|
hi def link rmdYamlFieldTtl Identifier
|
|
|
|
hi def link yamlFlowString String
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
" You don't need this if either your markdown/syntax.vim already highlights
|
|
|
|
" citations or you are writing standard markdown
|
|
|
|
if g:rmd_syn_hl_citations
|
|
|
|
" From vim-pandoc-syntax
|
|
|
|
" parenthetical citations
|
|
|
|
syn match pandocPCite /\^\@<!\[[^\[\]]\{-}-\{0,1}@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*.\{-}\]/ contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display
|
|
|
|
" in-text citations with location
|
|
|
|
syn match pandocICite /@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\s\[.\{-1,}\]/ contains=pandocCiteKey,@Spell display
|
|
|
|
" cite keys
|
|
|
|
syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:alnum:]à-öø-ÿÀ-ÖØ-ß_:.#$%&\-+?<>~\/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display
|
|
|
|
syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display
|
|
|
|
syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite
|
|
|
|
hi def link pandocPCite Operator
|
|
|
|
hi def link pandocICite Operator
|
|
|
|
hi def link pandocCiteKey Label
|
|
|
|
hi def link pandocCiteAnchor Operator
|
|
|
|
hi def link pandocCiteLocator Operator
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
let b:current_syntax = "rmd"
|
|
|
|
|
2018-10-29 15:38:41 -07:00
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" vim: ts=8 sw=2
|