Skip to content

Commit 6c7fdea

Browse files
committed
beginWithKeyword replaced by a simpler beginKeywords.
1 parent a3c2db5 commit 6c7fdea

29 files changed

+66
-103
lines changed

docs/reference.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ Sometimes a mode can end not by itself but implicitly with its containing (paren
7878
This is achieved with :ref:`endsWithParent <endsWithParent>` attribute.
7979

8080

81-
beginWithKeyword
81+
beginKeywords
8282
^^^^^^^^^^^^^^^^
8383

84-
**type**: boolean
84+
**type**: string
8585

8686
Used instead of ``begin`` for modes starting with keywords to avoid needless repetition:
8787

@@ -97,9 +97,11 @@ Used instead of ``begin`` for modes starting with keywords to avoid needless rep
9797
::
9898

9999
{
100-
beginWithKeyword: true, keywords: 'extends implements'
100+
beginKeywords: 'extends implements'
101101
}
102102

103+
Unlike the ``[[#keywords]]`` attribute, this one allows only a simple list of space separated keywords. If you do need additional features of ``keywords`` or you just need more keywords for this mode you may include ``keywords`` along with ``beginKeywords``.
104+
103105

104106
.. _endsWithParent:
105107

src/highlight.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function() {
166166
return;
167167
mode.compiled = true;
168168

169-
var keywords = []; // used later with beginWithKeyword but filled as a side-effect of keywords compilation
169+
mode.keywords = mode.keywords || mode.beginKeywords;
170170
if (mode.keywords) {
171171
var compiled_keywords = {};
172172

@@ -177,7 +177,6 @@ function() {
177177
str.split(' ').forEach(function(kw) {
178178
var pair = kw.split('|');
179179
compiled_keywords[pair[0]] = [className, pair[1] ? Number(pair[1]) : 1];
180-
keywords.push(pair[0]);
181180
});
182181
}
183182

@@ -193,9 +192,10 @@ function() {
193192
}
194193
mode.keywords = compiled_keywords;
195194
}
195+
196196
if (parent) {
197-
if (mode.beginWithKeyword) {
198-
mode.begin = '\\b(' + keywords.join('|') + ')\\b(?!\\.)\\s*';
197+
if (mode.beginKeywords) {
198+
mode.begin = '\\b(' + mode.beginKeywords.split(/\s+/).join('|') + ')\\b(?!\\.)\\s*';
199199
}
200200
mode.beginRe = langRe(mode.begin ? mode.begin : '\\B|\\b');
201201
if (!mode.end && !mode.endsWithParent)

src/languages/actionscript.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,26 @@ function(hljs) {
3131
hljs.C_NUMBER_MODE,
3232
{
3333
className: 'package',
34-
beginWithKeyword: true, end: '{',
35-
keywords: 'package',
34+
beginKeywords: 'package', end: '{',
3635
contains: [TITLE_MODE]
3736
},
3837
{
3938
className: 'class',
40-
beginWithKeyword: true, end: '{',
41-
keywords: 'class interface',
39+
beginKeywords: 'class interface', end: '{',
4240
contains: [
4341
{
44-
beginWithKeyword: true,
45-
keywords: 'extends implements'
42+
beginKeywords: 'extends implements'
4643
},
4744
TITLE_MODE
4845
]
4946
},
5047
{
5148
className: 'preprocessor',
52-
beginWithKeyword: true, end: ';',
53-
keywords: 'import include'
49+
beginKeywords: 'import include', end: ';'
5450
},
5551
{
5652
className: 'function',
57-
beginWithKeyword: true, end: '[{;]',
58-
keywords: 'function',
53+
beginKeywords: 'function', end: '[{;]',
5954
illegal: '\\S',
6055
contains: [
6156
TITLE_MODE,

src/languages/applescript.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ function(hljs) {
9393
},
9494
{
9595
className: 'function_start',
96-
beginWithKeyword: true,
97-
keywords: 'on',
96+
beginKeywords: 'on',
9897
illegal: '[${=;\\n]',
9998
contains: [TITLE, PARAMS]
10099
}

src/languages/autohotkey.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ function(hljs) {
2121
},
2222
{
2323
className: 'built_in',
24-
beginWithKeyword: true,
25-
keywords: 'ComSpec Clipboard ClipboardAll ErrorLevel'
24+
beginKeywords: 'ComSpec Clipboard ClipboardAll ErrorLevel'
2625
}
2726
];
2827

src/languages/axapta.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ function(hljs) {
2323
},
2424
{
2525
className: 'class',
26-
beginWithKeyword: true, end: '{',
26+
beginKeywords: 'class interface', end: '{',
2727
illegal: ':',
28-
keywords: 'class interface',
2928
contains: [
3029
{
3130
className: 'inheritance',
32-
beginWithKeyword: true,
33-
keywords: 'extends implements',
31+
beginKeywords: 'extends implements',
3432
relevance: 10
3533
},
3634
{

src/languages/coffeescript.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ function(hljs) {
112112
},
113113
{
114114
className: 'class',
115-
beginWithKeyword: true, keywords: 'class',
115+
beginKeywords: 'class',
116116
end: '$',
117117
illegal: /[:="\[\]]/,
118118
contains: [
119119
{
120-
beginWithKeyword: true, keywords: 'extends',
120+
beginKeywords: 'extends',
121121
endsWithParent: true,
122122
illegal: /[:="\[\]]/,
123123
contains: [TITLE]

src/languages/cs.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,22 @@ function(hljs) {
5151
hljs.QUOTE_STRING_MODE,
5252
hljs.C_NUMBER_MODE,
5353
{
54-
beginWithKeyword: true, end: '{',
55-
keywords: 'class namespace',
54+
beginKeywords: 'class namespace', end: '{',
5655
contains: [
5756
TITLE
5857
]
5958
},
6059
{
61-
beginWithKeyword: true, keywords: 'protected public private internal',
62-
starts: {
63-
end: '{|;',
64-
keywords: KEYWORDS,
65-
contains: [
66-
{
67-
begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
68-
contains: [
69-
TITLE
70-
]
71-
}
72-
]
73-
}
60+
beginKeywords: 'protected public private internal', end: '{|;',
61+
keywords: KEYWORDS,
62+
contains: [
63+
{
64+
begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
65+
contains: [
66+
TITLE
67+
]
68+
}
69+
]
7470
}
7571
]
7672
};

src/languages/delphi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function(hljs) {
3434
};
3535
var FUNCTION = {
3636
className: 'function',
37-
beginWithKeyword: true, end: /[:;]/,
37+
beginKeywords: 'function constructor destructor procedure', end: /[:;]/,
3838
keywords: 'function constructor|10 destructor|10 procedure|10',
3939
contains: [
4040
{

src/languages/fsharp.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ function(hljs) {
3030
},
3131
{
3232
className: 'class',
33-
beginWithKeyword: true, end: '\\(|=|$',
34-
keywords: 'type',
33+
beginKeywords: 'type', end: '\\(|=|$',
3534
contains: [
3635
{
3736
className: 'title',

src/languages/haskell.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ function(hljs) {
9090
},
9191
{
9292
className: 'default',
93-
beginWithKeyword: true, end: '$',
94-
keywords: 'default',
93+
beginKeywords: 'default', end: '$',
9594
contains: [CONSTRUCTOR, LIST, COMMENT]
9695
},
9796
{
9897
className: 'infix',
99-
beginWithKeyword: true, end: '$',
100-
keywords: 'infix infixl infixr',
98+
beginKeywords: 'infix infixl infixr', end: '$',
10199
contains: [hljs.C_NUMBER_MODE, COMMENT]
102100
},
103101
{

src/languages/java.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ function(hljs) {
2525
hljs.QUOTE_STRING_MODE,
2626
{
2727
className: 'class',
28-
beginWithKeyword: true, end: '{',
29-
keywords: 'class interface',
28+
beginKeywords: 'class interface', end: '{',
3029
excludeEnd: true,
3130
illegal: ':',
3231
contains: [
3332
{
34-
beginWithKeyword: true,
35-
keywords: 'extends implements',
33+
beginKeywords: 'extends implements',
3634
relevance: 10
3735
},
3836
{

src/languages/javascript.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ function(hljs) {
4747
},
4848
{
4949
className: 'function',
50-
beginWithKeyword: true, end: /{/,
51-
keywords: 'function',
50+
beginKeywords: 'function', end: /\{/,
5251
contains: [
5352
{
5453
className: 'title', begin: /[A-Za-z$_][0-9A-Za-z$_]*/

src/languages/lasso.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function(hljs) {
109109
},
110110
{
111111
className: 'class',
112-
beginWithKeyword: true, keywords: 'define',
112+
beginKeywords: 'define',
113113
returnEnd: true, end: '\\(|=>',
114114
contains: [
115115
{

src/languages/livecodeserver.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ function(hljs) {
119119
},
120120
{
121121
className: 'function',
122-
beginWithKeyword: true, end: '$',
123-
keywords: 'function',
122+
beginKeywords: 'function', end: '$',
124123
contains: [
125124
VARIABLE,
126125
{
@@ -131,8 +130,7 @@ function(hljs) {
131130
},
132131
{
133132
className: 'function',
134-
beginWithKeyword: true, end: '$',
135-
keywords: 'end',
133+
beginKeywords: 'end', end: '$',
136134
contains: [
137135
{
138136
className: 'title',
@@ -142,8 +140,7 @@ function(hljs) {
142140
},
143141
{
144142
className: 'command',
145-
beginWithKeyword: true, end: '$',
146-
keywords: 'command on',
143+
beginKeywords: 'command on', end: '$',
147144
contains: [
148145
VARIABLE,
149146
{
@@ -154,8 +151,7 @@ function(hljs) {
154151
},
155152
{
156153
className: 'command',
157-
beginWithKeyword: true, end: '$',
158-
keywords: 'end',
154+
beginKeywords: 'end', end: '$',
159155
contains: [
160156
{
161157
className: 'title',

src/languages/lua.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ function(hljs) {
3737
contains: COMMENTS.concat([
3838
{
3939
className: 'function',
40-
beginWithKeyword: true, end: '\\)',
41-
keywords: 'function',
40+
beginKeywords: 'function', end: '\\)',
4241
contains: [
4342
{
4443
className: 'title',

src/languages/matlab.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ function(hljs) {
4040
contains: [
4141
{
4242
className: 'function',
43-
beginWithKeyword: true, end: '$',
44-
keywords: 'function',
43+
beginKeywords: 'function', end: '$',
4544
contains: [
4645
{
4746
className: 'title',

src/languages/ocaml.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ function(hljs) {
3030
},
3131
{
3232
className: 'class',
33-
beginWithKeyword: true, end: '\\(|=|$',
34-
keywords: 'type',
33+
beginKeywords: 'type', end: '\\(|=|$',
3534
contains: [
3635
{
3736
className: 'title',

src/languages/oxygene.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function(hljs) {
3333
};
3434
var FUNCTION = {
3535
className: 'function',
36-
beginWithKeyword: true, end: '[:;]',
36+
beginKeywords: 'function constructor destructor procedure method', end: '[:;]',
3737
keywords: 'function constructor|10 destructor|10 procedure|10 method|10',
3838
contains: [
3939
{

src/languages/perl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ function(hljs) {
136136
},
137137
{
138138
className: 'sub',
139-
beginWithKeyword: true, end: '(\\s*\\(.*?\\))?[;{]',
140-
keywords: 'sub',
139+
beginKeywords: 'sub', end: '(\\s*\\(.*?\\))?[;{]',
141140
relevance: 5
142141
},
143142
{

src/languages/php.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ function(hljs) {
6969
VARIABLE,
7070
{
7171
className: 'function',
72-
beginWithKeyword: true, end: /[;{]/,
73-
keywords: 'function',
72+
beginKeywords: 'function', end: /[;{]/,
7473
illegal: '\\$|\\[|%',
7574
contains: [
7675
TITLE,
@@ -89,13 +88,11 @@ function(hljs) {
8988
},
9089
{
9190
className: 'class',
92-
beginWithKeyword: true, end: '{',
93-
keywords: 'class',
91+
beginKeywords: 'class', end: '{',
9492
illegal: '[:\\(\\$]',
9593
contains: [
9694
{
97-
beginWithKeyword: true, endsWithParent: true,
98-
keywords: 'extends',
95+
beginKeywords: 'extends', endsWithParent: true,
9996
contains: [TITLE]
10097
},
10198
TITLE

src/languages/python.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function(hljs) {
5555
contains: ['self', PROMPT, NUMBER, STRING]
5656
};
5757
var FUNC_CLASS_PROTO = {
58-
beginWithKeyword: true, end: /:/,
58+
end: /:/,
5959
illegal: /[${=;\n]/,
6060
contains: [TITLE, PARAMS]
6161
};
@@ -75,8 +75,8 @@ function(hljs) {
7575
NUMBER,
7676
STRING,
7777
hljs.HASH_COMMENT_MODE,
78-
hljs.inherit(FUNC_CLASS_PROTO, {className: 'function', keywords: 'def', relevance: 10}),
79-
hljs.inherit(FUNC_CLASS_PROTO, {className: 'class', keywords: 'class'}),
78+
hljs.inherit(FUNC_CLASS_PROTO, {className: 'function', beginKeywords: 'def', relevance: 10}),
79+
hljs.inherit(FUNC_CLASS_PROTO, {className: 'class', beginKeywords: 'class'}),
8080
{
8181
className: 'decorator',
8282
begin: /@/, end: /$/

0 commit comments

Comments
 (0)