HTML IMG Alt="<% ..." is an error?

  • Hi there, I’m new to Notepad++ and editing an HTML file. It contains an IMG tag with an Alt attribute like this:

    Alt="<%PlaceHolderName1% Image.>"

    I thought that in the value between the double quotes pretty much anything goes (and Firefox displays it as is) but the starting <% is being highlighted in yellow, and the entire rest of the file thereafter in cyan.
    What am I misunderstanding please?

  • Having a < inside a tag’s attribute is borderline-wrong in HTML: many browsers accept it, but some interpretations say it’s not valid. For real angle-brackets inside the attributes, it’s best to use the encoded &lt; and &gt;.

    However, many templating systems use that notation for placeholders. They replace those before the HTML is served to the browser, so it’s valid HTML by the time it gets rendered. But you are editing the source when it has that not-actually-HTML notation, so Notepad++ syntax highlighting is flagging this.

    (This is bordering on a ‘cookie baking’ question, but because you were trying to interpret why it showed up as “error” in Notepad++ highlighting, I thought it was worth answering.)

  • @PeterJones Hi, thanks for the response. I would have expected to use &lt; and &gt; in normal body content but didn’t think it was necessary within attribute values, and as Firefox was happy was puzzled as to why Notepad++ wasn’t.
    As it happens the HTML is intended as a template with the % delimiting placeholders for later search & replace, and the < and > intended to delimit the Alt text from normal content when viewing the template in browser.
    Interestingly Firefox also renders &lt; and &gt; in Alt text as < and > (I had half-expected that they might be shown as is (are?)). (One of these days I really must look into what W3C actually say about all this!).
    In the end I think I might go with [ and ] as delimiters in place of < and > that way Firefox, Notepad++, and readability are all happy!
    Thank you.

  • @PeterJones P.S. The thought occurs that there might be a case for an HTML Template syntax (as opposed to a normal HTML syntax), would this be a plugin? (Pardon me, slightly rhetorical pondering out loud here).

  • Yes, an alternate syntax would require a lexer plugin. (Or getting a new lexer integrated into Scintilla, and then getting NPP to update Scintilla to the latest-and-greatest, which hasn’t been a priority of the NPP developer.)

    Or, if you’re brave, I’ve got some links to some old posts by @Claudia-Frank , who had done some work on making custom lexers using PythonScript. Those links are in my last post in . It’d take some effort on your part to customize those to work with HTML+templating, but it’d be a starting point.