-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDMarkdown.sublime-syntax
3237 lines (2890 loc) · 111 KB
/
GDMarkdown.sublime-syntax
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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%YAML 1.2
---
# This definition aims to meet CommonMark specifications
# http://spec.commonmark.org/
# with GitHub Formatted Markdown extensions
# https://github.github.com/gfm/
# and has a few extras like Markdown Extra's footnotes
# https://michelf.ca/projects/php-markdown/extra/#footnotes
#
# The scope suffix should indicate which flavor of Markdown the feature came from,
# to help make this syntax definition easier to maintain.
name: GDMarkdown
scope: text.html.markdown.godot
version: 2
file_extensions:
- md
- mdown
- mdwn
- markdown
- markdn
variables:
atx_heading: (?:[ ]{,3}[#]{1,6}(?:[ \t]|$)) # between 0 and 3 spaces, followed 1 to 6 hashes, followed by at least one space or tab or by end of the line
atx_heading_space: (?:(?=[ \t]+#+[ \t]*$)|[ \t]+|$) # consume spaces only if heading is not empty to ensure `atx_heading_end` can fully match closing hashes
atx_heading_end: (?:[ \t]+(#+))?[ \t]*($\n?) # \n is optional so ## is matched as end punctuation in new document (at eof)
setext_heading_or_paragraph: ^(?:[ ]{,3}=+|(?=[ ]{,3}\S)) # between 0 and 3 spaces, followed by non-whitespace (consume equal signs as paragraphs may start with them)
setext_heading_escape: ^(?=[ ]{,3}(?:=+|-+)[ \t]*$) # between 0 and 3 spaces, followed by at least one hyphen or equal sign (setext underline can be of any length)
setext_heading1_escape: ^(?=[ ]{,3}=+[ \t]*$) # between 0 and 3 spaces, followed by at least one equal sign (setext underline can be of any length)
setext_heading1_end: ^[ ]{,3}(=+)[ \t]*$(\n?) # between 0 and 3 spaces, followed by at least one equal sign (setext underline can be of any length)
setext_heading2_end: ^[ ]{,3}(-+)[ \t]*$(\n?) # between 0 and 3 spaces, followed by at least one hyphen (setext underline can be of any length)
list_setext_heading_or_paragraph: (?:[ \t]*=+|(?=[ \t]*\S)) # any number of spaces, followed by non-whitespace (consume equal signs as paragraphs may start with them)
list_setext_heading_escape: ^(?=[ \t]{2,}(?:==+|--+)[ \t]*$) # two or more spaces, followed by at least one hyphen or equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items)
list_setext_heading1_escape: ^(?=[ \t]{2,}==+[ \t]*$) # two or more spaces, followed by at least one equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items)
list_setext_heading1_end: ^[ \t]{2,}(==+)[ \t]*$(\n?) # two or more spaces, followed by at least one equal sign (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items)
list_setext_heading2_end: ^[ \t]{2,}(--+)[ \t]*$(\n?) # two or more spaces, followed by at least one hyphen (setext underline can be of any length, but ST needs at least 2 to avoid ambiguity with empty list items)
block_quote: (?:[ ]{,3}(>)[ ]?) # between 0 and 3 spaces, followed by a greater than sign, (followed by any character or the end of the line = "only care about optional space!")
indented_code_block: (?:[ ]{4}|[ ]{0,3}\t) # a visual tab of width 4 consisting of 4 spaces or 0 to 3 spaces followed by 1 tab
first_list_item: (?:[ ]{,3}(?:1[.)]|[*+-])\s) # between 0 and 3 spaces, followed by either: at least one integer and a full stop or a parenthesis, or (a star, plus or dash), followed by whitespace
list_item: (?:[ ]{,3}(?:\d{1,9}[.)]|[*+-])\s) # between 0 and 3 spaces, followed by either: at least one integer and a full stop or a parenthesis, or (a star, plus or dash), followed by whitespace
thematic_break: |-
(?x:
[ ]{,3} # between 0 to 3 spaces
(?: # followed by one of the following:
[-](?:[ \t]*[-]){2,} # - a dash, followed by the following at least twice: any number of spaces or tabs followed by a dash
| [*](?:[ \t]*[*]){2,} # - a star, followed by the following at least twice: any number of spaces or tabs followed by a star
| [_](?:[ \t]*[_]){2,} # - an underscore, followed by the following at least twice: any number of spaces or tabs followed by an underscore
)
[ \t]*$ # followed by any number of tabs or spaces, followed by the end of the line
)
backticks: |-
(?x:
(`{4})(?![\s`])(?:[^`]+(?=`)|(?!`{4})`+(?!`))+(`{4})(?!`) # 4 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 4 backticks, or at least one non backtick character) at least once, followed by exactly 4 backticks
| (`{3})(?![\s`])(?:[^`]+(?=`)|(?!`{3})`+(?!`))+(`{3})(?!`) # 3 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 3 backticks, or at least one non backtick character) at least once, followed by exactly 3 backticks
| (`{2})(?![\s`])(?:[^`]+(?=`)|(?!`{2})`+(?!`))+(`{2})(?!`) # 2 backticks, followed by at least one non whitespace, non backtick character, followed by (less than 2 backticks, or at least one non backtick character) at least once, followed by exactly 2 backticks
| (`{1})(?![\s`])(?:[^`]+(?=`)|(?!`{1})`+(?!`))+(`{1})(?!`) # 1 backtick, followed by at least one non whitespace, non backtick character, followed by ( at least one non backtick character) at least once, followed by exactly 1 backtick
)
escapes: \\[-+*/!"#$%&'(),.:;<=>?@\[\\\]^_`{|}~]
balance_square_brackets: |-
(?x:
(?:
(?:{{escapes}})+ # escape characters
| [^\[\]`\\]+(?=[\[\]`\\]|$) # anything that isn't a square bracket or a backtick or the start of an escape character
| {{backticks}} # inline code
| \[(?: # nested square brackets (one level deep)
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
{{backticks}}? # balanced backticks
)*\] # closing square bracket
)+
)
balance_square_brackets_and_emphasis: |-
(?x:
(?:
(?:{{escapes}})+ # escape characters
| [^\[\]`\\_*]+(?=[\[\]`\\_*]|$) # anything that isn't a square bracket, a backtick, the start of an escape character, or an emphasis character
| {{backticks}} # inline code
| \[(?: # nested square brackets (one level deep)
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
{{backticks}}? # balanced backticks
)*\] # closing square bracket
)+ # at least one character
)
balance_square_brackets_pipes_and_emphasis: |-
(?x:
(?:
(?:{{escapes}})+ # escape characters
| [^\[\]`\\_*|]+(?=[\[\]`\\_*|]|$) # anything that isn't a square bracket, a backtick, the start of an escape character, or an emphasis character
| {{backticks}} # inline code
| \[(?: # nested square brackets (one level deep)
[^\[\]`]+(?=[\[\]`]) # anything that isn't a square bracket or a backtick
{{backticks}}? # balanced backticks
)*\] # closing square bracket
)+ # at least one character
)
balanced_emphasis: |-
(?x:
\* (?!\*){{balance_square_brackets_and_emphasis}}+\* (?!\*)
| \*\* {{balance_square_brackets_and_emphasis}}+\*\*
| _ (?!_) {{balance_square_brackets_and_emphasis}}+_ (?!_)
| __ {{balance_square_brackets_and_emphasis}}+__
)
table_cell: |-
(?x:
# Pipes inside other inline spans (such as emphasis, code, etc.) will not break a cell,
# emphasis in table cells can't span multiple lines
(?:
{{balance_square_brackets_pipes_and_emphasis}}
| {{balanced_emphasis}}
)+ # at least one character
)
table_first_row: |-
(?x:
# at least 2 non-escaped pipe chars on the line
(?:{{table_cell}}?\|){2}
# something other than whitespace followed by a pipe char or hyphen,
# followed by something other than whitespace and the end of the line
| (?! \s*\-\s+ | \s+\|){{table_cell}}\|(?!\s+$)
)
fenced_code_block_start: |-
(?x:
([ \t]*)
(
(`){3,} # 3 or more backticks
(?![^`]*`) # not followed by any more backticks on the same line
| # or
(~){3,} # 3 or more tildas
)
\s* # allow for whitespace between code block start and info string
)
fenced_code_block_language: |-
(?x: # first word of an infostring is used as language specifier
(
[[:alpha:]] # starts with a letter to make sure not to hit any attribute annotation
[^\s:;`]* # optionally followed by any nonwhitespace character (except backticks)
)
)
fenced_code_block_trailing_infostring_characters: |-
(?x:
(
\s* # any whitespace, or ..
|
[\s:;][^`]* # any characters (except backticks), separated by colon, semicolon or whitespace ...
)
$\n? # ... until EOL
)
fenced_code_block_end: |-
(?x:
[ \t]*
(
\2 # the backtick/tilde combination that opened the code fence
(?:\3|\4)* # plus optional additional closing characters
)
\s*$ # any amount of whitespace until EOL
)
fenced_code_block_escape: ^{{fenced_code_block_end}}
# https://spec.commonmark.org/0.30/#email-autolink
email_domain_commonmark: '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'
email_user_commonmark: '[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+'
# https://spec.commonmark.org/0.30/#html-blocks
html_block: |-
(?x:
[ ]{,3}
(?:
{{html_tag_block_end_at_close_tag}} # html block type 1
| {{html_tag_block_end_at_blank_line}} # html block type 6
| {{html_block_open_tag}} # html block type 7
| {{html_block_close_tag}} # html block type 7
| {{html_block_comment}} # html block type 2
| {{html_block_decl}} # html block type 4
| {{html_block_cdata}} # html block type 5
| {{html_block_preprocessor}} # html block type 3
)
)
html_block_comment: <!--
html_block_cdata: <!\[CDATA\[
html_block_decl: <![a-zA-Z]
html_block_preprocessor: <\?
html_block_open_tag: |-
(?xi:
<
[a-z] # A tag name consists of an ASCII letter
[a-z0-9-]* # followed by zero or more ASCII letters, digits, or hyphens (-)
(?: # An attribute consists of whitespace, an attribute name, and an optional attribute value specification
\s+
[a-z_:] # An attribute name consists of an ASCII letter, _, or :
[a-z0-9_.:-]* # followed by zero or more ASCII letters, digits, _, ., :, or -
(?: # An attribute value specification consists of optional whitespace, a = character, optional whitespace, and an attribute value
\s*
=
\s*
(?:
[^ @'=<>`]+ # An unquoted attribute value is a nonempty string of characters not including spaces, ", ', =, <, >, or `
| '[^']*' # A single-quoted attribute value consists of ', zero or more characters not including ', and a final '
| "[^"]*" # A double-quoted attribute value consists of ", zero or more characters not including ", and a final "
)
)?
)*
\s*
/?
>
\s*$
)
html_block_close_tag: |-
(?xi:
</
[a-z] # A tag name consists of an ASCII letter
[a-z0-9-]* # followed by zero or more ASCII letters, digits, or hyphens (-)
\s*
>
\s*$
)
html_tag_block_end_at_close_tag: |-
<(?xi: pre | script | style | textarea ){{html_tag_break_char}}
html_tag_block_end_at_blank_line: |-
<(?xi:
address | article | aside | base | basefont | blockquote | body | caption
| c enter | col | colgroup | dd | details | dialog | dir | div | dl | dt
| fieldset | figcaption | figure | footer | form | frame | frameset | h1 | h2
| h3 | h4 | h5 | h6 | head | header | hr | html | iframe | legend | li | link
| main | menu | menuitem | nav | noframes | ol | optgroup | option | p | param
| section | source | summary | table | tbody | td | tfoot | th
| thead | title | tr | track | ul
){{html_tag_maybe_selfclosing_break_char}}
html_tag_break_char: (?:[ \t>]|$)
html_tag_maybe_selfclosing_break_char: (?:[ \t]|/?>|$)
html_entity: '&([a-zA-Z0-9]+|#\d+|#[Xx]\h+);'
ascii_space: '\t\n\f '
tag_attribute_name_start: (?=[^{{ascii_space}}=/>}])
tag_attribute_name_break: (?=[{{ascii_space}}=/>}])
tag_unquoted_attribute_start: (?=[^{{ascii_space}}=/>}])
tag_unquoted_attribute_break: (?=[{{ascii_space}}}]|/?>)
reference_definition: (?:\[{{reference_name}}\]\:)
footnote_name: (?:\^(?:\\\]|[^]])+)
reference_name: (?:(?:\\\]|[^]])+)
paragraph_end: |-
(?x: # pop out of this context if one of the following conditions are met:
^(?=\s*$ # the line is blank (or only contains whitespace)
| {{block_quote}} # a blockquote begins the line
| {{atx_heading}} # an ATX heading begins the line
| {{fenced_code_block_start}} # a fenced codeblock begins the line
| {{thematic_break}} # line is a thematic beak
| {{first_list_item}} # a list item begins the line
| {{html_block}} # a html block begins the line
)
)
list_paragraph_end: |-
(?x: # pop out of this context if one of the following conditions are met:
^(?= [ \t]*
(?: $ # the line is blank (or only contains whitespace)
| {{block_quote}} # a blockquote begins the line
| {{atx_heading}} # an ATX heading begins the line
| {{fenced_code_block_start}} # a fenced codeblock begins the line
| {{thematic_break}} # line is a thematic beak
| {{list_item}} # a list item begins the line
| {{html_block}} # a html block begins the line
)
)
)
# https://spec.commonmark.org/0.30/#left-flanking-delimiter-run
bold_italic_asterisk_begin: |-
(?x:
(\*\*)(\*) {{no_space_nor_punct}}
| \B (\*\*)(\*) {{no_space_but_punct}}
)
bold_asterisk_begin: |-
(?x:
\*{2} {{no_space_nor_punct}}
| \B \*{2} {{no_space_but_punct}}
)
italic_asterisk_begin: |-
(?x:
\* {{no_space_nor_punct}}
| \B \* {{no_space_but_punct}}
)
no_escape_behind: (?<![^\\]\\)(?<![\\]{3})
# not followed by Unicode whitespace and not followed by a Unicode punctuation character
no_space_nor_punct: (?![\s*\p{P}])
# not followed by Unicode whitespace and followed by a Unicode punctuation character
no_space_but_punct: (?=[[^\s*]&&\p{P}])
##############################################################################
contexts:
main:
- include: frontmatter
- match: ''
set: markdown
frontmatter:
- match: (---)\s*(?i:(json)\s*)\n
captures:
0: meta.frontmatter.markdown
1: punctuation.section.block.begin.frontmatter.markdown
2: constant.other.language-name.markdown
embed: scope:source.json
embed_scope: meta.frontmatter.markdown source.json.embedded.markdown
escape: ^(---|\.{3})\s*\n # pandoc requires the remainder of the line to be blank
escape_captures:
0: meta.frontmatter.markdown
1: punctuation.section.block.end.frontmatter.markdown
- match: (---)\s*(?i:(yaml|yml)\s*)?\n
captures:
0: meta.frontmatter.markdown
1: punctuation.section.block.begin.frontmatter.markdown
2: constant.other.language-name.markdown
embed: scope:source.yaml
embed_scope: meta.frontmatter.markdown source.yaml.embedded.markdown
escape: ^(---|\.{3})\s*\n # pandoc requires the remainder of the line to be blank
escape_captures:
0: meta.frontmatter.markdown
1: punctuation.section.block.end.frontmatter.markdown
markdown:
- include: indented-code-blocks
- include: thematic-breaks
- include: block-quotes
- include: list-blocks
- include: tables
- include: fenced-code-blocks
- include: html-blocks
- include: reference-definitions
- include: atx-headings
- include: setext-headings-or-paragraphs
indented-markdown:
# This is a public context which can be embedded by 3rd-party syntaxes
# to support Markdown highlighting in locations of arbitrary indentation,
# but without reference to list blocks as this is an implementation detail.
# The content may diverge from list block content in future.
- include: list-block-content
###[ CONTAINER BLOCKS: BLOCK QUOTES ]#########################################
block-quotes:
# https://spec.commonmark.org/0.30/#block-quotes
- match: '[ \t]{,3}(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
push:
- block-quote-meta
- block-quote-body
- block-quote-punctuation-body
block-quote-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.markdown
- include: immediately-pop
block-quote-body:
- include: block-quote-end
- include: block-quote-punctuations
- include: block-quote-content
block-quote-content:
- include: indented-code-blocks
- include: block-quote-common
- include: block-quote-paragraph
block-quote-common:
- include: thematic-breaks
- include: atx-headings
- include: block-quote-reference-definitions
- include: block-quote-fenced-code-block
- include: block-quote-list-block
block-quote-end:
- match: ^(?!(?:[ \t]*>))
pop: 1
block-quote-punctuations:
- match: ^[ \t]{,3}(>)[ ]?
captures:
1: punctuation.definition.blockquote.markdown
push: block-quote-punctuation-body
block-quote-punctuation-body:
- include: block-quote-punctuation-content
- include: immediately-pop
block-quote-punctuation-content:
- match: '[ \t]{,3}(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
block-quote-nested-punctuations:
# Quotes signs in list items are not restricted by indentation level
# for technical reasons.
- match: ^[ \t]*(>)[ ]?
captures:
1: punctuation.definition.blockquote.markdown
push: block-quote-nested-punctuation-body
block-quote-nested-punctuation-body:
- include: block-quote-nested-punctuation-content
- include: immediately-pop
block-quote-nested-punctuation-content:
- match: '[ \t]*(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
###[ CONTAINER BLOCKS: BLOCK QUOTES > FENCED CODE BLOCKS ]####################
block-quote-fenced-code-block:
- match: |-
(?x)
{{fenced_code_block_start}}
{{fenced_code_block_language}}?
.*$\n? # all characters until EOL
captures:
0: meta.code-fence.definition.begin.text.markdown-gfm
2: punctuation.definition.raw.code-fence.begin.markdown
5: constant.other.language-name.markdown
push: block-quote-fenced-code-block-body
block-quote-fenced-code-block-body:
- include: block-quote-fenced-code-block-end
- include: block-quote-fenced-code-block-content
block-quote-fenced-code-block-content:
- include: block-quote-punctuation-content
- match: .*$\n?
scope: markup.raw.code-fence.markdown-gfm
block-quote-fenced-code-block-end:
- include: block-quote-end
- match: '{{fenced_code_block_end}}'
captures:
0: meta.code-fence.definition.end.text.markdown-gfm
1: punctuation.definition.raw.code-fence.end.markdown
pop: 1
###[ CONTAINER BLOCKS: BLOCK QUOTES > REFERENCE DEFINITIONS ]#################
block-quote-reference-definitions:
# https://spec.commonmark.org/0.30/#link-reference-definitions
- include: block-quote-footnote-definitions
- include: block-quote-link-definitions
block-quote-footnote-definitions:
# Mardown Extras Footnotes
- match: '([ \t]*)(\[)({{footnote_name}})(\])(:)'
captures:
2: punctuation.definition.reference.begin.markdown
3: entity.name.reference.link.markdown
4: punctuation.definition.reference.end.markdown
5: punctuation.separator.key-value.markdown
push: block-quote-footnote-def-body
block-quote-footnote-def-body:
- meta_scope: meta.link.reference.def.footnote.markdown-extra
- include: block-quote-footnote-def-end
- include: block-quote-punctuations
- include: block-quote-footnote-paragraphs
block-quote-footnote-def-end:
# A footnote definition is terminated by blocks not indented by at least 4 characters.
# Note: The first space after a quotation punctuation is not counted for simplicity reasons.
- match: ^(?!(?:[ \t]*>)+[ ](?:\1[ ]{4}|\s*$))
pop: 1
block-quote-footnote-paragraphs:
- match: '[ \t]*(?=\S)'
push: block-quote-footnote-paragraph-body
block-quote-footnote-paragraph-body:
- include: block-quote-footnote-paragraph-end
- include: block-quote-punctuations
- include: footnote-paragraph-common
block-quote-footnote-paragraph-end:
- match: |-
(?x)
# pop out of this context if one of the following conditions are met:
^(?= (?:[ \t]*>)* [ \t]*
(?: $ # the line is blank (or only contains whitespace)
| {{reference_definition}} # a reference definition begins the line
| {{atx_heading}} # an ATX heading begins the line
| {{fenced_code_block_start}} # a fenced codeblock begins the line
| {{thematic_break}} # line is a thematic beak
| {{list_item}} # a list item begins the line
| {{html_block}} # a html block begins the line
)
)
pop: 1
block-quote-link-definitions:
# https://spec.commonmark.org/0.30/#link-reference-definition
- match: '[ \t]*(\[)({{reference_name}})(\])(:)'
captures:
1: punctuation.definition.reference.begin.markdown
2: entity.name.reference.link.markdown
3: punctuation.definition.reference.end.markdown
4: punctuation.separator.key-value.markdown
push:
- block-quote-link-def-meta
- block-quote-link-def-title
- block-quote-link-def-url
block-quote-link-def-meta:
- meta_include_prototype: false
- meta_scope: meta.link.reference.def.markdown
- include: immediately-pop
block-quote-link-def-title:
- include: block-quote-nested-paragraph-end
- include: block-quote-punctuations
- include: link-title-begin
- include: else-pop
block-quote-link-def-url:
- include: block-quote-nested-paragraph-end
- include: block-quote-punctuations
- match: <
scope: punctuation.definition.link.begin.markdown
set: block-quote-link-def-url-angled
- match: (?=\S)
set: link-def-url-unquoted
block-quote-link-def-url-angled:
- meta_content_scope: markup.underline.link.markdown
- include: block-quote-punctuations
- include: link-url-angled
###[ CONTAINER BLOCKS: BLOCK QUOTES > LIST BLOCKS ]###########################
block-quote-list-block:
- match: ([ \t]*)([*+-])((?:[ ](\[)([ xX])(\]))?\s)
captures:
1: markup.list.unnumbered.markdown
2: markup.list.unnumbered.bullet.markdown punctuation.definition.list_item.markdown
3: markup.list.unnumbered.markdown
4: markup.checkbox.begin.markdown-gfm punctuation.definition.checkbox.begin.markdown-gfm
5: markup.checkbox.mark.markdown-gfm
6: markup.checkbox.end.markdown-gfm punctuation.definition.checkbox.end.markdown-gfm
set: block-quote-unordered-list-block-body
- match: ([ \t]*)(\d{1,9}([.)]))(\s)
captures:
1: markup.list.numbered.markdown
2: markup.list.numbered.bullet.markdown
3: punctuation.definition.list_item.markdown
4: markup.list.numbered.markdown
set: block-quote-ordered-list-block-body
block-quote-ordered-list-block-body:
- meta_content_scope: markup.list.numbered.markdown
- include: block-quote-list-block-end
- include: block-quote-list-block-content
block-quote-unordered-list-block-body:
- meta_content_scope: markup.list.unnumbered.markdown
- include: block-quote-list-block-end
- include: block-quote-list-block-content
block-quote-list-block-content:
- include: list-block-common
- include: block-quote-fenced-code-block
- include: block-quote-nested-punctuation-content
- include: block-quote-reference-definitions
- include: block-quote-list-paragraphs
block-quote-list-block-end:
- include: block-quote-end
# A list block ends with the first unindented text block.
# Note:
# This is a simplification as we can't count indentation levels.
# According to CommonMark, a list block ends as soon as a new paragraph
# starts which is less indented than the first list item's text.
- match: ^(?=(?:[ \t]*>)+[ ]?\S)
pop: 1
block-quote-list-paragraphs:
# A list paragraph doesn't support indented code blocks.
- match: '[ \t]*(?=\S)'
push: block-quote-list-paragraph-body
block-quote-list-paragraph-body:
- meta_scope: meta.paragraph.list.markdown
- include: block-quote-nested-paragraph-end
- include: block-quote-nested-punctuations
- include: inlines
block-quote-nested-paragraph-end:
- match: |-
(?x)
# pop out of this context if one of the following conditions are met:
^(?= (?:[ \t]*>)* [ \t]*
(?: $ # the line is blank (or only contains whitespace)
| {{atx_heading}} # an ATX heading begins the line
| {{fenced_code_block_start}} # a fenced codeblock begins the line
| {{thematic_break}} # line is a thematic beak
| {{list_item}} # a list item begins the line
| {{html_block}} # a html block begins the line
)
)
pop: 1
###[ CONTAINER BLOCKS: BLOCK QUOTES > PARAGRAPHS ]############################
block-quote-paragraph:
- match: '[ \t]*(?=\S)'
set: block-quote-paragraph-body
block-quote-paragraph-body:
- meta_scope: markup.paragraph.markdown
- include: block-quote-paragraph-end
- include: block-quote-punctuations
- include: inlines
block-quote-paragraph-end:
- match: |-
(?x)
# pop out of this context if one of the following conditions are met:
^(?= (?:[ \t]{,3}>)*
(?: \s* $ # the line is blank (or only contains whitespace)
| {{atx_heading}} # an ATX heading begins the line
| {{fenced_code_block_start}} # a fenced codeblock begins the line
| {{thematic_break}} # line is a thematic beak
| {{list_item}} # a list item begins the line
| {{html_block}} # a html block begins the line
)
)
pop: 1
###[ CONTAINER BLOCKS: LISTS ]################################################
list-blocks:
- match: ([ \t]*)([*+-])((?:[ ](\[)([ xX])(\]))?\s)
captures:
1: markup.list.unnumbered.markdown
2: markup.list.unnumbered.bullet.markdown punctuation.definition.list_item.markdown
3: markup.list.unnumbered.markdown
4: markup.checkbox.begin.markdown-gfm punctuation.definition.checkbox.begin.markdown-gfm
5: markup.checkbox.mark.markdown-gfm
6: markup.checkbox.end.markdown-gfm punctuation.definition.checkbox.end.markdown-gfm
push: unordered-list-block
- match: ([ \t]*)(\d{1,9}([.)]))(\s)
captures:
1: markup.list.numbered.markdown
2: markup.list.numbered.bullet.markdown
3: punctuation.definition.list_item.markdown
4: markup.list.numbered.markdown
push: ordered-list-block
unordered-list-block:
- meta_content_scope: markup.list.unnumbered.markdown
- include: list-block-end
- include: list-block-content
ordered-list-block:
- meta_content_scope: markup.list.numbered.markdown
- include: list-block-end
- include: list-block-content
list-block-end:
- match: ^(?=\S)
pop: 1
list-block-content:
- include: fenced-code-blocks
- include: html-blocks
- include: reference-definitions
- include: list-block-common
- include: list-block-quotes
- include: list-setext-headings-or-paragraphs
list-block-common:
- include: thematic-breaks
- include: atx-headings
- include: list-items
list-items:
- match: ([ \t]*)([*+-])((?:[ ](\[)([ xX])(\]))?\s)
captures:
1: markup.list.unnumbered.markdown
2: markup.list.unnumbered.bullet.markdown punctuation.definition.list_item.markdown
3: markup.list.unnumbered.markdown
4: markup.checkbox.begin.markdown-gfm punctuation.definition.checkbox.begin.markdown-gfm
5: markup.checkbox.mark.markdown-gfm
6: markup.checkbox.end.markdown-gfm punctuation.definition.checkbox.end.markdown-gfm
- match: ([ \t]*)(\d{1,9}([.)]))(\s)
captures:
1: markup.list.numbered.markdown
2: markup.list.numbered.bullet.markdown
3: punctuation.definition.list_item.markdown
4: markup.list.numbered.markdown
list-block-quotes:
- match: '[ \t]*(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
push:
- block-quote-meta
- list-block-quote-body
- block-quote-punctuation-body
list-block-quote-body:
- include: block-quote-end
- include: list-block-quote-punctuations
- include: list-block-quote-content
list-block-quote-content:
- include: indented-code-blocks
- include: block-quote-common
- include: list-block-quote-paragraph
list-block-quote-punctuations:
- match: ^[ \t]*(>)[ ]?
captures:
1: punctuation.definition.blockquote.markdown
push: block-quote-punctuation-body
list-block-quote-paragraph:
- match: '[ \t]*(?=\S)'
set: list-block-quote-paragraph-body
list-block-quote-paragraph-body:
- meta_scope: markup.paragraph.markdown
- include: block-quote-nested-paragraph-end
- include: list-block-quote-punctuations
- include: inlines
list-setext-headings-or-paragraphs:
# A paragraph may start with a line of equal signs which must not be matched
# as heading underline. This is achieved by consuming them here, which also
# applies `meta.paragraph` scope as expected.
# A line of dashes is already matched as thematic break and thus ignored.
- match: '{{list_setext_heading_or_paragraph}}'
branch_point: list-setext-headings-or-paragraphs
branch:
- list-paragraph
- list-setext-heading2
- list-setext-heading1
list-setext-heading1:
# https://spec.commonmark.org/0.30/#setext-headings
- meta_scope: markup.heading.1.markdown
- meta_content_scope: entity.name.section.markdown
- match: '{{list_setext_heading1_end}}'
captures:
1: punctuation.definition.heading.setext.markdown
2: meta.whitespace.newline.markdown
pop: 1
- include: setext-heading-content
list-setext-heading2:
# https://spec.commonmark.org/0.30/#setext-headings
- meta_scope: markup.heading.2.markdown
- meta_content_scope: entity.name.section.markdown
- match: '{{list_setext_heading2_end}}'
captures:
1: punctuation.definition.heading.setext.markdown
2: meta.whitespace.newline.markdown
pop: 1
- match: '{{list_setext_heading1_escape}}'
fail: list-setext-headings-or-paragraphs
- include: setext-heading-content
list-paragraph:
# https://spec.commonmark.org/0.30/#paragraphs
- meta_scope: meta.paragraph.list.markdown
- include: list-paragraph-fail
- include: list-paragraph-end
- include: list-math-blocks
- include: inlines
list-paragraph-end:
- match: '{{list_paragraph_end}}'
pop: 1
list-paragraph-fail:
- match: '{{list_setext_heading_escape}}'
fail: list-setext-headings-or-paragraphs
###[ LEAF BLOCKS: ATX HEADINGS ]##############################################
atx-headings:
# https://spec.commonmark.org/0.30/#atx-headings
# Note:
# Consume spaces and tabs after opening hashes so entity.name
# starts with first non-whitespace character,
# but don't do so if directly followed by closing hashes
# as terminator pattern requires them to match then.
- match: '[ \t]*(#{1}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading1-content
- match: '[ \t]*(#{2}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading2-content
- match: '[ \t]*(#{3}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading3-content
- match: '[ \t]*(#{4}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading4-content
- match: '[ \t]*(#{5}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading5-content
- match: '[ \t]*(#{6}){{atx_heading_space}}'
captures:
1: punctuation.definition.heading.begin.markdown
push: atx-heading6-content
atx-heading1-content:
- meta_scope: markup.heading.1.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading2-content:
- meta_scope: markup.heading.2.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading3-content:
- meta_scope: markup.heading.3.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading4-content:
- meta_scope: markup.heading.4.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading5-content:
- meta_scope: markup.heading.5.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading6-content:
- meta_scope: markup.heading.6.markdown
- meta_content_scope: entity.name.section.markdown
- include: atx-heading-content
atx-heading-content:
- match: '{{atx_heading_end}}'
captures:
1: punctuation.definition.heading.end.markdown
2: meta.whitespace.newline.markdown
pop: 1
- include: emphasis
- include: images
- include: literals
- include: links
- include: markups
###[ LEAF BLOCKS: SETEXT HEADINGS OR PARAGRAPH ]##############################
setext-headings-or-paragraphs:
# A paragraph may start with a line of equal signs which must not be matched
# as heading underline. This is achieved by consuming them here, which also
# applies `meta.paragraph` scope as expected.
# A line of dashes is already matched as thematic break and thus ignored.
- match: '{{setext_heading_or_paragraph}}'
branch_point: setext-headings-or-paragraphs
branch:
- paragraph
- setext-heading2
- setext-heading1
setext-heading1:
# https://spec.commonmark.org/0.30/#setext-headings
- meta_scope: markup.heading.1.markdown
- meta_content_scope: entity.name.section.markdown
- match: '{{setext_heading1_end}}'
captures:
1: punctuation.definition.heading.setext.markdown
2: meta.whitespace.newline.markdown
pop: 1
- include: setext-heading-content
setext-heading2:
# https://spec.commonmark.org/0.30/#setext-headings
- meta_scope: markup.heading.2.markdown
- meta_content_scope: entity.name.section.markdown
- match: '{{setext_heading2_end}}'
captures:
1: punctuation.definition.heading.setext.markdown
2: meta.whitespace.newline.markdown
pop: 1
- match: '{{setext_heading1_escape}}'
fail: setext-headings-or-paragraphs
- include: setext-heading-content
setext-heading-content:
- include: setext-hard-line-breaks
- include: emphasis
- include: images
- include: literals
- include: links
- include: markups
setext-hard-line-breaks:
# This context consumes what 'hard-line-breaks' does for normal
# paragraphs to avoid deadlock of ST's syntax engine.
#
# as workaround for
# https://github.com/sublimehq/sublime_text/issues/5415
# causing
# https://github.com/sublimehq/Packages/issues/3494
- match: '[ ]{2,}$'
- match: '\\\n'
paragraph:
# https://spec.commonmark.org/0.30/#paragraphs
- meta_scope: meta.paragraph.markdown
- include: paragraph-fail
- include: paragraph-end
- include: math-blocks
- include: inlines
paragraph-end:
- match: '{{paragraph_end}}'
pop: 1
paragraph-fail:
- match: '{{setext_heading_escape}}'
fail: setext-headings-or-paragraphs
###[ LEAF BLOCKS: INDENTED CODE BLOCKS ]######################################
indented-code-blocks:
# https://spec.commonmark.org/0.30/#indented-code-blocks
- match: '{{indented_code_block}}'
push: indented-code-block-body
indented-code-block-body:
- meta_scope: markup.raw.block.markdown
- match: \n
pop: 1
###[ LEAF BLOCKS: FENCED CODE BLOCKS ]########################################
fenced-code-blocks:
# https://spec.commonmark.org/0.30/#fenced-code-blocks
- match: (?={{fenced_code_block_start}})
push: fenced-code-block-content
fenced-code-block-content:
- match: $
pop: 1
- include: fenced-syntaxes
- include: fenced-raw
fenced-syntaxes:
- include: fenced-actionscript
- include: fenced-applescript
- include: fenced-clojure
- include: fenced-c
- include: fenced-cpp
- include: fenced-csharp
- include: fenced-css
- include: fenced-diff
- include: fenced-dosbatch
- include: fenced-erlang
- include: fenced-graphviz
- include: fenced-golang
- include: fenced-haskell
- include: fenced-html-php
- include: fenced-html
- include: fenced-java
- include: fenced-javascript
- include: fenced-jsonc
- include: fenced-jspx
- include: fenced-jsx
- include: fenced-lisp
- include: fenced-lua
- include: fenced-makefile
- include: fenced-matlab
- include: fenced-objc
- include: fenced-objcpp
- include: fenced-ocaml
- include: fenced-perl
- include: fenced-php