Visual Studio - Markup syntax highlighting inside script[type:txt/html]

风格不统一 提交于 2019-12-08 16:55:23

问题


Does anyone know how or if its possible for Visual Studio 2008 to highlight the html syntax inside a script block of type "text/html" just like any other markup on an aspx/html page. I'm using the script block to house my templates for client-side templating.


回答1:


Two ideas come to mind, assuming the page itself is an ASP.NET page (and not a plain HTML page) :

  1. create a custom control which emits the script tag and end-tag. By using a custom control, you'll fool the IDE into not knowing about the script tag, and so you'll get the same syntax coloring as the enclosing page's HTML
  2. extract the script block's contents into a user control, and place an instance of that user control inside the script block. Since VS doesn't know that the user control's content will be inside a script block, you'll get syntax coloring.

I like the first option better, as it doesn't force you to split your page into multiple files.

If it's a plain HTML page, there's not many easy ways to do this. If "not easy" is OK, then you can alwasy create an HttpModule which replaces a placeholder tag in the source code (e.g. <myscript>) with, upon output to the user, a real text/html script tag.




回答2:


This is now a part of Visual Studio if you add Web Tools 2012.2:

http://vswebessentials.com/features/html

Be sure to use type="text/html" on the script tag.



来源:https://stackoverflow.com/questions/678801/visual-studio-markup-syntax-highlighting-inside-scripttypetxt-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!