Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

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

    Help wanted · · · – – – · · ·
    alt img attribute html syntax
    3
    6
    840
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G. the H.
      G. the H. last edited by

      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?
      Thankyou.

      1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones last edited by

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

        G. the H. 2 Replies Last reply Reply Quote 3
        • andrecool-68
          andrecool-68 last edited by

          https://www.w3schools.com/tags/tag_img.asp

          1 Reply Last reply Reply Quote 0
          • G. the H.
            G. the H. @PeterJones last edited by G. the H.

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

            1 Reply Last reply Reply Quote 1
            • G. the H.
              G. the H. @PeterJones last edited by

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

              1 Reply Last reply Reply Quote 0
              • PeterJones
                PeterJones last edited by

                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 https://notepad-plus-plus.org/community/topic/16164/bug-javascript-multiline-character-not-understood-by-notepad/11 . It’d take some effort on your part to customize those to work with HTML+templating, but it’d be a starting point.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors