UI input boxes for action code fields can use syntax highlighting. This includes link actions (Links Inspector) and notes using the built-in 'Action' prototype.
Coloured highlighting assist in spotting simple coding mistakes:
- Double-quoted strings are red.
- Single-quoted strings are orange.
- Attribute references are purple.
- Operators appear in light blue. The function operator is coloured blue but function names are not.
- Comments appear in grey.
- The variable 'var' command (and optional var type) in green. Note that variable names, including function inputs and loop variables are not coloured.
- Conditional colour the 'if' light blue and the (optional) 'else' green.
- Unmatched parentheses, brackets and braces are highlighted in yellow.
Notes:
- Nesting unmatched quotes, i.e. 2 doubles around a single or vice versa, will (may) cause that expression within the overall action to be wrongly coloured. If correctly coded, this glitch (due to regex limitations) will not affect the functioning of the code.This does not affect
- Code syntax highlighting of Action Code cannot be set by the user (i.e. by using custom highlighters). However, applying the Action prototype will enable code colouring in any note using that prototype.
- Syntax highlighting will remove any pre-existing text colouring/highlighting. Font/font size are not affected.
- Syntax highlighting should not be used at the same time as highlighters. If both are used, the outcome will be unpredictable. As the highlighter feature is intended for marking up general text, its use is inappropriate for action code syntax marking.
Code notes and use of the action prototype
For large sections of code, it has long been practice to store such code in a note using the built-in 'Code' prototype. However, if the code being stored is action code, e.g. a long/complex Rule, then using the Action prototype may be a better choice.
If applying the 'Action' prototype to a pre-existing note and the $Text is not in already in a Monospaced font, it is a good idea to re-set the note font. Select the note and use menu Format ▸ Style ▸ Standard Font.
See also—notes linking to here: