Skip to content

Commit

Permalink
[Markdown] Simplify context structure
Browse files Browse the repository at this point in the history
This commit drops pushing dedicated `fenced-div-body` to workaround
hitting pattern repetition sanity limits of which reason is not yet clear.
  • Loading branch information
deathaxe committed Feb 8, 2025
1 parent ba42d70 commit 6df7e4d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Markdown/Fold.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.block.begin.markdown</string>
<string>punctuation.section.div.begin.markdown</string>
<key>end</key>
<string>punctuation.section.block.end.markdown</string>
<string>punctuation.section.div.end.markdown</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
Expand Down
24 changes: 10 additions & 14 deletions Markdown/Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ variables:
fenced_code_block_escape: ^{{fenced_code_block_end}}

# https://pandoc.org/MANUAL.html#divs-and-spans
fenced_div_block: :{3,}
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])?'
Expand Down Expand Up @@ -769,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 @@ -3520,11 +3521,14 @@ contexts:

fenced-div-blocks:
# https://pandoc.org/MANUAL.html#divs-and-spans
- match: ^[ \t]*({{fenced_div_block}})[ \t]*(?=\S)
- 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.block.begin.markdown
1: punctuation.section.div.begin.markdown
push:
- fenced-div-body
- fenced-div-puncuation
- fenced-div-attr

Expand All @@ -3542,20 +3546,12 @@ contexts:

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

fenced-div-body:
- meta_include_prototype: false
- meta_scope: meta.block.div.markdown
- match: ^[ \t]*(\1)(\s*\n)
captures:
1: punctuation.section.block.end.markdown
pop: 1
- include: markdown

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

else-pop:
Expand Down
104 changes: 73 additions & 31 deletions Markdown/tests/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9040,75 +9040,117 @@ Handle incomplete $\sqrt{b$ expressions well.
# TEST: PANDOC FENCED DIVS ####################################################
| Opening div tags must have attributes
:::
| <- - punctuation
|^^ - punctuation
::: class
| <- meta.block.div.markdown punctuation.section.block.begin.markdown
|^^^^^^^^ meta.block.div.markdown - meta.block meta.block
|^^ punctuation.section.block.begin.markdown
| <- 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
|^^^^^ meta.block.div.markdown
|^^^^^ markup.list.unnumbered.markdown
| ^^^^ meta.paragraph.list.markdown
- list
|^^^^^ meta.block.div.markdown
|^^^^^ markup.list.unnumbered.markdown
| ^^^^ meta.paragraph.list.markdown
:::
| <- meta.block.div.markdown punctuation.section.block.end.markdown
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown
---
::: {.class #id} :::
|^^^^^^^^^^^^^^^^^^^ meta.block.div.markdown
|^^ punctuation.section.block.begin.markdown
|^^^^^^^^^^^^^^^^^^^ 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.block.markdown
| ^^^ punctuation.section.div.markdown
::: inner
|^^^^^^^^ meta.block.div.markdown meta.block.div.markdown
|^^ punctuation.section.block.begin.markdown
|^^^^^^^^ meta.div.markdown
|^^ punctuation.section.div.begin.markdown
| ^^^^^ meta.attribute-with-value.markdown entity.other.attribute-name.markdown
paragraph
|^^^^^^^^ meta.block.div.markdown meta.block.div.markdown meta.paragraph.markdown
|^^^^^^^^ meta.paragraph.markdown
:::
|^^ meta.block.div.markdown meta.block.div.markdown punctuation.section.block.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown
| ^ meta.div.markdown - punctuation
:::
|^^ meta.block.div.markdown punctuation.section.block.end.markdown - meta.block meta.block
|^^ meta.div.markdown punctuation.section.div.end.markdown
| ^ meta.div.markdown - punctuation
---
::: block-quote
> quoted block
|^^^^^^^^^^^^^ meta.block.div.markdown markup.quote.markdown
|^^^^^^^^^^^^^ markup.quote.markdown
| ^^^^^^^^^^^^ markup.paragraph.markdown
> > nested quote
| <- meta.block.div.markdown markup.quote.markdown markup.paragraph.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^^^^ meta.block.div.markdown markup.quote.markdown markup.paragraph.markdown
| <- markup.quote.markdown markup.paragraph.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^^^^ markup.quote.markdown markup.paragraph.markdown
| ^ punctuation.definition.blockquote.markdown
:::
| <- meta.block.div.markdown punctuation.section.block.end.markdown
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown
---
::: code-block
```css
|^^^^^ meta.block.div.markdown meta.code-fence.definition.begin.css.markdown-gfm
|^^^^^ meta.code-fence.definition.begin.css.markdown-gfm
|^^ punctuation.definition.raw.code-fence.begin.markdown
| ^^^ constant.other.language-name.markdown
```
:::
| <- meta.block.div.markdown punctuation.section.block.end.markdown
|^^ meta.block.div.markdown punctuation.section.block.end.markdown
| <- meta.div.markdown punctuation.section.div.end.markdown
|^^ meta.div.markdown punctuation.section.div.end.markdown
---
::: table
| column | column
| --- | ---
| foo | bar
| <- meta.block.div.markdown meta.table.markdown-gfm punctuation.separator.table-cell.markdown
| <- meta.table.markdown-gfm punctuation.separator.table-cell.markdown
:::
| <- meta.block.div.markdown punctuation.section.block.end.markdown
|^^ meta.block.div.markdown punctuation.section.block.end.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
---
::: indendet-code-block
| <- markup.raw.block.markdown
|^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.raw.block.markdown
::: indendet-code-block
code
:::
|<- markup.raw.block.markdown
|^^^^^^^ markup.raw.block.markdown

0 comments on commit 6df7e4d

Please sign in to comment.