mardi 27 mai 2014

vim personnalisé la coloration syntaxique pour angularjs est feuilletée - Stack Overflow


I am doing angularjs development and have a bevy of HTML ng-templates included inside tags in my HTML, like so:


  <script type="text/ng-template" id="content_listing.html">
<div class="item_content">
<div class="horiz-nav-menu">
<h3> {{sectionName}} </h3>
<ul>
<li ng-repeat="navLink in navLinks"> <a href='#/{{navLink.Target}}' title='{{navLink.Tip}}'>{{navLink.Text}}</a> </li>
</ul>
</div>
</div>
</script>

It's highly annoying that my editor of choice, Vim, does not properly highlight the HTML because it is inside a script tag. As a result, I have created a custom syntax region for Vim and plopped it into a file after/syntax/html.vim which I have confirmed is getting processed when Vim starts up:


unlet b:current_syntax
syn include @HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/ng-template[^>]*>+ keepend end=+</script>+me=s-1 contains=@HTML,htmlScriptTag,@htmlPreproc

The problem is that the highlighting behavior is flaky (Vim 7.2). To make the highlighting work properly, I have to do things like scroll down so that the section with HTML scrolls off of the page and then scroll back, hit :e to reload the doc, etc. Also, even when the highlighting is displaying correctly, when I go to edit the HTML inside the tag the highlighting for that block turns off.


I am no expert on Vim syntax highlighting ... has anyone run into a similar thing? It looks to me like my region definition looks fine...



I am doing angularjs development and have a bevy of HTML ng-templates included inside tags in my HTML, like so:


  <script type="text/ng-template" id="content_listing.html">
<div class="item_content">
<div class="horiz-nav-menu">
<h3> {{sectionName}} </h3>
<ul>
<li ng-repeat="navLink in navLinks"> <a href='#/{{navLink.Target}}' title='{{navLink.Tip}}'>{{navLink.Text}}</a> </li>
</ul>
</div>
</div>
</script>

It's highly annoying that my editor of choice, Vim, does not properly highlight the HTML because it is inside a script tag. As a result, I have created a custom syntax region for Vim and plopped it into a file after/syntax/html.vim which I have confirmed is getting processed when Vim starts up:


unlet b:current_syntax
syn include @HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/ng-template[^>]*>+ keepend end=+</script>+me=s-1 contains=@HTML,htmlScriptTag,@htmlPreproc

The problem is that the highlighting behavior is flaky (Vim 7.2). To make the highlighting work properly, I have to do things like scroll down so that the section with HTML scrolls off of the page and then scroll back, hit :e to reload the doc, etc. Also, even when the highlighting is displaying correctly, when I go to edit the HTML inside the tag the highlighting for that block turns off.


I am no expert on Vim syntax highlighting ... has anyone run into a similar thing? It looks to me like my region definition looks fine...


0 commentaires:

Enregistrer un commentaire