CodeMirror variables mode
This is a CodeMirror mode that brings
syntax highlighting for variables in strings.
MIME types defined:
Options:
- base_token: string: token returned outside variables; default: 'string'
- escape_sequences: string, RegExp or null: possible escape sequences; default: '\\$'
- escape_token: string: token returned when spotting escaped characters; default: 'string'
-
variable_patterns: array of objects: possible variable patterns:
- prefix: string or RegExp: prefix used to spot variables; mandatory; example: '${'
- name: RegExp: pattern for acceptable variables names; mandatory; example: /\w+/
- suffix: string or RegExp: suffix matching the prefix; optional; example: '}'
- prefix_token: string: token returned for prefixes; optional; default: 'string strong'
- name_token: string: token returned for names; optional; default: 'variable-2'
- suffix_token: string: token returned for suffixes; optional; default: 'string strong'
- error_token: string: token returned for errors; optional; default: 'error'
Patterns must be ordered based on their prefix, e.g. '${' before '$'.
Direct use
By default, codemirror-mode-variables supports $-prefixed variables with optional braces, e.g. $foo or ${bar}:
Custom variable patterns
Braces:
Brackets:
Apache-style:
printf-style:
Use as nested mode
Below is a demonstration of how the variables mode can be used to highlight variables within other languages (here, nginx).