Skip to content

Commit

Permalink
[Markdown] Add GitHub Alerts syntax (#3892)
Browse files Browse the repository at this point in the history
* [Markdown] Add GitHub Alerts syntax

Resolves #3891

* [Markdown] Exclude block quote headings from symbol lists

Block quotes may contain headings, which are not related with normal
documentation structure. Thus exclude them from symbol lists and index.
  • Loading branch information
deathaxe authored Dec 29, 2023
1 parent ba620ca commit e420984
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 1 deletion.
125 changes: 125 additions & 0 deletions Markdown/Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,56 @@ contexts:

block-quotes:
# https://spec.commonmark.org/0.30/#block-quotes
- match: '[ \t]{,3}(>)[ ]?((\[)!CAUTION(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.caution.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-caution-meta
- block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!WARNING(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.warning.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-warning-meta
- block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!IMPORTANT(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.important.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-important-meta
- block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!NOTE(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.note.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-note-meta
- block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!TIP(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.tip.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-tip-meta
- block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
Expand All @@ -362,6 +412,31 @@ contexts:
- block-quote-body
- block-quote-punctuation-body

block-quote-caution-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.alert.caution.markdown
- include: immediately-pop

block-quote-warning-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.alert.warning.markdown
- include: immediately-pop

block-quote-important-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.alert.important.markdown
- include: immediately-pop

block-quote-note-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.alert.note.markdown
- include: immediately-pop

block-quote-tip-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.alert.tip.markdown
- include: immediately-pop

block-quote-meta:
- meta_include_prototype: false
- meta_scope: markup.quote.markdown
Expand Down Expand Up @@ -709,6 +784,56 @@ contexts:
4: markup.list.numbered.markdown

list-block-quotes:
- match: '[ \t]{,3}(>)[ ]?((\[)!CAUTION(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.caution.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-caution-meta
- list-block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!WARNING(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.warning.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-warning-meta
- list-block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!IMPORTANT(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.important.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-important-meta
- list-block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!NOTE(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.note.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-note-meta
- list-block-quote-body
- block-quote-punctuation-body
- match: '[ \t]{,3}(>)[ ]?((\[)!TIP(\]))'
captures:
1: punctuation.definition.blockquote.markdown
2: markup.heading.alert.tip.markdown
3: punctuation.definition.heading.begin.markdown
4: punctuation.definition.heading.end.markdown
push:
- block-quote-tip-meta
- list-block-quote-body
- block-quote-punctuation-body
- match: '[ \t]*(>)[ ]?'
captures:
1: punctuation.definition.blockquote.markdown
Expand Down
2 changes: 1 addition & 1 deletion Markdown/Symbol List - Heading.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plist version="1.0">
<dict>
<key>scope</key>
<string>text.html.markdown markup.heading - meta.whitespace.newline.markdown</string>
<string>text.html.markdown markup.heading - markup.quote - meta.whitespace.newline.markdown</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
Expand Down
149 changes: 149 additions & 0 deletions Markdown/tests/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -8193,6 +8193,155 @@ This is a [[wiki link]].
| ^^ punctuation.definition.link.end.markdown
# TEST: GITHUB ALERTS #########################################################
> [!CAUTION]
| <- markup.quote.alert.caution.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^ markup.quote.alert.caution.markdown
| ^^^^^^^^^^ markup.heading.alert.caution.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!CAUTION]
>
> Text
| <- markup.quote.alert.caution.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.caution.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.caution.markdown markup.paragraph.markdown
> [!WARNING]
| <- markup.quote.alert.warning.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^ markup.quote.alert.warning.markdown
| ^^^^^^^^^^ markup.heading.alert.warning.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!WARNING]
>
> Text
| <- markup.quote.alert.warning.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.warning.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.warning.markdown markup.paragraph.markdown
> [!IMPORTANT]
| <- markup.quote.alert.important.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^^^ markup.quote.alert.important.markdown
| ^^^^^^^^^^^^ markup.heading.alert.important.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!IMPORTANT]
>
> Text
| <- markup.quote.alert.important.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.important.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.important.markdown markup.paragraph.markdown
> [!NOTE]
| <- markup.quote.alert.note.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^ markup.quote.alert.note.markdown
| ^^^^^^^ markup.heading.alert.note.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!NOTE]
>
> Text
| <- markup.quote.alert.note.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.note.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.note.markdown markup.paragraph.markdown
> [!TIP]
| <- markup.quote.alert.tip.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^ markup.quote.alert.tip.markdown
| ^^^^^^ markup.heading.alert.tip.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!TIP]
>
> Text
| <- markup.quote.alert.tip.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.tip.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.tip.markdown markup.paragraph.markdown
1. list item
> [!CAUTION]
| <- markup.quote.alert.caution.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^ markup.quote.alert.caution.markdown
| ^^^^^^^^^^ markup.heading.alert.caution.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!CAUTION]
>
> Text
| <- markup.quote.alert.caution.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.caution.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.caution.markdown markup.paragraph.markdown
1. list item
> [!WARNING]
| <- markup.quote.alert.warning.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^ markup.quote.alert.warning.markdown
| ^^^^^^^^^^ markup.heading.alert.warning.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!WARNING]
>
> Text
| <- markup.quote.alert.warning.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.warning.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.warning.markdown markup.paragraph.markdown
1. list item
> [!IMPORTANT]
| <- markup.quote.alert.important.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^^^^^^ markup.quote.alert.important.markdown
| ^^^^^^^^^^^^ markup.heading.alert.important.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!IMPORTANT]
>
> Text
| <- markup.quote.alert.important.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.important.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.important.markdown markup.paragraph.markdown
1. list item
> [!NOTE]
| <- markup.quote.alert.note.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^^ markup.quote.alert.note.markdown
| ^^^^^^^ markup.heading.alert.note.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!NOTE]
>
> Text
| <- markup.quote.alert.note.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.note.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.note.markdown markup.paragraph.markdown
1. list item
> [!TIP]
| <- markup.quote.alert.tip.markdown punctuation.definition.blockquote.markdown
|^^^^^^^^ markup.quote.alert.tip.markdown
| ^^^^^^ markup.heading.alert.tip.markdown
| ^ punctuation.definition.heading.begin.markdown
| ^ punctuation.definition.heading.end.markdown
> [!TIP]
>
> Text
| <- markup.quote.alert.tip.markdown punctuation.definition.blockquote.markdown
|^ markup.quote.alert.tip.markdown - markup.paragraph
| ^^^^^ markup.quote.alert.tip.markdown markup.paragraph.markdown
# TEST: MATHJAX BLOCKS MARKUP #################################################
$$
Expand Down

0 comments on commit e420984

Please sign in to comment.