Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight <script> and <style> tags better. #88

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion syntax/vue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@ function! s:register_language(language, tag, ...)
endif
endfunction

if !exists("g:vue_disable_pre_processors") || !g:vue_disable_pre_processors
function! s:register_tag(language, tag)
if s:syntax_available(a:language)
execute 'syntax include @' . a:language . ' syntax/' . a:language . '.vim'
unlet! b:current_syntax
execute 'syntax region vue_' . a:language
\ 'keepend'
\ 'start=/<' . a:tag . '>/'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lacks the \_[^>]* from s:register_language(), it's for maintaining the highlighting when the tag contains other, unrelated attributes.

However I think the s:register_language() function can be reused to highlight <script> and <style> as well, since it's not that different. I can have a further look at this too when I find some time

\ 'end="</' . a:tag . '>"me=s-1'
\ 'contains=@' . a:language . ',vueSurroundingTag'
\ 'fold'
endif
endfunction

if !exists('g:vue_disable_pre_processors') || !g:vue_disable_pre_processors
call s:register_tag('javascript', 'script')
call s:register_tag('css', 'style')
call s:register_language('pug', 'template', s:attr('lang', '\%(pug\|jade\)'))
call s:register_language('slm', 'template')
call s:register_language('handlebars', 'template')
call s:register_language('haml', 'template')
call s:register_language('typescript', 'script', '\%(lang=\("\|''\)[^\1]*\(ts\|typescript\)[^\1]*\1\|ts\)')
call s:register_language('coffee', 'script')
call s:register_language('javascript', 'script')
call s:register_language('css', 'style')
call s:register_language('stylus', 'style')
call s:register_language('sass', 'style')
call s:register_language('scss', 'style')
Expand Down
10 changes: 7 additions & 3 deletions test/test_syntax.vader
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ Execute (Syntax doesn't stop at the first closing template tag):
#
# JavaScript
#
Given vue:
Given vue (Javascript region without lang attribute):
<script>
//
var foo = 'bar';
</script>

Execute:
AssertEqual 'javaScriptLineComment', SyntaxAt(2, 1)
AssertEqual 'htmlScriptTag', SyntaxAt(1, 1)
AssertEqual 'vueSurroundingTag', SyntaxAt(1, 1)
AssertEqual 'javaScriptIdentifier', SyntaxAt(3, 1)


Given vue (Script tag with misc. attributes and newline):
Expand All @@ -55,11 +57,13 @@ Execute:
Given vue (CSS region without lang attribute):
<style>
/**/
body { }
</style>

Execute:
AssertEqual 'cssComment', SyntaxAt(2, 1)
AssertEqual 'htmlTag', SyntaxAt(1, 1)
AssertEqual 'vueSurroundingTag', SyntaxAt(1, 1)
AssertEqual 'cssTagName', SyntaxAt(3, 1)

#
# Pug
Expand Down