Style configuration not working

  • The word “getElementById” is defined as a keyword for JavaScript languaje (default configuration).
    But in my JavaScript files “getElementById” does not apply the style configuration if it is preceded by any word and a dot or followed by a dot.


    ¿How can this be solved?

    Thanks a lot!

  • @Mikel-Cortés ,

    Based on what you showed, you either have a really old Notepad++ (sharing ? menu, Debug Info would be helpful); or you used to have a really old Notepad++ and upgraded, but the styler and theme config files as well as langs.xml weren’t updated to match the newest version; or you have a fresh install of a recent version, but the Mikel theme (which doesn’t, AFAIK, ship with Notepad++) maybe hasn’t been updated to match the modern lexer libraries.

    I say this because your Language selector only shows JavaScript, it does not list both JavaScript and JavaScript (embeded), because they are implemented separately now. The “embeded” highlighting is used when you have an HTML file with a <script> tag. The non-embeded is when you have a .js file or similar, or otherwise set Language > J > JavaScript. Also, the modern langs.xml config file doesn’t have getElementById in the default list of keywords for either (which is odd, IMO).

    In my v7.9.2, if I add getElementById to the User-defined keywords list for the JavaScript > WINDOW INSTRUCTION, and have set Language > J > JavaScript, then it highlights as expected:
    If I set Language > H > HTML with adding getElementById to the User-defined keywords for JavaScript (embedded) > KEYWORD, and wrap the code in a <script> tag, then I get similar to what you showed:

    So it looks like the embedded-JavaScript-in-HTML parser doesn’t handle all the normal situations for keywords; I would say that’s a bug you should report, but the bug would be in the HTML+embedded lexer that’s comes from the Scintilla library, so you’d have to report the bug to Scintilla first (and they seem to be focused on things other than the lexers), then they’d have to implement it and release it, then you’d have to ask Notepad++ developers to update the Scintilla component in Notepad++, and they’d have to decided to do it (which rarely happens – usually years between such upgrades, because it’s a lot of work on their part), and then you’d have to wait for them to do it, and… by then, you might not be programming in JavaScript anymore because AI’s have taken over. ;-)

    Anyway, as a workaround, you can add extra highlighting to a builtin lexer (like the HTML lexer) or to a User Defined Language (UDL) using regexes via the script that @Ekopalypse shares in his github repo, which requires the PythonScript plugin. With that, you could add a regex for JavaScript (embedded) which will highlight getElementById (and similar) in the contexts that are missing from that lexer’s repertoire.

  • Thanks for your reply @PeterJones

    I have reinstalled Notepad ++ last version and now “JavaScript (embedded)” appears on my list; but as you have said the issue continues.

    It seems that “.” is not considered as a word separator to identify keywords to apply the style configuration.


Log in to reply