Visual Studio-脚本内的标记语法突出显示[type:txt/html] [英] Visual Studio - Markup syntax highlighting inside script[type:txt/html]

查看:73
本文介绍了Visual Studio-脚本内的标记语法突出显示[type:txt/html]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道Visual Studio 2008如何或是否有可能像在aspx/html页面上的任何其他标记一样突出显示"text/html"类型的脚本块中的html语法.我正在使用脚本块来存放我的模板以进行客户端模板制作.

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.

推荐答案

有两个想法,假设页面本身是ASP.NET页面(而不是普通的HTML页面):

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

  1. 创建一个自定义控件,该控件发出script标签和结束标签.通过使用自定义控件,您将使IDE愚弄不知道script标记,因此将获得与封闭页面的HTML相同的语法颜色
  2. 将脚本块的内容提取到用户控件中,然后将该用户控件的实例放置在脚本块中.由于VS不知道用户控件的内容将在脚本块中,因此您将获得语法颜色.
  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.

如果它是纯HTML页面,则没有很多简单的方法可以做到这一点.如果不容易"是可以的,则可以通过创建一个 HttpModule ,它会在输出给用户后,用真实的text/html脚本标签替换源代码中的占位符标签(例如<myscript>).

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.

这篇关于Visual Studio-脚本内的标记语法突出显示[type:txt/html]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆