Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Markdown] Add support for fenced divs #4146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Markdown/Fold.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<key>excludeTrailingNewlines</key>
<true/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.div.begin.markdown</string>
<key>end</key>
<string>punctuation.section.div.end.markdown</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
</array>
</dict>
</dict>
Expand Down
48 changes: 47 additions & 1 deletion Markdown/Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ variables:
)
fenced_code_block_escape: ^{{fenced_code_block_end}}

# https://pandoc.org/MANUAL.html#divs-and-spans
fenced_div_block: '[ \t]*(:{3,})'

# 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.!#$%&''*+/=?^_`{|}~-]+'
Expand Down Expand Up @@ -262,6 +265,7 @@ variables:
| {{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
| {{fenced_div_block}} # a fenced div block 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
Expand All @@ -275,6 +279,7 @@ variables:
| {{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
| {{fenced_div_block}} # a fenced div block 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
Expand Down Expand Up @@ -347,6 +352,7 @@ contexts:
- include: list-blocks
- include: tables
- include: fenced-code-blocks
- include: fenced-div-blocks
- include: html-blocks
- include: reference-definitions
- include: atx-headings
Expand Down Expand Up @@ -579,6 +585,7 @@ contexts:
| {{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
| {{fenced_div_block}} # a fenced div block 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
Expand Down Expand Up @@ -690,6 +697,7 @@ contexts:
(?: $ # 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
| {{fenced_div_block}} # a fenced div block 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
Expand Down Expand Up @@ -717,6 +725,7 @@ contexts:
(?: \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
| {{fenced_div_block}} # a fenced div block 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
Expand Down Expand Up @@ -760,6 +769,7 @@ contexts:

list-block-content:
- include: fenced-code-blocks
- include: fenced-div-blocks
- include: html-blocks
- include: reference-definitions
- include: list-block-common
Expand Down Expand Up @@ -2249,6 +2259,7 @@ contexts:
| {{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
| {{fenced_div_block}} # a fenced div block 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
Expand Down Expand Up @@ -2364,6 +2375,7 @@ contexts:
| {{atx_heading}}
| {{block_quote}}
| {{fenced_code_block_start}}
| {{fenced_div_block}}
| {{indented_code_block}}
| {{thematic_break}}
)
Expand Down Expand Up @@ -3505,6 +3517,41 @@ contexts:
- include: scope:text.tex.latex#macros
- include: scope:text.tex.latex#math-content

###[ EXTENSIONS: PANDOC FENCED DIVS ]##########################################

fenced-div-blocks:
# https://pandoc.org/MANUAL.html#divs-and-spans
- match: '{{fenced_div_block}}[ \t]*$\n?'
scope: meta.div.markdown
captures:
1: punctuation.section.div.end.markdown
- match: '{{fenced_div_block}}'
captures:
1: punctuation.section.div.begin.markdown
push:
- fenced-div-puncuation
- fenced-div-attr

fenced-div-attr:
- meta_include_prototype: false
- match: \{
scope: punctuation.definition.attributes.begin.markdown
set: link-def-attr-body
- match: '{{tag_attribute_name_start}}'
set:
- tag-attr-meta
- tag-attr-equals
- tag-attr-name
- match: else-pop

fenced-div-puncuation:
- meta_include_prototype: false
- meta_scope: meta.div.markdown
- match: ':+'
scope: punctuation.section.div.markdown
pop: 1
- include: else-pop

###[ PROTOTYPES ]#############################################################

else-pop:
Expand All @@ -3523,4 +3570,3 @@ contexts:
immediately-pop:
- match: ''
pop: 1

117 changes: 117 additions & 0 deletions Markdown/tests/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9037,3 +9037,120 @@ Handle incomplete $\sqrt{b$ expressions well.
| ^^ meta.group.brace
| ^ punctuation.definition.math.end - meta.group
| ^ meta.paragraph.list.markdown - markup.math

# TEST: PANDOC FENCED DIVS ####################################################

::: class
| <- meta.div.markdown punctuation.section.div.begin.markdown
|^^^^^^^^ meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
- list
|^^^^^ markup.list.unnumbered.markdown
| ^^^^ meta.paragraph.list.markdown
- list
|^^^^^ markup.list.unnumbered.markdown
| ^^^^ meta.paragraph.list.markdown
:::
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown

---

::: {.class #id} :::
|^^^^^^^^^^^^^^^^^^^ meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^^^^^^^^^^ meta.attributes.markdown
| ^ punctuation.definition.attributes.begin.markdown
| ^^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
| ^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
| ^ punctuation.definition.attributes.end.markdown
| ^^^ punctuation.section.div.markdown
::: inner
|^^^^^^^^ meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
paragraph
|^^^^^^^^ meta.paragraph.markdown
:::
|^^ meta.div.markdown punctuation.section.div.end.markdown
| ^ meta.div.markdown - punctuation
:::
|^^ meta.div.markdown punctuation.section.div.end.markdown
| ^ meta.div.markdown - punctuation

---

::: block-quote
> quoted block
|^^^^^^^^^^^^^ markup.quote.markdown
| ^^^^^^^^^^^^ markup.paragraph.markdown
> > nested quote
| <- markup.quote.markdown markup.paragraph.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^^^^ markup.quote.markdown markup.paragraph.markdown
| ^ punctuation.definition.blockquote.markdown
:::
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown

---

::: code-block
```css
|^^^^^ meta.code-fence.definition.begin.css.markdown-gfm
|^^ punctuation.definition.raw.code-fence.begin.markdown
| ^^^ constant.other.language-name.markdown
```
:::
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown

---

::: table
| column | column
| --- | ---
| foo | bar
| <- meta.table.markdown-gfm punctuation.separator.table-cell.markdown
:::
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ punctuation.section.div.end.markdown

---

1. ordered list item

::: div
| <- markup.list.numbered.markdown meta.div.markdown punctuation.section.div.begin.markdown
|^^^^^^ markup.list.numbered.markdown meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
:::
| <- markup.list.numbered.markdown meta.div.markdown punctuation.section.div.end.markdown
|^^^ markup.list.numbered.markdown meta.div.markdown
|^^ punctuation.section.div.end.markdown

---

- unordered list item

::: div
| <- markup.list.unnumbered.markdown meta.div.markdown punctuation.section.div.begin.markdown
|^^^^^^ markup.list.unnumbered.markdown meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
:::
|^^^ markup.list.unnumbered.markdown meta.div.markdown
|^^ punctuation.section.div.end.markdown

---

::: indented-code-block
| <- markup.raw.block.markdown
|^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.raw.block.markdown

::: indented-code-block
code
:::
|<- markup.raw.block.markdown
|^^^^^^^ markup.raw.block.markdown