From b69fbad1af47d632fd5f6d289afb8429c5e8618d Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Mon, 4 Mar 2019 11:33:35 +0100 Subject: Add mdx support, closes #342 --- README.md | 3 ++- after/syntax/mdx.vim | 45 +++++++++++++++++++++++++++++++++++++++++++++ build | 3 ++- config.vim | 3 +++ ftdetect/polyglot.vim | 3 +++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 after/syntax/mdx.vim diff --git a/README.md b/README.md index 2d30b105..0a86d689 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 100+ times faster** than the 127 packages it consists of. +- It **installs and updates 100+ times faster** than the 128 packages it consists of. - Solid syntax and indentation support (other features skipped). Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). - No support for esoteric languages, only most popular ones (modern too, like `slim`). @@ -109,6 +109,7 @@ If you need full functionality of any plugin, please use it directly with your p - [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin) - [markdown](https://github.com/plasticboy/vim-markdown) (syntax, indent) - [mathematica](https://github.com/rsmenon/vim-mathematica) (syntax, ftplugin) +- [mdx](https://github.com/jxnblk/vim-mdx-js) (syntax) - [meson](https://github.com/mesonbuild/meson) (syntax, indent, ftplugin) - [moonscript](https://github.com/leafo/moonscript-vim) (syntax, indent, ftplugin) - [nginx](https://github.com/chr4/nginx.vim) (syntax, indent, ftplugin) diff --git a/after/syntax/mdx.vim b/after/syntax/mdx.vim new file mode 100644 index 00000000..46f73946 --- /dev/null +++ b/after/syntax/mdx.vim @@ -0,0 +1,45 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'mdx') != -1 + finish +endif + + +" based on mxw/vim-jsx + +if exists('b:current_syntax') + let s:current_syntax=b:current_syntax + unlet b:current_syntax +endif +syn include @XMLSyntax syntax/xml.vim +if exists('s:current_syntax') + let b:current_syntax=s:current_syntax +endif + +" JSX attributes should color as JS. Note the trivial end pattern; we let +" jsBlock take care of ending the region. +syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock + +" JSX child blocks behave just like JSX attributes, except that (a) they are +" syntactically distinct, and (b) they need the syn-extend argument, or else +" nested XML end-tag patterns may end the outer jsxRegion. +syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock + \ extend + +" Highlight JSX regions as XML; recursively match. +" +" Note that we prohibit JSX tags from having a < or word character immediately +" preceding it, to avoid conflicts with, respectively, the left shift operator +" and generic Flow type annotations (http://flowtype.org/). +syn region jsxRegion + \ contains=@Spell,@XMLSyntax,jsxRegion,jsxChild,jsBlock,javascriptBlock + \ start=+\%(<\|\w\)\@+ + \ end=++ + \ end=+/>+ + \ keepend + \ extend + +" Add jsxRegion to the lowest-level JS syntax cluster. +syn cluster jsExpression add=jsxRegion + +" Allow jsxRegion to contain reserved words. +syn cluster javascriptNoReserved add=jsxRegion diff --git a/build b/build index 387dd2e3..c661e0b7 100755 --- a/build +++ b/build @@ -63,7 +63,7 @@ extract() { output "${subdirs##, })"$'\n' - if (echo "julia coffee-script elixir fish git plantuml scala swift jinja" | grep -qF "$name"); then + if (echo "julia coffee-script elixir fish git plantuml scala swift jinja mdx" | grep -qF "$name"); then echo "Skipping ftdetect installation of $name" >&2 continue fi @@ -217,6 +217,7 @@ PACKS=" mako:sophacles/vim-bundle-mako markdown:plasticboy/vim-markdown:_SYNTAX mathematica:rsmenon/vim-mathematica + mdx:jxnblk/vim-mdx-js meson:mesonbuild/meson:_ALL:/data/syntax-highlighting/vim/ moonscript:leafo/moonscript-vim nginx:chr4/nginx.vim diff --git a/config.vim b/config.vim index b48dc5a9..2b36a56a 100644 --- a/config.vim +++ b/config.vim @@ -71,6 +71,9 @@ augroup filetypedetect "jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja + + "mdx + autocmd BufNewFile,BufRead *.mdx set filetype=markdown.mdx augroup END " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 3316c3b7..e78ac9dc 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -71,6 +71,9 @@ augroup filetypedetect "jinja autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja + + "mdx + autocmd BufNewFile,BufRead *.mdx set filetype=markdown.mdx augroup END " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 -- cgit v1.2.3