Skip to content

Commit 85eaf3b

Browse files
committed
update naming and docs
1 parent 3f2673d commit 85eaf3b

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

docs/mode-reference.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Regular expression starting a mode. For example a single quote for strings or tw
6262
If absent, ``begin`` defaults to a regexp that matches anything, so the mode starts immediately.
6363

6464

65-
after:begin
65+
on:begin
6666
^^^^^^^^^^^
6767

6868
**type**: callback (matchData, response)
@@ -72,6 +72,8 @@ This callback is triggered the moment a begin match is detected. ``matchData`` i
7272
- ``response.data`` - a simple object data store. Can be used for building more complex rules where the end rule is dependent on the content of begin, etc.
7373
- ``response.ignoreMatch()`` - pretend as if this match never happened. The mode is not entered. Continues trying subsequent modes in the current mode's ``contains`` list
7474

75+
For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``.
76+
7577

7678
end
7779
^^^
@@ -90,7 +92,7 @@ Sometimes a mode can end not by itself but implicitly with its containing (paren
9092
This is achieved with :ref:`endsWithParent <endsWithParent>` attribute.
9193

9294

93-
before:end
95+
on:end
9496
^^^^^^^^^^^
9597

9698
**type**: callback (matchData, response)
@@ -100,6 +102,8 @@ This callback is triggered the moment an end match is detected. ``matchData`` in
100102
- ``response.data`` - a simple object data store. Can be used for building more complex rules where the end rule is dependent on the content of begin, etc.
101103
- ``response.ignoreMatch()`` - pretend as if this match never happened. The mode is not entered. Continues trying subsequent modes in the current mode's ``contains`` list
102104

105+
For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``.
106+
103107

104108
beginKeywords
105109
^^^^^^^^^^^^^^^^
@@ -204,8 +208,12 @@ tell it to end the function definition after itself:
204208

205209
.. _endSameAsBegin:
206210

207-
endSameAsBegin
208-
^^^^^^^^^^^^^^
211+
endSameAsBegin (deprecated as of 10.1)
212+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213+
214+
**Deprecated:** *This attribute has been deprecated.* You should instead use the
215+
``END_SAME_AS_BEGIN`` mode or use the ``on:begin`` and ``on:end`` attributes to
216+
build more complex paired matchers.
209217

210218
**type**: boolean
211219

src/highlight.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ const HLJS = function(hljs) {
203203
let matched = regex.startsWith(mode.endRe, matchPlusRemainder);
204204

205205
if (matched) {
206-
if (mode["before:end"]) {
206+
if (mode["on:end"]) {
207207
let resp = new Response(mode);
208-
mode["before:end"](match, resp);
208+
mode["on:end"](match, resp);
209209
if (resp.ignore)
210210
matched = false;
211211
}
@@ -217,7 +217,7 @@ const HLJS = function(hljs) {
217217
return mode;
218218
}
219219
}
220-
// even if before:end fires an `ignore` it's still possible
220+
// even if on:end fires an `ignore` it's still possible
221221
// that we might trigger the end node because of a parent mode
222222
if (mode.endsWithParent) {
223223
return endOfMode(mode.parent, match, matchPlusRemainder);
@@ -245,7 +245,7 @@ const HLJS = function(hljs) {
245245

246246
let resp = new Response(new_mode);
247247
// first internal before callbacks, then the public ones
248-
let beforeCallbacks = [new_mode.__beforeBegin, new_mode["before:begin"]];
248+
let beforeCallbacks = [new_mode.__beforeBegin, new_mode["on:begin"]];
249249
for (let cb of beforeCallbacks) {
250250
if (!cb) continue;
251251
cb(match, resp);
@@ -268,10 +268,10 @@ const HLJS = function(hljs) {
268268
}
269269
}
270270
mode = startNewMode(new_mode);
271-
if (mode["after:begin"]) {
272-
let resp = new Response(mode);
273-
mode["after:begin"](match, resp);
274-
}
271+
// if (mode["after:begin"]) {
272+
// let resp = new Response(mode);
273+
// mode["after:begin"](match, resp);
274+
// }
275275
return new_mode.returnBegin ? 0 : lexeme.length;
276276
}
277277

src/lib/modes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const METHOD_GUARD = {
121121
export const END_SAME_AS_BEGIN = function(mode) {
122122
return Object.assign(mode,
123123
{
124-
'after:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
125-
'before:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch() }
124+
'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
125+
'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch() }
126126
});
127127
};

0 commit comments

Comments
 (0)