Notepad2e icon indicating copy to clipboard operation
Notepad2e copied to clipboard

Highlight JS templates

Open ProgerXP opened this issue 6 years ago • 4 comments
trafficstars

JavaScript has a relatively new syntax for strings:

let str = `line1
${eval} line2
${`nested ${1+1}`} line3`

I.e. like 'str' and "str" but multiline and allowing expression interpolation via ${...} (and nested templates via this construct).

Need to add highlighting for such strings. However, Scintilla probably has this already, maybe we should just update our schemes? Also see #180.

ProgerXP avatar Dec 26 '18 09:12 ProgerXP

Fixed.

cshnik avatar Jan 10 '19 20:01 cshnik

Was this implemented from scratch or it's using Scintilla rules? Because highlighting rules are not correct:

  • backslash escapes are not correctly handled: foo backslash backtick bar is a single template because backtick is escaped but it's highlighted as foo as a template and bar as a code
  • nested templates are not recognized - backtick before abc doesn't close the string, it's start of another string since anything inside ${ } is code, not part of the template nested

ProgerXP avatar Jan 11 '19 19:01 ProgerXP

Here are the points:

  1. Scintilla's lexers are used when applying predefined highlighting rules.
  2. CPP lexer is used for Javascript scheme.
  3. Recent version of Scintilla still has no correct support of "JS template strings" feature: https://sourceforge.net/p/scintilla/feature-requests/1112/

cshnik avatar Jan 14 '19 17:01 cshnik

I see. Let's leave the rule enabled just in case later Scintilla devs get around to implementing proper template highlighting.

ProgerXP avatar Jan 14 '19 18:01 ProgerXP