This repository was archived by the owner on Apr 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhighlight.ts
More file actions
672 lines (630 loc) · 25.8 KB
/
Copy pathhighlight.ts
File metadata and controls
672 lines (630 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
import {Tree, NodeType, NodeProp, TreeCursor} from "@lezer/common"
let nextTagID = 0
/// Highlighting tags are markers that denote a highlighting category.
/// They are [associated](#highlight.styleTags) with parts of a syntax
/// tree by a language mode, and then mapped to an actual CSS style by
/// a [highlighter](#highlight.Highlighter).
///
/// Because syntax tree node types and highlight styles have to be
/// able to talk the same language, CodeMirror uses a mostly _closed_
/// [vocabulary](#highlight.tags) of syntax tags (as opposed to
/// traditional open string-based systems, which make it hard for
/// highlighting themes to cover all the tokens produced by the
/// various languages).
///
/// It _is_ possible to [define](#highlight.Tag^define) your own
/// highlighting tags for system-internal use (where you control both
/// the language package and the highlighter), but such tags will not
/// be picked up by regular highlighters (though you can derive them
/// from standard tags to allow highlighters to fall back to those).
export class Tag {
/// @internal
id = nextTagID++
/// @internal
constructor(
/// The set of this tag and all its parent tags, starting with
/// this one itself and sorted in order of decreasing specificity.
readonly set: Tag[],
/// The base unmodified tag that this one is based on, if it's
/// modified @internal
readonly base: Tag | null,
/// The modifiers applied to this.base @internal
readonly modified: readonly Modifier[]
) {}
/// Define a new tag. If `parent` is given, the tag is treated as a
/// sub-tag of that parent, and
/// [highlighters](#highlight.tagHighlighter) that don't mention
/// this tag will try to fall back to the parent tag (or grandparent
/// tag, etc).
static define(parent?: Tag): Tag {
if (parent?.base) throw new Error("Can not derive from a modified tag")
let tag = new Tag([], null, [])
tag.set.push(tag)
if (parent) for (let t of parent.set) tag.set.push(t)
return tag
}
/// Define a tag _modifier_, which is a function that, given a tag,
/// will return a tag that is a subtag of the original. Applying the
/// same modifier to a twice tag will return the same value (`m1(t1)
/// == m1(t1)`) and applying multiple modifiers will, regardless or
/// order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
///
/// When multiple modifiers are applied to a given base tag, each
/// smaller set of modifiers is registered as a parent, so that for
/// example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
/// `m1(m3(t1)`, and so on.
static defineModifier(): (tag: Tag) => Tag {
let mod = new Modifier
return (tag: Tag) => {
if (tag.modified.indexOf(mod) > -1) return tag
return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id))
}
}
}
let nextModifierID = 0
class Modifier {
instances: Tag[] = []
id = nextModifierID++
static get(base: Tag, mods: readonly Modifier[]) {
if (!mods.length) return base
let exists = mods[0].instances.find(t => t.base == base && sameArray(mods, t.modified))
if (exists) return exists
let set: Tag[] = [], tag = new Tag(set, base, mods)
for (let m of mods) m.instances.push(tag)
let configs = permute(mods)
for (let parent of base.set) for (let config of configs)
set.push(Modifier.get(parent, config))
return tag
}
}
function sameArray<T>(a: readonly T[], b: readonly T[]) {
return a.length == b.length && a.every((x, i) => x == b[i])
}
function permute<T>(array: readonly T[]): (readonly T[])[] {
let result = [array]
for (let i = 0; i < array.length; i++) {
for (let a of permute(array.slice(0, i).concat(array.slice(i + 1)))) result.push(a)
}
return result
}
/// This function is used to add a set of tags to a language syntax
/// via [`NodeSet.extend`](#common.NodeSet.extend) or
/// [`LRParser.configure`](#lr.LRParser.configure).
///
/// The argument object maps node selectors to [highlighting
/// tags](#highlight.Tag) or arrays of tags.
///
/// Node selectors may hold one or more (space-separated) node paths.
/// Such a path can be a [node name](#common.NodeType.name), or
/// multiple node names (or `*` wildcards) separated by slash
/// characters, as in `"Block/Declaration/VariableName"`. Such a path
/// matches the final node but only if its direct parent nodes are the
/// other nodes mentioned. A `*` in such a path matches any parent,
/// but only a single level—wildcards that match multiple parents
/// aren't supported, both for efficiency reasons and because Lezer
/// trees make it rather hard to reason about what they would match.)
///
/// A path can be ended with `/...` to indicate that the tag assigned
/// to the node should also apply to all child nodes, even if they
/// match their own style (by default, only the innermost style is
/// used).
///
/// When a path ends in `!`, as in `Attribute!`, no further matching
/// happens for the node's child nodes, and the entire node gets the
/// given style.
///
/// In this notation, node names that contain `/`, `!`, `*`, or `...`
/// must be quoted as JSON strings.
///
/// For example:
///
/// ```javascript
/// parser.withProps(
/// styleTags({
/// // Style Number and BigNumber nodes
/// "Number BigNumber": tags.number,
/// // Style Escape nodes whose parent is String
/// "String/Escape": tags.escape,
/// // Style anything inside Attributes nodes
/// "Attributes!": tags.meta,
/// // Add a style to all content inside Italic nodes
/// "Italic/...": tags.emphasis,
/// // Style InvalidString nodes as both `string` and `invalid`
/// "InvalidString": [tags.string, tags.invalid],
/// // Style the node named "/" as punctuation
/// '"/"': tags.punctuation
/// })
/// )
/// ```
export function styleTags(spec: {[selector: string]: Tag | readonly Tag[]}) {
let byName: {[name: string]: Rule} = Object.create(null)
for (let prop in spec) {
let tags = spec[prop]
if (!Array.isArray(tags)) tags = [tags as Tag]
for (let part of prop.split(" ")) if (part) {
let pieces: string[] = [], mode = Mode.Normal, rest = part
for (let pos = 0;;) {
if (rest == "..." && pos > 0 && pos + 3 == part.length) { mode = Mode.Inherit; break }
let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest)
if (!m) throw new RangeError("Invalid path: " + part)
pieces.push(m[0] == "*" ? "" : m[0][0] == '"' ? JSON.parse(m[0]) : m[0])
pos += m[0].length
if (pos == part.length) break
let next = part[pos++]
if (pos == part.length && next == "!") { mode = Mode.Opaque; break }
if (next != "/") throw new RangeError("Invalid path: " + part)
rest = part.slice(pos)
}
let last = pieces.length - 1, inner = pieces[last]
if (!inner) throw new RangeError("Invalid path: " + part)
let rule = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null)
byName[inner] = rule.sort(byName[inner])
}
}
return ruleNodeProp.add(byName)
}
const ruleNodeProp = new NodeProp<Rule>()
const enum Mode { Opaque, Inherit, Normal }
class Rule {
constructor(readonly tags: readonly Tag[],
readonly mode: Mode,
readonly context: readonly string[] | null,
public next?: Rule) {}
sort(other: Rule | undefined) {
if (!other || other.depth < this.depth) {
this.next = other
return this
}
other.next = this.sort(other.next)
return other
}
get depth() { return this.context ? this.context.length : 0 }
}
/// A highlighter defines a mapping from highlighting tags and
/// language scopes to CSS class names. They are usually defined via
/// [`tagHighlighter`](#highlight.tagHighlighter) or some wrapper
/// around that, but it is also possible to implement them from
/// scratch.
export interface Highlighter {
/// Get the set of classes that should be applied to the given set
/// of highlighting tags, or null if this highlighter doesn't assign
/// a style to the tags.
style(tags: readonly Tag[]): string | null
/// When given, the highlighter will only be applied to trees on
/// whose [top](#common.NodeType.isTop) node this predicate returns
/// true.
scope?(node: NodeType): boolean
}
/// Define a [highlighter](#highlight.Highlighter) from an array of
/// tag/class pairs. Classes associated with more specific tags will
/// take precedence.
export function tagHighlighter(tags: readonly {tag: Tag | readonly Tag[], class: string}[], options?: {
/// By default, highlighters apply to the entire document. You can
/// scope them to a single language by providing the tree's
/// [top](#common.NodeType.isTop) node type here.
scope?: (node: NodeType) => boolean,
/// Add a style to _all_ tokens. Probably only useful in combination
/// with `scope`.
all?: string
}): Highlighter {
let map: {[tagID: number]: string | null} = Object.create(null)
for (let style of tags) {
if (!Array.isArray(style.tag)) map[(style.tag as Tag).id] = style.class
else for (let tag of style.tag) map[tag.id] = style.class
}
let {scope, all = null} = options || {}
return {
style: (tags) => {
let cls = all
for (let tag of tags) {
for (let sub of tag.set) {
let tagClass = map[sub.id]
if (tagClass) {
cls = cls ? cls + " " + tagClass : tagClass
break
}
}
}
return cls
},
scope: scope
}
}
export function highlightTags(highlighters: readonly Highlighter[], tags: readonly Tag[]): string | null {
let result = null
for (let highlighter of highlighters) {
let value = highlighter.style(tags)
if (value) result = result ? result + " " + value : value
}
return result
}
/// Highlight the given [tree](#common.Tree) with the given
/// [highlighter](#highlight.Highlighter).
export function highlightTree(
tree: Tree,
highlighter: Highlighter | readonly Highlighter[],
/// Assign styling to a region of the text. Will be called, in order
/// of position, for any ranges where more than zero classes apply.
/// `classes` is a space separated string of CSS classes.
putStyle: (from: number, to: number, classes: string) => void,
/// The start of the range to highlight.
from = 0,
/// The end of the range.
to = tree.length,
) {
let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle)
builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters)
builder.flush(to)
}
class HighlightBuilder {
class = ""
constructor(
public at: number,
readonly highlighters: readonly Highlighter[],
readonly span: (from: number, to: number, cls: string) => void
) {}
startSpan(at: number, cls: string) {
if (cls != this.class) {
this.flush(at)
if (at > this.at) this.at = at
this.class = cls
}
}
flush(to: number) {
if (to > this.at && this.class) this.span(this.at, to, this.class)
}
highlightRange(cursor: TreeCursor, from: number, to: number, inheritedClass: string, highlighters: readonly Highlighter[]) {
let {type, from: start, to: end} = cursor
if (start >= to || end <= from) return
if (type.isTop) highlighters = this.highlighters.filter(h => !h.scope || h.scope(type))
let cls = inheritedClass
let rule = type.prop(ruleNodeProp), opaque = false
while (rule) {
if (!rule.context || cursor.matchContext(rule.context)) {
let tagCls = highlightTags(highlighters, rule.tags)
if (tagCls) {
if (cls) cls += " "
cls += tagCls
if (rule.mode == Mode.Inherit) inheritedClass += (inheritedClass ? " " : "") + tagCls
else if (rule.mode == Mode.Opaque) opaque = true
}
break
}
rule = rule.next
}
this.startSpan(cursor.from, cls)
if (opaque) return
let mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted)
if (mounted && mounted.overlay) {
let inner = cursor.node.enter(mounted.overlay[0].from + start, 1)!
let innerHighlighters = this.highlighters.filter(h => !h.scope || h.scope(mounted!.tree.type))
let hasChild = cursor.firstChild()
for (let i = 0, pos = start;; i++) {
let next = i < mounted.overlay.length ? mounted.overlay[i] : null
let nextPos = next ? next.from + start : end
let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to, nextPos)
if (rangeFrom < rangeTo && hasChild) {
while (cursor.from < rangeTo) {
this.highlightRange(cursor, rangeFrom, rangeTo, inheritedClass, highlighters)
this.startSpan(Math.min(to, cursor.to), cls)
if (cursor.to >= nextPos || !cursor.nextSibling()) break
}
}
if (!next || nextPos > to) break
pos = next.to + start
if (pos > from) {
this.highlightRange(inner.cursor(), Math.max(from, next.from + start), Math.min(to, pos),
inheritedClass, innerHighlighters)
this.startSpan(pos, cls)
}
}
if (hasChild) cursor.parent()
} else if (cursor.firstChild()) {
do {
if (cursor.to <= from) continue
if (cursor.from >= to) break
this.highlightRange(cursor, from, to, inheritedClass, highlighters)
this.startSpan(Math.min(to, cursor.to), cls)
} while (cursor.nextSibling())
cursor.parent()
}
}
}
const t = Tag.define
const comment = t(), name = t(), typeName = t(name), propertyName = t(name),
literal = t(), string = t(literal), number = t(literal),
content = t(), heading = t(content), keyword = t(), operator = t(),
punctuation = t(), bracket = t(punctuation), meta = t()
/// The default set of highlighting [tags](#highlight.Tag).
///
/// This collection is heavily biased towards programming languages,
/// and necessarily incomplete. A full ontology of syntactic
/// constructs would fill a stack of books, and be impractical to
/// write themes for. So try to make do with this set. If all else
/// fails, [open an
/// issue](https://github.com/codemirror/codemirror.next) to propose a
/// new tag, or [define](#highlight.Tag^define) a local custom tag for
/// your use case.
///
/// Note that it is not obligatory to always attach the most specific
/// tag possible to an element—if your grammar can't easily
/// distinguish a certain type of element (such as a local variable),
/// it is okay to style it as its more general variant (a variable).
///
/// For tags that extend some parent tag, the documentation links to
/// the parent.
export const tags = {
/// A comment.
comment,
/// A line [comment](#highlight.tags.comment).
lineComment: t(comment),
/// A block [comment](#highlight.tags.comment).
blockComment: t(comment),
/// A documentation [comment](#highlight.tags.comment).
docComment: t(comment),
/// Any kind of identifier.
name,
/// The [name](#highlight.tags.name) of a variable.
variableName: t(name),
/// A type [name](#highlight.tags.name).
typeName: typeName,
/// A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
tagName: t(typeName),
/// A property or field [name](#highlight.tags.name).
propertyName: propertyName,
/// An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
attributeName: t(propertyName),
/// The [name](#highlight.tags.name) of a class.
className: t(name),
/// A label [name](#highlight.tags.name).
labelName: t(name),
/// A namespace [name](#highlight.tags.name).
namespace: t(name),
/// The [name](#highlight.tags.name) of a macro.
macroName: t(name),
/// A literal value.
literal,
/// A string [literal](#highlight.tags.literal).
string,
/// A documentation [string](#highlight.tags.string).
docString: t(string),
/// A character literal (subtag of [string](#highlight.tags.string)).
character: t(string),
/// An attribute value (subtag of [string](#highlight.tags.string)).
attributeValue: t(string),
/// A number [literal](#highlight.tags.literal).
number,
/// An integer [number](#highlight.tags.number) literal.
integer: t(number),
/// A floating-point [number](#highlight.tags.number) literal.
float: t(number),
/// A boolean [literal](#highlight.tags.literal).
bool: t(literal),
/// Regular expression [literal](#highlight.tags.literal).
regexp: t(literal),
/// An escape [literal](#highlight.tags.literal), for example a
/// backslash escape in a string.
escape: t(literal),
/// A color [literal](#highlight.tags.literal).
color: t(literal),
/// A URL [literal](#highlight.tags.literal).
url: t(literal),
/// A language keyword.
keyword,
/// The [keyword](#highlight.tags.keyword) for the self or this
/// object.
self: t(keyword),
/// The [keyword](#highlight.tags.keyword) for null.
null: t(keyword),
/// A [keyword](#highlight.tags.keyword) denoting some atomic value.
atom: t(keyword),
/// A [keyword](#highlight.tags.keyword) that represents a unit.
unit: t(keyword),
/// A modifier [keyword](#highlight.tags.keyword).
modifier: t(keyword),
/// A [keyword](#highlight.tags.keyword) that acts as an operator.
operatorKeyword: t(keyword),
/// A control-flow related [keyword](#highlight.tags.keyword).
controlKeyword: t(keyword),
/// A [keyword](#highlight.tags.keyword) that defines something.
definitionKeyword: t(keyword),
/// A [keyword](#highlight.tags.keyword) related to defining or
/// interfacing with modules.
moduleKeyword: t(keyword),
/// An operator.
operator,
/// An [operator](#highlight.tags.operator) that defines something.
derefOperator: t(operator),
/// Arithmetic-related [operator](#highlight.tags.operator).
arithmeticOperator: t(operator),
/// Logical [operator](#highlight.tags.operator).
logicOperator: t(operator),
/// Bit [operator](#highlight.tags.operator).
bitwiseOperator: t(operator),
/// Comparison [operator](#highlight.tags.operator).
compareOperator: t(operator),
/// [Operator](#highlight.tags.operator) that updates its operand.
updateOperator: t(operator),
/// [Operator](#highlight.tags.operator) that defines something.
definitionOperator: t(operator),
/// Type-related [operator](#highlight.tags.operator).
typeOperator: t(operator),
/// Control-flow [operator](#highlight.tags.operator).
controlOperator: t(operator),
/// Program or markup punctuation.
punctuation,
/// [Punctuation](#highlight.tags.punctuation) that separates
/// things.
separator: t(punctuation),
/// Bracket-style [punctuation](#highlight.tags.punctuation).
bracket,
/// Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
/// tokens).
angleBracket: t(bracket),
/// Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
/// tokens).
squareBracket: t(bracket),
/// Parentheses (usually `(` and `)` tokens). Subtag of
/// [bracket](#highlight.tags.bracket).
paren: t(bracket),
/// Braces (usually `{` and `}` tokens). Subtag of
/// [bracket](#highlight.tags.bracket).
brace: t(bracket),
/// Content, for example plain text in XML or markup documents.
content,
/// [Content](#highlight.tags.content) that represents a heading.
heading,
/// A level 1 [heading](#highlight.tags.heading).
heading1: t(heading),
/// A level 2 [heading](#highlight.tags.heading).
heading2: t(heading),
/// A level 3 [heading](#highlight.tags.heading).
heading3: t(heading),
/// A level 4 [heading](#highlight.tags.heading).
heading4: t(heading),
/// A level 5 [heading](#highlight.tags.heading).
heading5: t(heading),
/// A level 6 [heading](#highlight.tags.heading).
heading6: t(heading),
/// A prose separator (such as a horizontal rule).
contentSeparator: t(content),
/// [Content](#highlight.tags.content) that represents a list.
list: t(content),
/// [Content](#highlight.tags.content) that represents a quote.
quote: t(content),
/// [Content](#highlight.tags.content) that is emphasized.
emphasis: t(content),
/// [Content](#highlight.tags.content) that is styled strong.
strong: t(content),
/// [Content](#highlight.tags.content) that is part of a link.
link: t(content),
/// [Content](#highlight.tags.content) that is styled as code or
/// monospace.
monospace: t(content),
/// [Content](#highlight.tags.content) that has a strike-through
/// style.
strikethrough: t(content),
/// Inserted text in a change-tracking format.
inserted: t(),
/// Deleted text.
deleted: t(),
/// Changed text.
changed: t(),
/// An invalid or unsyntactic element.
invalid: t(),
/// Metadata or meta-instruction.
meta,
/// [Metadata](#highlight.tags.meta) that applies to the entire
/// document.
documentMeta: t(meta),
/// [Metadata](#highlight.tags.meta) that annotates or adds
/// attributes to a given syntactic element.
annotation: t(meta),
/// Processing instruction or preprocessor directive. Subtag of
/// [meta](#highlight.tags.meta).
processingInstruction: t(meta),
/// [Modifier](#highlight.Tag^defineModifier) that indicates that a
/// given element is being defined. Expected to be used with the
/// various [name](#highlight.tags.name) tags.
definition: Tag.defineModifier(),
/// [Modifier](#highlight.Tag^defineModifier) that indicates that
/// something is constant. Mostly expected to be used with
/// [variable names](#highlight.tags.variableName).
constant: Tag.defineModifier(),
/// [Modifier](#highlight.Tag^defineModifier) used to indicate that
/// a [variable](#highlight.tags.variableName) or [property
/// name](#highlight.tags.propertyName) is being called or defined
/// as a function.
function: Tag.defineModifier(),
/// [Modifier](#highlight.Tag^defineModifier) that can be applied to
/// [names](#highlight.tags.name) to indicate that they belong to
/// the language's standard environment.
standard: Tag.defineModifier(),
/// [Modifier](#highlight.Tag^defineModifier) that indicates a given
/// [names](#highlight.tags.name) is local to some scope.
local: Tag.defineModifier(),
/// A generic variant [modifier](#highlight.Tag^defineModifier) that
/// can be used to tag language-specific alternative variants of
/// some common tag. It is recommended for themes to define special
/// forms of at least the [string](#highlight.tags.string) and
/// [variable name](#highlight.tags.variableName) tags, since those
/// come up a lot.
special: Tag.defineModifier()
}
/// This is a highlighter that adds stable, predictable classes to
/// tokens, for styling with external CSS.
///
/// The following tags are mapped to their name prefixed with `"tok-"`
/// (for example `"tok-comment"`):
///
/// * [`link`](#highlight.tags.link)
/// * [`heading`](#highlight.tags.heading)
/// * [`emphasis`](#highlight.tags.emphasis)
/// * [`strong`](#highlight.tags.strong)
/// * [`keyword`](#highlight.tags.keyword)
/// * [`atom`](#highlight.tags.atom) [`bool`](#highlight.tags.bool)
/// * [`url`](#highlight.tags.url)
/// * [`labelName`](#highlight.tags.labelName)
/// * [`inserted`](#highlight.tags.inserted)
/// * [`deleted`](#highlight.tags.deleted)
/// * [`literal`](#highlight.tags.literal)
/// * [`string`](#highlight.tags.string)
/// * [`number`](#highlight.tags.number)
/// * [`variableName`](#highlight.tags.variableName)
/// * [`typeName`](#highlight.tags.typeName)
/// * [`namespace`](#highlight.tags.namespace)
/// * [`className`](#highlight.tags.className)
/// * [`macroName`](#highlight.tags.macroName)
/// * [`propertyName`](#highlight.tags.propertyName)
/// * [`operator`](#highlight.tags.operator)
/// * [`comment`](#highlight.tags.comment)
/// * [`meta`](#highlight.tags.meta)
/// * [`punctuation`](#highlight.tags.punctuation)
/// * [`invalid`](#highlight.tags.invalid)
///
/// In addition, these mappings are provided:
///
/// * [`regexp`](#highlight.tags.regexp),
/// [`escape`](#highlight.tags.escape), and
/// [`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
/// are mapped to `"tok-string2"`
/// * [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
/// to `"tok-variableName2"`
/// * [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
/// to `"tok-variableName tok-local"`
/// * [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
/// to `"tok-variableName tok-definition"`
/// * [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
/// to `"tok-propertyName tok-definition"`
export const classHighlighter = tagHighlighter([
{tag: tags.link, class: "tok-link"},
{tag: tags.heading, class: "tok-heading"},
{tag: tags.emphasis, class: "tok-emphasis"},
{tag: tags.strong, class: "tok-strong"},
{tag: tags.keyword, class: "tok-keyword"},
{tag: tags.atom, class: "tok-atom"},
{tag: tags.bool, class: "tok-bool"},
{tag: tags.url, class: "tok-url"},
{tag: tags.labelName, class: "tok-labelName"},
{tag: tags.inserted, class: "tok-inserted"},
{tag: tags.deleted, class: "tok-deleted"},
{tag: tags.literal, class: "tok-literal"},
{tag: tags.string, class: "tok-string"},
{tag: tags.number, class: "tok-number"},
{tag: [tags.regexp, tags.escape, tags.special(tags.string)], class: "tok-string2"},
{tag: tags.variableName, class: "tok-variableName"},
{tag: tags.local(tags.variableName), class: "tok-variableName tok-local"},
{tag: tags.definition(tags.variableName), class: "tok-variableName tok-definition"},
{tag: tags.special(tags.variableName), class: "tok-variableName2"},
{tag: tags.definition(tags.propertyName), class: "tok-propertyName tok-definition"},
{tag: tags.typeName, class: "tok-typeName"},
{tag: tags.namespace, class: "tok-namespace"},
{tag: tags.className, class: "tok-className"},
{tag: tags.macroName, class: "tok-macroName"},
{tag: tags.propertyName, class: "tok-propertyName"},
{tag: tags.operator, class: "tok-operator"},
{tag: tags.comment, class: "tok-comment"},
{tag: tags.meta, class: "tok-meta"},
{tag: tags.invalid, class: "tok-invalid"},
{tag: tags.punctuation, class: "tok-punctuation"}
])