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
Copy file name to clipboardExpand all lines: docs/mode-reference.rst
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,52 @@ Disables autodetection for this language.
105
105
(defaults to false, meaning auto-detect is enabled)
106
106
107
107
108
+
__emitTokens
109
+
^^^^^^^^^^^^
110
+
111
+
.. warning::
112
+
113
+
**This is currently still private/beta API**, though it's expected to be fairly stable.
114
+
115
+
It should land in version 12.0.
116
+
117
+
Allows grammars to bundle custom parsers - bypassing the default parser and grammar mode definitions. This should be a function that accepts the raw source code as the first argument and an "Emitter" object as the second.
118
+
119
+
A custom parser may parse the source as it sees fit - making calls to the Emitter along the way - allowing Highlight.js to generate and theme the final HTML.
120
+
121
+
The **Emitter** API is trivial:
122
+
123
+
- ``addText(text)``
124
+
- ``startScope(name)``
125
+
- ``endScope()``
126
+
127
+
Given:
128
+
129
+
::
130
+
131
+
hello beautiful world!
132
+
133
+
134
+
Assuming beautiful is a keyword our Emitter calls might look something like:
The intended use of ``addText`` is larger chunks of plain text, not individual characters. Custom parsers should buffer plain text output into complete strings rather than sending output one character at a time.
0 commit comments