在记事本中显示不匹配的 html 标签++
有没有办法在 Notepad++ 中突出显示不匹配的 HTML 标签?
例如,如果我有以下 HTML...
<HTML>
<!--Server: <%=(java.net.InetAddress.getLocalHost()).getHostName()%>-->
<HEAD>
<TITLE>Vital Stats</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<SCRIPT SRC="vital_stats.js" TYPE="text/javascript"></SCRIPT>
<LINK REL="STYLESHEET" HREF="../main.css">
</HTML>
我希望以某种方式突出显示 标记,以表明它没有相应的
标签。
我还希望看到突出显示的任何没有相应开始标记的结束标记。
编辑
我已经了解 Notepad++ 的单击标签即可查看其相应标签的功能。我希望突出显示整个文档中不匹配的任何标签。即使我可以运行某种实用程序/插件,它会为我列出任何不匹配标签的行号和名称,这也会很有帮助。
Is there a way to highlight unmatched HTML tags in Notepad++?
For instance, if I had the following HTML...
<HTML>
<!--Server: <%=(java.net.InetAddress.getLocalHost()).getHostName()%>-->
<HEAD>
<TITLE>Vital Stats</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<SCRIPT SRC="vital_stats.js" TYPE="text/javascript"></SCRIPT>
<LINK REL="STYLESHEET" HREF="../main.css">
</HTML>
I would like the <HEAD>
tag to be highlighted in some way to indicate that it doesn't have a corresponding </HEAD>
tag.
I would also like to see any closing tags highlighted that don't have a corresponding opening tag.
EDIT
I already know about Notepad++'s feature of clicking a tag to see it's corresponding tag. I'm looking to highlight ANY tags that aren't matched in the ENTIRE document. Even if there's some sort of utility/plugin that I could run that would list for me the line number and name of any unmatched tags would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已请求某人开发一个插件,以便在 Notepad++ 中执行此操作,网址为 https://sourceforge.net/projects/notepad-plus/forums/forum/331753/topic/4936812
直到那发生这种情况,似乎在 Notepad++ 中无法完成此操作。
I've put in a request for someone to develop a plugin to do this in Notepad++ at https://sourceforge.net/projects/notepad-plus/forums/forum/331753/topic/4936812
Until that happens, it appears that this cannot be done in Notepad++.
它被突出显示。单击标签,您可以看到:
成对开闭的标签突出显示(紫色)。没有成对的标签不会突出显示。
边距上还有一条红线通向结束标记。如果没有结束标记,您会发现它不会通向任何地方。
下面是图像 - 第一个显示有效情况,第二个 - 无效。
(我的 Windows 上的 Notepad++ 版本是 5.9.5,选择的语言是 HTML)
It's highlighted. Click on the tag and you can see:
Tags which are pair open-close are highlighted (violet). Tags without pair aren't highlighted.
There is also red line on the margin which leads to the closing tag. If there is no closing tag you can see that it leads to nowhere.
Below are images - first shows valid situation, second - invalid.
(My Notepad++ version is 5.9.5 on Windows and choosed language is HTML)
对于我正在处理的大文件,找到额外/丢失的 div 的解决方法是将文件的副本重命名为 file.java。然后将“/div”替换为 },将“div”替换为 {。
For the big file I was working on, my workaround to find the extra/missing div was to rename a copy of the file to file.java. Then replace "/div" with } and "div" with {.
可能永远不会有这样的插件。原因是有效代码中的匹配标签(或块开始和结束)是明确的,但在无效环境中,例如如果缺少匹配标签,则没有“伙伴”(以及伙伴位置)的标签是不明确的。例如,如果您有这样的构造:
不可能说哪个 div 是未关闭的以及哪个代码真正属于哪个块。 npp 中的默认标签荧光笔只是假设最近关闭的标签属于最后打开的标签。但这只是一个疯狂的猜测,有助于手动检查该块是否正确,然后折叠它以检查下一个外部块,直到找到融合的块。因此,如果存在不匹配的标签,并且不假设可能是错误的“解决方案”,那么给出提示的唯一真正指标就是只计算打开和关闭的标签。这里有一个非 npp 解决方案,使用正则表达式。您可能为此使用 AnalysePlugin,或使用内置搜索/计数功能。
There probably won't be any plugins like this, probably ever. The reason is that matching tags (or block beginning and ending) in a valid code are unambiguous, but in an invalid environment, like if a matching tag is missing, then the tag without "partner" (and the partners position) is ambiguous. If you for example have this construct:
it's impossible to say, which of the divs is the one which is not closed and which code really belongs to which block. The default tag-highlighter in npp just assumes afaik that the most recent closed tag belongs to the last opened. But this is just a wild guess and helps to manually check, if the block is correct and than fold it to check the next outer block until you found the melded block. So the only real metric to give a hint if there is an unmatched tag that doesn't assume a probably wrong 'solution' would be to just count opened and closed tags. There is an non-npp solution for this here using regex. You might be using the AnalysePlugin for this, or use the build-in search/count functionality.