Skip to content

Commit ba42d70

Browse files
committed
[Markdown] Add support for fenced divs
This commit aligns Markdown adds patterns for Pandoc fenced divs. see: https://pandoc.org/MANUAL.html#divs-and-spans
1 parent df76b02 commit ba42d70

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed

Markdown/Fold.tmPreferences

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<key>excludeTrailingNewlines</key>
2424
<true/>
2525
</dict>
26+
<dict>
27+
<key>begin</key>
28+
<string>punctuation.section.block.begin.markdown</string>
29+
<key>end</key>
30+
<string>punctuation.section.block.end.markdown</string>
31+
<key>excludeTrailingNewlines</key>
32+
<false/>
33+
</dict>
2634
</array>
2735
</dict>
2836
</dict>

Markdown/Markdown.sublime-syntax

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ variables:
172172
)
173173
fenced_code_block_escape: ^{{fenced_code_block_end}}
174174

175+
# https://pandoc.org/MANUAL.html#divs-and-spans
176+
fenced_div_block: :{3,}
177+
175178
# https://spec.commonmark.org/0.30/#email-autolink
176179
email_domain_commonmark: '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'
177180
email_user_commonmark: '[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+'
@@ -262,6 +265,7 @@ variables:
262265
| {{block_quote}} # a blockquote begins the line
263266
| {{atx_heading}} # an ATX heading begins the line
264267
| {{fenced_code_block_start}} # a fenced codeblock begins the line
268+
| {{fenced_div_block}} # a fenced div block begins the line
265269
| {{thematic_break}} # line is a thematic beak
266270
| {{first_list_item}} # a list item begins the line
267271
| {{html_block}} # a html block begins the line
@@ -275,6 +279,7 @@ variables:
275279
| {{block_quote}} # a blockquote begins the line
276280
| {{atx_heading}} # an ATX heading begins the line
277281
| {{fenced_code_block_start}} # a fenced codeblock begins the line
282+
| {{fenced_div_block}} # a fenced div block begins the line
278283
| {{thematic_break}} # line is a thematic beak
279284
| {{list_item}} # a list item begins the line
280285
| {{html_block}} # a html block begins the line
@@ -347,6 +352,7 @@ contexts:
347352
- include: list-blocks
348353
- include: tables
349354
- include: fenced-code-blocks
355+
- include: fenced-div-blocks
350356
- include: html-blocks
351357
- include: reference-definitions
352358
- include: atx-headings
@@ -579,6 +585,7 @@ contexts:
579585
| {{reference_definition}} # a reference definition begins the line
580586
| {{atx_heading}} # an ATX heading begins the line
581587
| {{fenced_code_block_start}} # a fenced codeblock begins the line
588+
| {{fenced_div_block}} # a fenced div block begins the line
582589
| {{thematic_break}} # line is a thematic beak
583590
| {{list_item}} # a list item begins the line
584591
| {{html_block}} # a html block begins the line
@@ -690,6 +697,7 @@ contexts:
690697
(?: $ # the line is blank (or only contains whitespace)
691698
| {{atx_heading}} # an ATX heading begins the line
692699
| {{fenced_code_block_start}} # a fenced codeblock begins the line
700+
| {{fenced_div_block}} # a fenced div block begins the line
693701
| {{thematic_break}} # line is a thematic beak
694702
| {{list_item}} # a list item begins the line
695703
| {{html_block}} # a html block begins the line
@@ -717,6 +725,7 @@ contexts:
717725
(?: \s* $ # the line is blank (or only contains whitespace)
718726
| {{atx_heading}} # an ATX heading begins the line
719727
| {{fenced_code_block_start}} # a fenced codeblock begins the line
728+
| {{fenced_div_block}} # a fenced div block begins the line
720729
| {{thematic_break}} # line is a thematic beak
721730
| {{list_item}} # a list item begins the line
722731
| {{html_block}} # a html block begins the line
@@ -2249,6 +2258,7 @@ contexts:
22492258
| {{reference_definition}} # a reference definition begins the line
22502259
| {{atx_heading}} # an ATX heading begins the line
22512260
| {{fenced_code_block_start}} # a fenced codeblock begins the line
2261+
| {{fenced_div_block}} # a fenced div block begins the line
22522262
| {{thematic_break}} # line is a thematic beak
22532263
| {{list_item}} # a list item begins the line
22542264
| {{html_block}} # a html block begins the line
@@ -2364,6 +2374,7 @@ contexts:
23642374
| {{atx_heading}}
23652375
| {{block_quote}}
23662376
| {{fenced_code_block_start}}
2377+
| {{fenced_div_block}}
23672378
| {{indented_code_block}}
23682379
| {{thematic_break}}
23692380
)
@@ -3505,6 +3516,46 @@ contexts:
35053516
- include: scope:text.tex.latex#macros
35063517
- include: scope:text.tex.latex#math-content
35073518

3519+
###[ EXTENSIONS: PANDOC FENCED DIVS ]##########################################
3520+
3521+
fenced-div-blocks:
3522+
# https://pandoc.org/MANUAL.html#divs-and-spans
3523+
- match: ^[ \t]*({{fenced_div_block}})[ \t]*(?=\S)
3524+
captures:
3525+
1: punctuation.section.block.begin.markdown
3526+
push:
3527+
- fenced-div-body
3528+
- fenced-div-puncuation
3529+
- fenced-div-attr
3530+
3531+
fenced-div-attr:
3532+
- meta_include_prototype: false
3533+
- match: \{
3534+
scope: punctuation.definition.attributes.begin.markdown
3535+
set: link-def-attr-body
3536+
- match: '{{tag_attribute_name_start}}'
3537+
set:
3538+
- tag-attr-meta
3539+
- tag-attr-equals
3540+
- tag-attr-name
3541+
- match: else-pop
3542+
3543+
fenced-div-puncuation:
3544+
- meta_include_prototype: false
3545+
- match: ':+'
3546+
scope: punctuation.section.block.markdown
3547+
pop: 1
3548+
- include: else-pop
3549+
3550+
fenced-div-body:
3551+
- meta_include_prototype: false
3552+
- meta_scope: meta.block.div.markdown
3553+
- match: ^[ \t]*(\1)(\s*\n)
3554+
captures:
3555+
1: punctuation.section.block.end.markdown
3556+
pop: 1
3557+
- include: markdown
3558+
35083559
###[ PROTOTYPES ]#############################################################
35093560

35103561
else-pop:
@@ -3523,4 +3574,3 @@ contexts:
35233574
immediately-pop:
35243575
- match: ''
35253576
pop: 1
3526-

Markdown/tests/syntax_test_markdown.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9037,3 +9037,78 @@ Handle incomplete $\sqrt{b$ expressions well.
90379037
| ^^ meta.group.brace
90389038
| ^ punctuation.definition.math.end - meta.group
90399039
| ^ meta.paragraph.list.markdown - markup.math
9040+
9041+
# TEST: PANDOC FENCED DIVS ####################################################
9042+
9043+
| Opening div tags must have attributes
9044+
:::
9045+
| <- - punctuation
9046+
|^^ - punctuation
9047+
9048+
::: class
9049+
| <- meta.block.div.markdown punctuation.section.block.begin.markdown
9050+
|^^^^^^^^ meta.block.div.markdown - meta.block meta.block
9051+
|^^ punctuation.section.block.begin.markdown
9052+
| ^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
9053+
- list
9054+
|^^^^^ meta.block.div.markdown
9055+
|^^^^^ markup.list.unnumbered.markdown
9056+
| ^^^^ meta.paragraph.list.markdown
9057+
- list
9058+
|^^^^^ meta.block.div.markdown
9059+
|^^^^^ markup.list.unnumbered.markdown
9060+
| ^^^^ meta.paragraph.list.markdown
9061+
:::
9062+
| <- meta.block.div.markdown punctuation.section.block.end.markdown
9063+
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
9064+
9065+
::: {.class #id} :::
9066+
|^^^^^^^^^^^^^^^^^^^ meta.block.div.markdown
9067+
|^^ punctuation.section.block.begin.markdown
9068+
| ^^^^^^^^^^^^ meta.attributes.markdown
9069+
| ^ punctuation.definition.attributes.begin.markdown
9070+
| ^^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
9071+
| ^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
9072+
| ^ punctuation.definition.attributes.end.markdown
9073+
| ^^^ punctuation.section.block.markdown
9074+
::: inner
9075+
|^^^^^^^^ meta.block.div.markdown meta.block.div.markdown
9076+
|^^ punctuation.section.block.begin.markdown
9077+
| ^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
9078+
paragraph
9079+
|^^^^^^^^ meta.block.div.markdown meta.block.div.markdown meta.paragraph.markdown
9080+
:::
9081+
|^^ meta.block.div.markdown meta.block.div.markdown punctuation.section.block.end.markdown
9082+
:::
9083+
|^^ meta.block.div.markdown punctuation.section.block.end.markdown - meta.block meta.block
9084+
9085+
::: block-quote
9086+
> quoted block
9087+
|^^^^^^^^^^^^^ meta.block.div.markdown markup.quote.markdown
9088+
| ^^^^^^^^^^^^ markup.paragraph.markdown
9089+
> > nested quote
9090+
| <- meta.block.div.markdown markup.quote.markdown markup.paragraph.markdown punctuation.definition.blockquote.markdown
9091+
|^^^^^^^^^^^^^^^ meta.block.div.markdown markup.quote.markdown markup.paragraph.markdown
9092+
| ^ punctuation.definition.blockquote.markdown
9093+
:::
9094+
| <- meta.block.div.markdown punctuation.section.block.end.markdown
9095+
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
9096+
9097+
::: code-block
9098+
```css
9099+
|^^^^^ meta.block.div.markdown meta.code-fence.definition.begin.css.markdown-gfm
9100+
|^^ punctuation.definition.raw.code-fence.begin.markdown
9101+
| ^^^ constant.other.language-name.markdown
9102+
```
9103+
:::
9104+
| <- meta.block.div.markdown punctuation.section.block.end.markdown
9105+
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
9106+
9107+
::: table
9108+
| column | column
9109+
| --- | ---
9110+
| foo | bar
9111+
| <- meta.block.div.markdown meta.table.markdown-gfm punctuation.separator.table-cell.markdown
9112+
:::
9113+
| <- meta.block.div.markdown punctuation.section.block.end.markdown
9114+
|^^ meta.block.div.markdown punctuation.section.block.end.markdown

0 commit comments

Comments
 (0)