-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.html
546 lines (544 loc) · 33.2 KB
/
reference.html
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mode reference | highlight.js - にほんご。</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta property="og:title" content="Mode reference | highlight.js - にほんご。">
<meta property="og:url">
<meta property="og:type" content="article">
<link rel="icon" href="https://tr.you84815.space/hljs/favicon.ico">
<link rel="stylesheet" type="text/css" href="./css/main.css">
<link id="theme_style" rel="stylesheet" type="text/css" href="">
<script id="srcTheme" src="./js/toggleTheme.js" data-dir="hljs"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-106478577-1', 'auto');
</script>
</head>
<body>
<div id="container">
<header>
<div class="icon"><a class="no-barba" href="https://tr.you84815.space/">
<svg width="16" height="16">
<rect width="16" height="16" fill="#e0e0e0"></rect>
</svg></a></div>
<div class="navi_toggle" onclick="toggleMenu()">
<svg id="menu_close" width="24" height="24" viewBox="0 0 24 24">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
<svg id="menu_open" width="24" height="24" viewBox="0 0 24 24">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path>
</svg>
</div>
<div class="title">highlight.js - <a class="no-barba" href="https://tr.you84815.space/">にほんご。</a></div><span id="toggleTheme">
<svg role="img" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path d="M8 256c0 136.966 111.033 248 248 248s248-111.034 248-248S392.966 8 256 8 8 119.033 8 256zm248 184V72c101.705 0 184 82.311 184 184 0 101.705-82.311 184-184 184z"></path>
</svg></span>
</header>
<div class="navi" id="navi">
<ul class="menu">
<li><a class="index" href="./index.html">Home</a></li>
<li><a class="getting-started" href="./getting-started.html">Getting Started</a></li>
<li><span onclick="toggleApi()">Library API</span>
<ul class="hidden" id="navi_api">
<li><a href="./api/highlight.html">.highlight()</a></li>
<li><a href="./api/highlight-auto.html">.highlightAuto()</a></li>
<li><a href="./api/fix-markup.html">.fixMarkup()</a></li>
<li><a href="./api/highlight-block.html">.highlightBlock()</a></li>
<li><a href="./api/configure.html">.configure()</a></li>
<li><a href="./api/init-highlighting.html">.initHighlighting()</a></li>
<li><a href="./api/init-highlighting-onload.html">.initHighlightingOnLoad()</a></li>
<li><a href="./api/register-language.html">.registerLanguage()</a></li>
<li><a href="./api/list-languages.html">.listLanguages()</a></li>
<li><a href="./api/get-language.html">.getLanguage()</a></li>
</ul>
</li>
<li><a class="languageGuide" href="./language-guide.html">Language definition guide</a>
<ul class="hidden" id="navi_languageGuide">
<li><a href="./language-guide.html#highlighting-overview">ハイライトの概要</a></li>
<li><a href="./language-guide.html#general-syntax">一般的な構文</a></li>
<li><a href="./language-guide.html#keywords">キーワード</a></li>
<li><a href="./language-guide.html#sub-modes">サブモード</a></li>
<li><a href="./language-guide.html#comments">コメント</a></li>
<li><a href="./language-guide.html#markup-generation">マークアップ</a></li>
<li><a href="./language-guide.html#mode-attributes">モード属性</a></li>
<li><a href="./language-guide.html#relevance">コードの関連性</a></li>
<li><a href="./language-guide.html#illegal-symbols">不正シンボル</a></li>
<li><a href="./language-guide.html#pre-defined-modes">定義済みのモードと正規表現</a></li>
</ul>
</li>
<li><a class="reference active" href="./reference.html">Mode reference</a>
<ul id="navi_reference">
<li><a href="./reference.html#types">各属性値の型</a>
</li>
<li><a href="./reference.html#attributes">属性</a>
<ul>
<li><a href="./reference.html#case_insensitive">case_insensitive</a></li>
<li><a href="./reference.html#aliases">aliases</a></li>
<li><a href="./reference.html#className">className</a></li>
<li><a href="./reference.html#begin">begin</a></li>
<li><a href="./reference.html#end">end</a></li>
<li><a href="./reference.html#beginKeywords">beginKeywords</a></li>
<li><a href="./reference.html#endsWithParent">endsWithParent</a></li>
<li><a href="./reference.html#endsParent">endsParent</a></li>
<li><a href="./reference.html#lexemes">lexemes</a></li>
<li><a href="./reference.html#keywords">keywords</a></li>
<li><a href="./reference.html#illegal">illegal</a></li>
<li><a href="./reference.html#exclude">excludeBegin, excludeEnd</a></li>
<li><a href="./reference.html#returnBegin">returnBegin</a></li>
<li><a href="./reference.html#returnEnd">returnEnd</a></li>
<li><a href="./reference.html#contains">contains</a></li>
<li><a href="./reference.html#starts">starts</a></li>
<li><a href="./reference.html#variants">variants</a></li>
<li><a href="./reference.html#subLanguage">subLanguage</a></li>
<li><a href="./reference.html#skip">skip</a></li>
</ul>
</li>
</ul>
</li>
<li><span onclick="cssClassRef()">CSS classes reference</span>
<ul class="hidden" id="navi_cssClassRef">
<li><a href="./css-class-ref/stylable-class.html">指定可能なクラス</a></li>
<li><a href="./css-class-ref/language-name.html">言語名とエイリアス</a></li>
</ul>
</li>
<li><a class="styleGuide" href="./style-guide.html">Style guide</a>
<ul class="hidden" id="navi_styleGuide">
<li><a href="./style-guide.html#key-principle">基本的な方針</a></li>
<li><a href="./style-guide.html#defining-a-theme">テーマの定義</a></li>
<li><a href="./style-guide.html#typography-n-layout">タイポグラフィとレイアウトの注意事項</a></li>
<li><a href="./style-guide.html#subst">.subst</a></li>
<li><a href="./style-guide.html#contributing">コントリビュート</a></li>
</ul>
</li>
<li><a class="languageCheckList" href="./language-check-list.html">Language contributor checklist</a>
<ul class="hidden" id="navi_languageCheckList">
<li><a href="./language-check-list.html#put-language-definition">1. 言語定義の.jsファイルを追加</a></li>
<li><a href="./language-check-list.html#provide-meta-data">2. メタデータの挿入</a></li>
<li><a href="./language-check-list.html#code-example">3. コード例の作成</a></li>
<li><a href="./language-check-list.html#write-class-reference">4. クラスリファレンス作成</a></li>
<li><a href="./language-check-list.html#add-yourself">5. AUTHORS.*.txtとCHANGES.mdの編集</a></li>
<li><a href="./language-check-list.html#pull-request">6. プルリクエストを作成</a></li>
</ul>
</li>
<li><a class="buildAndTest" href="./building-n-testing.html">Building and testing</a>
<ul class="hidden" id="navi_buildAndTest">
<li><a href="./building-n-testing.html#building">ビルド</a></li>
<li><a href="./building-n-testing.html#basic-testing">基本テスト</a></li>
<li><a href="./building-n-testing.html#testing-markup">マークアップテスト</a></li>
</ul>
</li>
<li><a class="releaseProcess" href="./release-process.html">Release process</a></li>
<li><a class="lineNumbers" href="./line-numbers.html">Line numbers</a></li>
<li><a class="newLanguages" href="./new-languages.html">On requesting new languages</a></li>
<li><a class="other" href="./other.html">Other</a></li>
</ul>
</div>
<div id="content">
<div id="main">
<div id="barba-wrapper">
<div class="barba-container">
<h1>Mode reference</h1>
<div id="update_date"><span>更新日: 2018.09.14
</span>
</div>
<p>ここではhighlight.jsで使われる各モードを説明しています。</p>
<h2 id="types">各属性値の型</h2>
<p>このリファレンスでの属性値の型は以下の通りです。</p>
<div class="table-box">
<table class="my-table">
<tr>
<td><code>identifier</code></td>
<td>
JavaScriptの変数と、CSSのクラス名として使うのに適した文字列。
(すなわち、<code>/[A-Za-z0-9_]+/</code>)
</td>
</tr>
<tr>
<td><code>regexp</code></td>
<td>
JavaScriptの正規表現を表す文字列。
リテラルな正規表現ではないので、全てのバックスラッシュ(<code>\</code>)を2回繰り返す必要があります。
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>JavaScriptのbool値です。<code>true</code>または<code>false</code></td>
</tr>
<tr>
<td><code>number</code></td>
<td>JavaScriptの数値です。</td>
</tr>
<tr>
<td><code>object</code></td>
<td>JavaScriptのオブジェクトです。<code>{ ... }</code></td>
</tr>
<tr>
<td><code>array</code></td>
<td>JavaScriptの配列です。<code>[ ... ]</code></td>
</tr>
</table>
</div>
<h2 id="attributes">属性</h2>
<h3 id="case_insensitive">case_insensitive</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>
言語のキーワードと正規表現の大文字・小文字を区別しません。
トップレベルのモードでのみ使用可能です。
</p>
<pre><code>{
<span class="hljs-attr">case_insensitive</span>: <span class="hljs-literal">true</span>,
...
}</code></pre><br>
<h3 id="aliases">aliases</h3>
<div><b>type :</b> <span class="type">array</span></div>
<p>HTMLで指定するクラスや、<a href="./api/get-language.html"><code>.getLanguage()</code></a>メソッドで言語を検出するために追加する名前(エイリアス)のリスト。
(標準的な名前に加えて定義します。)
</p>
<pre><code>{
<span class="hljs-attr">aliases</span>: [<span class="hljs-string">'js'</span>, <span class="hljs-string">'jsx'</span>],
...
}</code></pre><br>
<h3 id="className">className</h3>
<div><b>type :</b> <span class="type">identifier</span></div>
<p>
モードの名前。
HTMLマークアップのクラス名として使用されます。
</p>
<p>
複数のモードに同じ名前を指定することができます。
言語がシングルクォーテーション(<code>'</code>)やダブルクォーテーション(<code>"</code>)で囲まれた文字列を、
どちらも"文字列"とするような、複数の構文を持つ場合に便利です。
</p>
<pre><code>{
<span class="hljs-attr">className</span>: <span class="hljs-string">'number'</span>,
...
},
{
<span class="hljs-attr">className</span>: <span class="hljs-string">'string'</span>,
...
},</code></pre><br>
<h3 id="begin">begin</h3>
<div><b>type :</b> <span class="type">regexp</span></div>
<p>
モードの開始を表す正規表現。
例えば、文字列を表すシングルクォーテーション(<code>'</code>)や、
C言語のコメント用のスラッシュ(<code>//</code>)などです。
<code>begin</code>が未定義の場合、
デフォルトは全ての文字列にマッチする正規表現のため、
モードはただちに開始になります。
</p>
<pre><code>{
<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/^\s*['"]use (strict|asm)['"]/</span>
...
},</code></pre><br>
<h3 id="end">end</h3>
<div><b>type :</b> <span class="type">regexp</span></div>
<p>
モードの終了を表す正規表現。
例えば、文字列を表すシングルクォーテーション(<code>'</code>)や、
1行コメント用の行末(<code>$</code>)などです。
</p>
<p>
しばしば、開始の正規表現でモード全体を定義し、モードの終了を指定する必要が無いことがあります。
例えば、数字は<code>begin: "\\b\\d+"</code>で全ての数字を定義することができます。
</p>
<p><code>begin</code>が未定義の場合、
デフォルトは全ての文字列にマッチする正規表現のため、
モードはただちに終了になります。
</p>
<p>
時々、モードは自身で終了することはできませんが、
自身を含んだ親のモードで暗黙的に終了することがあります。
これは<a href="#endsWithParent"><code>endsWithParent</code></a>属性で行われます。
</p>
<pre><code>{
<span class="hljs-attr">end</span>: <span class="hljs-regexp">/$/</span>
...
},</code></pre><br>
<h3 id="beginKeywords">beginKeywords</h3>
<div><b>type :</b> <span class="type">string</span></div>
<p>
不要な繰り返しを避けるために、モードをキーワードで開始します。
<code>begin</code>の代わりに使われます。
</p>
<pre><code>{
<span class="hljs-attr">begin</span>: <span class="hljs-string">'\\b(extends|implements) '</span>,
<span class="hljs-attr">keywords</span>: <span class="hljs-string">'extends implements'</span>
}</code></pre>
<p>上記の定義は、以下のように指定することもできます。</p>
<pre><code>{
<span class="hljs-attr">beginKeywords</span>: <span class="hljs-string">'extends implements'</span>
}</code></pre>
<p><a href="#keywords"><code>keywords</code></a>属性とは異なり、スペースで区切られた単純なキーワードリストのみを許可します。
<code>keywords</code>に追加機能が必要だったり、
単にこのモードにキーワードを追加したい場合、
<code>beginKeywords</code>と併せて、<code>keywords</code>を指定することができます。
</p><br>
<h3 id="endsWithParent">endsWithParent</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>親のモードが終了した時に、モードを終了することを示すフラグです。</p>
<p>
よく説明で使われるのは次の例です。
CSSではセレクタに、<code>{</code>と<code>}</code>で囲まれたルールを適用します。
個々のルールは<code>;</code>で区切られますが、
最後のルールは<code>;</code>を省略することができます。
</p>
<pre><code>p {
<span class="hljs-attr">width</span>: <span class="hljs-number">100</span>%; color: red
}</code></pre>
<p>このような場合に<code>endsWithParent</code>が動作します。</p>
<pre><code>{
<span class="hljs-attr">className</span>: <span class="hljs-string">'rules'</span>, <span class="hljs-attr">begin</span>: <span class="hljs-string">'{'</span>, <span class="hljs-attr">end</span>: <span class="hljs-string">'}'</span>,
<span class="hljs-attr">contains</span>: [
{<span class="hljs-attr">className</span>: <span class="hljs-string">'rule'</span>, <span class="hljs-comment">/* ... */</span> end: <span class="hljs-string">';'</span>, <span class="hljs-attr">endsWithParent</span>: <span class="hljs-literal">true</span>}
]
}</code></pre><br>
<h3 id="endsParent">endsParent</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>現在のモードが終了した直後に、親のモードを強制的に終了します。</p>
<p>
これは、簡単に表現できる終了語句が無いモードで、適用されるサブモードがあれば、
親のモードの代わりに、サブモードから親モードを閉じることができます。
</p>
<p>
例えば、Elixirでは関数を定義する2種類の方法があります。
1つめは<code>do</code>キーワードを使う方法、2つめは<code>,</code>を使う方法です。
</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span></span> <span class="hljs-symbol">:clear</span>, list <span class="hljs-keyword">do</span>
<span class="hljs-symbol">:ok</span>
<span class="hljs-keyword">end</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span></span>, <span class="hljs-symbol">do:</span> IO.puts <span class="hljs-string">"hello world"</span></code></pre>
<p>
1つめの場合、関数名の後ろのパラメータにカンマを含めることができます。
そして、関数名のみを強調したい場合は、
関数名の後に関数定義を終了するよう指定することができます。
</p>
<pre><code>{
<span class="hljs-attr">className</span>: <span class="hljs-string">'function'</span>,
<span class="hljs-attr">beginKeywords</span>: <span class="hljs-string">'def'</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/\B\b/</span>,
<span class="hljs-attr">contains</span>: [
{
<span class="hljs-attr">className</span>: <span class="hljs-string">'title'</span>,
<span class="hljs-attr">begin</span>: hljs.IDENT_RE, <span class="hljs-attr">endsParent</span>: <span class="hljs-literal">true</span>
}
]
}</code></pre>
<blockquote>正規表現<code>end: /\B\b/</code>は、関数自体が終了にならないように指定しています。</blockquote><br>
<h3 id="lexemes">lexemes</h3>
<div><b>type :</b> <span class="type">regexp</span></div>
<p>
言語のテキストから個々の語句を抽出し、
その中からキーワードを探す正規表現を指定します。
デフォルト値<code>hljs.IDENT_RE</code>は、ほとんどの言語で使用可能です。
</p>
<pre><code>{
<span class="hljs-attr">lexemes</span>: <span class="hljs-regexp">/[!#@\w]+/</span>,
...
},</code></pre><br>
<h3 id="keywords">keywords</h3>
<div><b>type :</b> <span class="type">object</span></div>
<p>キーワードの定義は2つの方法があります。</p>
<ul>
<li><code>'for while if else weird_voodoo|10 ... '</code><br>スペースで区切ったキーワードと、関連オプションをパイプで渡す方法</li>
<li><code>{'keyword': ' ... ', 'literal': ' ... '}</code><br>異なる種類のキーワードと、その文字列をオブジェクト形式で指定します。
指定する文字列は1つ目の形式で指定します。
</li>
</ul>
<p>詳しくは<a href="./language-guide.html#keywords">キーワード</a>を参照してください。</p>
<pre><code>{
<span class="hljs-attr">keywords</span>: {
<span class="hljs-attr">keyword</span>:
<span class="hljs-string">'cp cpf ... '</span>+
...
<span class="hljs-string">'vnoremap vnoremenu ... '</span>,
<span class="hljs-attr">built_in</span>: <span class="hljs-comment">//built in func</span>
<span class="hljs-string">'synIDtrans ... '</span> +
...
<span class="hljs-string">'exp'</span>
},
...
}
</code></pre><br>
<h3 id="illegal">illegal</h3>
<div><b>type :</b> <span class="type">regexp</span></div>
<p>
不正シンボルを定義する正規表現を指定します。
パーサが不正シンボルを見つけた場合、すぐに言語解析を終了します。
</p>
<pre><code>{
<span class="hljs-attr">illegal</span>: <span class="hljs-regexp">/#(?!!)/</span>
...
}</code></pre><br>
<h3 id="exclude">excludeBegin, excludeEnd</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>
モードの開始語句、終了語句をマークアップから除外します。
例えばCSSの場合、スタイルのルールは<code>;</code>で終了します。
しかし、視覚的には<code>;</code>を色付けしない方が良いでしょう。
<code>excludeEnd: true</code>を指定すると、
<code>span</code>タグの要素が<code>;</code>の前に閉じられます。
</p>
<pre><code>{
<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/\(/</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/\)/</span>,
<span class="hljs-attr">excludeBegin</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">excludeEnd</span>: <span class="hljs-literal">true</span>,
...
}</code></pre><br>
<h3 id="returnBegin">returnBegin</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>
開始語句を見つけたらパーサへ戻ります。
これは、親のモード内だけではなく、
サブモードのルールで解析させるような、複雑な開始語句を使う時に指定します。
</p>
<p>
事実上、パーサが戻ってくることになり、
無限ループを発生させることが出来るので、扱いに注意してください!
</p>
<pre><code><span class="hljs-keyword">var</span> IDENT_RE = <span class="hljs-string">'[A-Za-z$_][0-9A-Za-z$_]*'</span>;
...
{
<span class="hljs-attr">begin</span>: IDENT_RE + <span class="hljs-string">'\\s*:'</span>, <span class="hljs-attr">returnBegin</span>: <span class="hljs-literal">true</span>,
...
}</code></pre><br>
<h3 id="returnEnd">returnEnd</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>
終了語句を見つけたらパーサへ戻ります。
これは例えば、HTMLに埋め込まれたJavaScriptを解析する場合に使います。
JavaScriptのブロックは、HTML終了タグ<code></script></code>で終了します。
これはJavaScriptのルールでは解析することができません。
そこで、解析内容を親のHTMLモードに戻します。
HTMLモードは<code></script></code>どのようにするべきか分かっているはずです。
</p>
<p>
事実上、パーサが戻ってくることになり、
無限ループを発生させることが出来るので、扱いに注意してください!
</p>
<pre><code>{
<span class="hljs-attr">end</span>: <span class="hljs-string">'\<\/script\>'</span>, <span class="hljs-attr">returnEnd</span>: <span class="hljs-literal">true</span>,
...
}</code></pre><br>
<h3 id="contains">contains</h3>
<div><b>type :</b> <span class="type">array</span></div>
<p>
モード内で検索するサブモードのリスト。
詳しくは<a href="./language-guide.html#sub-modes">サブモード</a>を参照してください。
</p>
<pre><code>{
<span class="hljs-attr">contains</span>: [
hljs.C_BLOCK_COMMENT_MODE,
{
<span class="hljs-attr">className</span>: <span class="hljs-string">'selector-id'</span>, <span class="hljs-attr">begin</span>: <span class="hljs-regexp">/#[A-Za-z0-9_-]+/</span>
},
{
<span class="hljs-attr">className</span>: <span class="hljs-string">'selector-class'</span>, <span class="hljs-attr">begin</span>: <span class="hljs-regexp">/\.[A-Za-z0-9_-]+/</span>
},
...
],
...
}</code></pre><br>
<h3 id="starts">starts</h3>
<div><b>type :</b> <span class="type">identifier</span></div>
<p>
現在のモードが終了した直後に開始するモード名を指定します。
新しく開始するモードには現在のモード(終了するモード)は含まれません。
</p>
<p>
現在、この属性はHTMLに含まれるJavaScriptとCSSをハイライトするために使われています。
<code>script</code>タグと<code>style</code>タグは、
タグの内容を解析するために、それぞれの言語定義を使用するサブモードを開始します。
(<a href="#subLanguage">subLanguage</a>を参照してください。)
</p>
<pre><code>{
<span class="hljs-attr">starts</span>: {
<span class="hljs-attr">end</span>: <span class="hljs-string">'\<\/script\>'</span>, <span class="hljs-attr">returnEnd</span>: <span class="hljs-literal">true</span>,
<span class="hljs-attr">subLanguage</span>: [<span class="hljs-string">'actionscript'</span>, <span class="hljs-string">'javascript'</span>, <span class="hljs-string">'handlebars'</span>, <span class="hljs-string">'xml'</span>]
}
...
}</code></pre><br>
<h3 id="variants">variants</h3>
<div><b>type :</b> <span class="type">array</span></div>
<p>
モードのメインの定義を、
モードの全ての属性を持ったいくつかの同様のモードに効果的に拡張します。
拡張したモードは<code>variants</code>で上書きまたは、追記します。
</p>
<pre><code>{
<span class="hljs-attr">className</span>: <span class="hljs-string">'string'</span>,
<span class="hljs-attr">contains</span>: [hljs.BACKSLASH_ESCAPE],
<span class="hljs-attr">relevance</span>: <span class="hljs-number">0</span>,
<span class="hljs-attr">variants</span>: [
{<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/"/</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/"/</span>},
{<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/'/</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/'/</span>, <span class="hljs-attr">relevance</span>: <span class="hljs-number">1</span>}
]
}</code></pre><br>
<h3 id="subLanguage">subLanguage</h3>
<div><b>type :</b> <span class="type">array</span></div>
<p>
モードの内容全体を別の言語でハイライトします。
この属性を使う場合、<a href="#keywords">キーワード</a>や<a href="#lexemes">語句</a>等の解析ルールの定義は不要です。
またサブ言語は、テキストを自身の<code><span class="language-name"></code>で囲うので、
<code>className</code>属性を指定しないことをお勧めします。
</p>
<p>この属性の値は、1つまたは複数の言語をハイライトし、制御します。</p>
<ul>
<li>言語名 : 明示的に特定の言語でハイライトします。</li>
<li>空の配列 : 利用可能な全ての言語を自動で検出します。</li>
<li>言語名の配列 : 指定された言語の中から自動で検出します。</li>
</ul>
<pre><code>{
<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/<\?(php)?/</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/\?>/</span>,
<span class="hljs-attr">subLanguage</span>: <span class="hljs-string">'php'</span>,
...
}</code></pre><br>
<h3 id="skip">skip</h3>
<div><b>type :</b> <span class="type">boolean</span></div>
<p>
モードのマークアップ処理をスキップし、
開始語句と終了語句とともに、親のバッファの一部として残します。
この属性は、複雑な解析が必要な場合に、
親モードの<a href="#subLanguage">サブ言語</a>と組み合わせて使用します。
</p>
<p>HTML内のPHPを解析する場合、</p>
<pre><code><p><span class="hljs-meta"><?</span> <span class="hljs-keyword">echo</span> <span class="hljs-string">'PHP'</span>; <span class="hljs-comment">/* ?> */</span> <span class="hljs-meta">?></span></p></code></pre>
<p>コメント内の<code>?></code>でPHPを終了すべきではなく、
正しい終了タグである<code>?></code>を見つけるために、
<code>/* .. */</code>をペアとして扱う必要があります。
</p>
<pre><code>{
<span class="hljs-attr">begin</span>: <span class="hljs-regexp">/<\?/</span>, <span class="hljs-attr">end</span>: <span class="hljs-regexp">/\?>/</span>,
<span class="hljs-attr">subLanguage</span>: <span class="hljs-string">'php'</span>,
<span class="hljs-attr">contains</span>: [{<span class="hljs-attr">begin</span>: <span class="hljs-string">'/\\*'</span>, <span class="hljs-attr">end</span>: <span class="hljs-string">'\\*/'</span>, <span class="hljs-attr">skip</span>: <span class="hljs-literal">true</span>}]
}</code></pre>
<p><code>skip: true</code>を定義しない場合、
全てのコメントをHTMLモードとして扱います。
</p><br><br>
<div class="license">
<p>
© 2006
Highlight.js is released under the BSD License. See <a href="https://github.com/isagalaev/highlight.js/blob/master/LICENSE">LICENSE</a> file for details.
</p>
<p>このコンテンツは<a href="https://highlightjs.readthedocs.io/en/latest/">highlightjsドキュメント</a>を翻訳/改変したものです。</p>
</div>
</div>
</div>
</div>
</div>
<footer><span>© <span id="copy_year">2017</span> tobijibu</span></footer>
</div>
<noscript id="deferred-styles">
<link href="./css/lazy.css" rel="stylesheet">
</noscript>
<script src="./js/main.js" defer></script>
<script src="./js/highlight.pack.js"></script>
<div id="src" hidden></div>
</body>
</html>