Community
    • Login

    Multi-language syntax-highlighting

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    feature request
    3 Posts 3 Posters 159 Views
    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.
    • BlastocystisB
      Blastocystis
      last edited by

      I’m sure this is a pretty obscure context …
      We have some XML files that contain embedded JavaScript. The files are part of a SmartCard authentication system. The main file consists of 740 lines of XML with 300+ lines of JavaScript plopped down in the middle of it. The XML portion of the file is properly highlighted. The JavaScript is contained in a CDATA section. Obviously it’s just text as far as the syntax highlighter is concerned.

      It would be really nice if there was a way to have NPP use the JavaScript highlighter on the JavaScript lines. Here’s a redacted version of how the JavaScript is embedded in the XML file:

      <Setting Name="identitytransformer1" Type="htf:map" xmlns="http://higgins.eclipse.org/sts/Configuration">
         <Setting Name="Provider" Type="xsd:string">com.some_combany.sso.idp.sts.ext.identitytransformer.x509.scripted.X509ScriptedMapperFactory</Setting>
         <Setting Name="X509CertificateToUserNameScript" Type="htf:jscriptexec">
            <![CDATA[
               // This section is JavaScript
               var USE_PIV = false ;
               var USE_CAC = true ;
               // ...etc...
           ]]>
         </Setting>
      </Setting>
      
      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Blastocystis
        last edited by

        @Blastocystis ,

        In HTML, it is able to apply javascript rendering to embedded javascript, because it’s in the universally-understood <script> tag. In generic XML, there is no single tag that always means “this is a script, so use javascript”, so there’s no unambiguous decision indicator that the lexer could use in XML: not all CDATA in XML is guaranteed to be javascript (and, in fact, is quite likely to not be), so it cannot just say “all CDATA”; not every XML-based file will use a Setting tag with the Type="htf:jscriptexec" attribute to indicate javascript. I don’t see how you could expect Notepad++ or any syntax highlighter to guess for you that it’s javascript, without highlighting non JS as JS for someone else, or not highlighting their JS which is indicated differently than in your circumstance.

        (Also, next time, please post in Help Wanted or General Discussion; the FAQ area where you tried to post is only used for presenting answers, not for asking questions.)

        mathlete2M 1 Reply Last reply Reply Quote 2
        • mathlete2M
          mathlete2 @PeterJones
          last edited by mathlete2

          @PeterJones said in Multi-language syntax-highlighting:

          not every XML-based file will use a Setting tag with the Type=“htf:jscriptexec” attribute to indicate javascript

          True, but to be fair, the jscript part of the Type attribute does give a sensible starting point for language-specific formatting rules. Whether or not the feature is easy to implement this way is another story…

          Given that @Blastocystis focused more on the CDATA section of the sample code, I’m guessing that (s)he was hoping for a more generic secondary language feature - one that gives users flexibility with the secondary language used. So, instead of applying a single language (the one selected in the current Language menu) to an entire document, have a Secondary Language menu that is designed to work on subsections of the document (to be marked in a specific manner). I could see this being equally complex to implement, though.

          Either way, perhaps it would make more sense to use/add a feature like Bookmarks to control where secondary language formatting is applied. In other words, give users the ability to directly choose which lines they want to format in another language by clicking on the margin.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors