Zack Macomber
Zack Macomber

Reputation: 6905

Show unmatched html tags in 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.

Upvotes: 10

Views: 30387

Answers (4)

phx16
phx16

Reputation: 47

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:

<div>
     <div>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
          <div>
            Quisque auctor ligula vitae magna egestas
        </div>
     Sed vulputate nunc eu vehicula vestibulum. 
  </div>

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.

Upvotes: 0

user584583
user584583

Reputation: 1280

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 {.

Upvotes: 2

Zack Macomber
Zack Macomber

Reputation: 6905

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++.

Upvotes: 4

psur
psur

Reputation: 4519

It's highlighted. Click on the tag and you can see:

  1. Tags which are pair open-close are highlighted (violet). Tags without pair aren't highlighted.

  2. 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)

Valid situation

Invalid situation

Upvotes: 2

Related Questions