You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enh(mathematica) Much improved highlighting for Wolfram (#2706)
Fix several issues and implement additional features for the Wolfram Language (Mathematica)
- Include an up-to-date list of built-in symbols in a separate `lib/mathematica.js` file. It's one keyword per line and more easy to maintain.
- Fix regexp to identify symbols/variables which requires special treatment and does not follow the common `IDENT_RE` matching.
- Replace generic `C_NUMBER_MODE` matching with dedicated regular expressions for all possible numbers in Mathematica.
- Include named-characters in the matching of symbols.
- Allow for dedicated styling of
- pattern-like forms, e.g. `par_String`
- slots of anonymous functions, e.g. `##3`
- message names, e.g. `myFunc::usage`
- braces, curly braces and brackets
- Introduce `classNameAliases` to map specific styles to general styles used by all themes. This allows for using built-in themes and writing sophisticated Mathematica themes.
These attributes are only valid at the language level (ie, they many only exist on the top-most language object and have no meaning if specified in children modes).
30
+
31
+
32
+
name
33
+
^^^^
34
+
35
+
- **type**: string
36
+
37
+
The canonical name of this language, ie "JavaScript", etc.
38
+
28
39
29
40
case_insensitive
30
41
^^^^^^^^^^^^^^^^
31
42
32
-
**type**: boolean
43
+
- **type**: boolean
33
44
34
45
Case insensitivity of language keywords and regexps. Used only on the top-level mode.
35
46
36
47
37
48
aliases
38
49
^^^^^^^
39
50
40
-
**type**: array
51
+
- **type**: array
41
52
42
53
A list of additional names (besides the canonical one given by the filename) that can be used to identify a language in HTML classes and in a call to :ref:`getLanguage <getLanguage>`.
43
54
44
55
56
+
classNameAliases
57
+
^^^^^^^^^^^^^^^^
58
+
59
+
- **type**: object
60
+
61
+
A mapping table of any custom class names your grammar uses and their supported equivalencies. Perhaps your language has a concept of "slots" that roughly correspond to variables in other languages. This allows you to write grammar code like:
62
+
63
+
::
64
+
65
+
{
66
+
classNameAliases: {
67
+
slot: "variable",
68
+
"message-name": "string"
69
+
},
70
+
contains: [
71
+
{
72
+
className: "slot",
73
+
begin: // ...
74
+
}
75
+
]
76
+
}
77
+
78
+
The final HTML output will render slots with the CSS class as ``hljs-variable``. This feature exists to make it easier for grammar maintainers to think in their own language when maintaining a grammar.
79
+
80
+
For a list of all supported class names please see the :doc:`CSS class reference
81
+
</css-classes-reference>`.
82
+
83
+
84
+
disableAutodetect
85
+
^^^^^^^^^^^^^^^^^
86
+
87
+
- **type**: boolean
88
+
89
+
Disables autodetection for this language.
90
+
91
+
92
+
93
+
Mode Attributes
94
+
---------------
95
+
96
+
45
97
className
46
98
^^^^^^^^^
47
99
48
-
**type**: identifier
100
+
- **type**: identifier
49
101
50
102
The name of the mode. It is used as a class name in HTML markup.
51
103
@@ -56,16 +108,16 @@ for one thing like string in single or double quotes.
56
108
begin
57
109
^^^^^
58
110
59
-
**type**: regexp
111
+
- **type**: regexp
60
112
61
113
Regular expression starting a mode. For example a single quote for strings or two forward slashes for C-style comments.
62
114
If absent, ``begin`` defaults to a regexp that matches anything, so the mode starts immediately.
63
115
64
116
65
117
on:begin
66
-
^^^^^^^^^^^
118
+
^^^^^^^^
67
119
68
-
**type**: callback (matchData, response)
120
+
- **type**: callback (matchData, response)
69
121
70
122
This callback is triggered the moment a begin match is detected. ``matchData`` includes the typical regex match data; the full match, match groups, etc. The ``response`` object is used to tell the parser how it should handle the match. It can be also used to temporarily store data.
71
123
@@ -78,7 +130,7 @@ For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``.
78
130
end
79
131
^^^
80
132
81
-
**type**: regexp
133
+
- **type**: regexp
82
134
83
135
Regular expression ending a mode. For example a single quote for strings or "$" (end of line) for one-line comments.
84
136
@@ -93,9 +145,9 @@ This is achieved with :ref:`endsWithParent <endsWithParent>` attribute.
93
145
94
146
95
147
on:end
96
-
^^^^^^^^^^^
148
+
^^^^^^
97
149
98
-
**type**: callback (matchData, response)
150
+
- **type**: callback (matchData, response)
99
151
100
152
This callback is triggered the moment an end match is detected. ``matchData`` includes the typical regex match data; the full match, match groups, etc. The ``response`` object is used to tell the parser how it should handle the match. It can also be used to retrieve data stored from a `begin` callback.
101
153
@@ -106,9 +158,9 @@ For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``.
106
158
107
159
108
160
beginKeywords
109
-
^^^^^^^^^^^^^^^^
161
+
^^^^^^^^^^^^^
110
162
111
-
**type**: string
163
+
- **type**: string
112
164
113
165
Used instead of ``begin`` for modes starting with keywords to avoid needless repetition:
114
166
@@ -140,7 +192,7 @@ Ex. ``class A { ... }`` would match while ``A.class == B.class`` would not.
140
192
endsWithParent
141
193
^^^^^^^^^^^^^^
142
194
143
-
**type**: boolean
195
+
- **type**: boolean
144
196
145
197
A flag showing that a mode ends when its parent ends.
146
198
@@ -169,7 +221,7 @@ This is when ``endsWithParent`` comes into play:
169
221
endsParent
170
222
^^^^^^^^^^^^^^
171
223
172
-
**type**: boolean
224
+
- **type**: boolean
173
225
174
226
Forces closing of the parent mode right after the current mode is closed.
175
227
@@ -215,7 +267,7 @@ endSameAsBegin (deprecated as of 10.1)
215
267
``END_SAME_AS_BEGIN`` mode or use the ``on:begin`` and ``on:end`` attributes to
216
268
build more complex paired matchers.
217
269
218
-
**type**: boolean
270
+
- **type**: boolean
219
271
220
272
Acts as ``end`` matching exactly the same string that was found by the
221
273
corresponding ``begin`` regexp.
@@ -244,7 +296,7 @@ and ``endSameAsBegin: true``.
244
296
lexemes (now keywords.$pattern)
245
297
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246
298
247
-
**type**: regexp
299
+
- **type**: regexp
248
300
249
301
A regular expression that extracts individual "words" from the code to compare
250
302
against :ref:`keywords <keywords>`. The default value is ``\w+`` which works for
@@ -260,7 +312,7 @@ constant that you repeat multiple times within different modes of your grammar.
260
312
keywords
261
313
^^^^^^^^
262
314
263
-
**type**: object
315
+
- **type**: object / string
264
316
265
317
Keyword definition comes in two forms:
266
318
@@ -273,7 +325,7 @@ For detailed explanation see :doc:`Language definition guide </language-guide>`.
273
325
illegal
274
326
^^^^^^^
275
327
276
-
**type**: regexp
328
+
- **type**: regexp
277
329
278
330
A regular expression that defines symbols illegal for the mode.
279
331
When the parser finds a match for illegal expression it immediately drops parsing the whole language altogether.
@@ -282,7 +334,7 @@ When the parser finds a match for illegal expression it immediately drops parsin
282
334
excludeBegin, excludeEnd
283
335
^^^^^^^^^^^^^^^^^^^^^^^^
284
336
285
-
**type**: boolean
337
+
- **type**: boolean
286
338
287
339
Exclude beginning or ending lexemes out of mode's generated markup. For example in CSS syntax a rule ends with a semicolon.
288
340
However visually it's better not to color it as the rule contents. Having ``excludeEnd: true`` forces a ``<span>`` element for the rule to close before the semicolon.
@@ -291,7 +343,7 @@ However visually it's better not to color it as the rule contents. Having ``excl
291
343
returnBegin
292
344
^^^^^^^^^^^
293
345
294
-
**type**: boolean
346
+
- **type**: boolean
295
347
296
348
Returns just found beginning lexeme back into parser. This is used when beginning of a sub-mode is a complex expression
297
349
that should not only be found within a parent mode but also parsed according to the rules of a sub-mode.
@@ -302,7 +354,7 @@ Since the parser is effectively goes back it's quite possible to create a infini
302
354
returnEnd
303
355
^^^^^^^^^
304
356
305
-
**type**: boolean
357
+
- **type**: boolean
306
358
307
359
Returns just found ending lexeme back into parser. This is used for example to parse JavaScript embedded into HTML.
308
360
A JavaScript block ends with the HTML closing tag ``</script>`` that cannot be parsed with JavaScript rules.
@@ -314,15 +366,15 @@ Since the parser is effectively goes back it's quite possible to create a infini
314
366
contains
315
367
^^^^^^^^
316
368
317
-
**type**: array
369
+
- **type**: array
318
370
319
371
The list of sub-modes that can be found inside the mode. For detailed explanation see :doc:`Language definition guide </language-guide>`.
320
372
321
373
322
374
starts
323
375
^^^^^^
324
376
325
-
**type**: identifier
377
+
- **type**: identifier
326
378
327
379
The name of the mode that will start right after the current mode ends. The new mode won't be contained within the current one.
328
380
@@ -333,7 +385,7 @@ Tags ``<script>`` and ``<style>`` start sub-modes that use another language defi
333
385
variants
334
386
^^^^^^^^
335
387
336
-
**type**: array
388
+
- **type**: array
337
389
338
390
Modification to the main definitions of the mode, effectively expanding it into several similar modes
339
391
each having all the attributes from the main definition augmented or overridden by the variants::
@@ -366,10 +418,11 @@ Further info: https://github.com/highlightjs/highlight.js/issues/826
366
418
367
419
.. _subLanguage:
368
420
421
+
369
422
subLanguage
370
423
^^^^^^^^^^^
371
424
372
-
**type**: string or array
425
+
- **type**: string or array
373
426
374
427
Highlights the entire contents of the mode with another language.
375
428
@@ -381,10 +434,11 @@ The value of the attribute controls which language or languages will be used for
381
434
* empty array: auto detection with all the languages available
382
435
* array of language names: auto detection constrained to the specified set
383
436
437
+
384
438
skip
385
439
^^^^
386
440
387
-
**type**: boolean
441
+
- **type**: boolean
388
442
389
443
Skips any markup processing for the mode ensuring that it remains a part of its
390
444
parent buffer along with the starting and the ending lexemes. This works in
@@ -407,10 +461,3 @@ handle pairs of ``/* .. */`` to correctly find the ending ``?>``::
407
461
Without ``skip: true`` every comment would cause the parser to drop out back
0 commit comments