juvenn / mustache.vim

Vim mode for mustache and handlebars (Deprecated)
github.com/mustache/vim-mode
125 stars 14 forks source link

does script tag templates really work? #5

Closed PEZ closed 10 years ago

PEZ commented 12 years ago

I don't get mustache code inside <script type="text/mustache"... syntax colored. The example.mustache file highlights correctly.

amadeus commented 10 years ago

Any update on support for this?

bruno- commented 10 years ago

Hi guys, I have looked into this a bit.

TL;DR In order for this to work properly html.vim syntax file should be updated. This can't be done through mustache.vim plugin. There is a hack to make it work. Put this in your .vimrc file:

if has("autocmd")
  au FileType html setlocal syntax=mustache
endif

Full explanation: The reason why <script type="text/mustache" does not highlight correctly is because you are (most likely) working with plain html files (files with extension .html ie. index.html). If that is the case, then mustache.vim plugin does not even get loaded and mustache syntax highlighting is naturally not working.

A slight off-topic to clarify: vim determines filetype (and applies syntax highlighting) by looking at file extension. If file extension is something of the following: *.mustache,*.handlebars,*.hbs,*.hogan,*.hulk,*.hjs, then proper mustache syntax highlighting will be applied. If file extension is .html,.htm - in that case vim applies only basic html syntax highlighting.

I hope that explains why script tag with mustache type attribute does not "work correctly".

It also indicates another thing - if we want it to work correctly, we would have to extend plain html syntax file that comes with vim (mustache.vim plugin cannot influence html syntax files). Here is the guy that maintains html.vim syntax file, and here is the source of the syntax file itself.

I don't even know if any kind of pull request is accepted for html.vim, how the process goes, would the maintainer allow that ("text/mustache" does not look like proper mime type - officially supported as html script type attribute value). Long story short, I think this option is off.

So with proper options off, here is the hack how to get the desired result. In your .vimrc file put the following:

if has("autocmd")
  au FileType html setlocal syntax=mustache
endif

The above command will apply mustache syntax highlighting for all html files. I've tested and this works just fine. Please let me know if it works for you.

bruno- commented 10 years ago

I think we gave it enough time for discussion. Closing the issue based on detailed explanation in previous post.