diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index 619ed512..fc2ffa7b 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -327,7 +327,7 @@ contexts: - include: latex-blocks - include: reference-definitions - include: atx-headings - - include: setext-heading-or-paragraph + - include: setext-headings-or-paragraphs ###[ CONTAINER BLOCKS: BLOCK QUOTES ]######################################### @@ -823,35 +823,54 @@ contexts: ###[ LEAF BLOCKS: SETEXT HEADINGS OR PARAGRAPH ]############################## - setext-heading-or-paragraph: - # https://spec.commonmark.org/0.30/#setext-headings + 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: ^[ ]{,3}(?:=+|(?=\S)) - push: 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: ^[ ]{,3}(=+)[ \t]*$(\n?) - scope: markup.heading.1.setext.markdown captures: 1: punctuation.definition.heading.setext.markdown 2: meta.whitespace.newline.markdown pop: true + - 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: ^[ ]{,3}(-+)[ \t]*$(\n?) - scope: markup.heading.2.setext.markdown captures: 1: punctuation.definition.heading.setext.markdown 2: meta.whitespace.newline.markdown pop: true + - include: setext-heading-content + + setext-heading-content: + - match: '{{setext_escape}}' + fail: setext-headings-or-paragraphs + - include: emphasis + - include: images + - include: literals + - include: links + - include: markups paragraph: + # https://spec.commonmark.org/0.30/#paragraphs - meta_scope: meta.paragraph.markdown - - include: setext-heading1 - - include: setext-heading2 + - match: '{{setext_escape}}' + fail: setext-headings-or-paragraphs - include: paragraph-end - include: inlines diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index 50a02c84..2f7f8912 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -748,8 +748,8 @@ bar Foo --- -| <- markup.heading.2.setext.markdown punctuation.definition.heading.setext.markdown -|^^ markup.heading.2.setext.markdown punctuation.definition.heading.setext.markdown +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown bar | <- meta.paragraph.markdown @@ -1055,24 +1055,267 @@ this must not be bold italic*** # TEST: SETEXT HEADINGS ####################################################### -Alternate Heading +SETEXT Heading Level 1 +| <- markup.heading.1.markdown entity.name.section.markdown ================= -|^^^^^^^^^^^^^^^^ markup.heading.1 punctuation.definition -| ^ meta.whitespace.newline +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown +|^^^^^^^^^^^^^^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown -heading underlined with dashes +SETEXT Heading Level 2 +| <- markup.heading.2.markdown entity.name.section.markdown ------------------------------ -| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.heading.2 punctuation.definition.heading +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.2.markdown meta.whitespace.newline.markdown - punctuation underlined heading followed by a separator ------------------- ------ -| <- meta.separator - markup.heading +| <- meta.separator.thematic-break.markdown - markup.heading underlined heading followed by another one that should be treated as a normal paragraph ================== ===== -| <- - markup.heading +| <- meta.paragraph.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-80 + +Foo *bar* +| <- markup.heading.1.markdown entity.name.section.markdown +|^^^^^^^^^ markup.heading.1.markdown entity.name.section.markdown +| ^^^^^ markup.italic.markdown +========= +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown +|^^^^^^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown + +Foo *bar* +| <- markup.heading.2.markdown entity.name.section.markdown +|^^^^^^^^^ markup.heading.2.markdown entity.name.section.markdown +| ^^^^^ markup.italic.markdown +--------- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^^^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.2.markdown meta.whitespace.newline.markdown + +Foo *bar +| <- markup.heading.1.markdown entity.name.section.markdown +|^^^^^^^^^ markup.heading.1.markdown entity.name.section.markdown +| ^^^^^ markup.italic.markdown +========= +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown - markup.italic +|^^^^^^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown - markup.italic +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown - markup.italic + +Foo *bar +| <- markup.heading.2.markdown entity.name.section.markdown +|^^^^^^^^^ markup.heading.2.markdown entity.name.section.markdown +| ^^^^^ markup.italic.markdown +--------- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown - markup.italic +|^^^^^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown - markup.italic +| ^ markup.heading.2.markdown meta.whitespace.newline.markdown - markup.italic + +https://spec.commonmark.org/0.30/#example-81 + +Foo *bar +baz* +| <- markup.heading.1.markdown entity.name.section.markdown markup.italic.markdown +|^^^ markup.heading.1.markdown entity.name.section.markdown markup.italic.markdown +| ^ markup.heading.1.markdown entity.name.section.markdown - markup.italic +==== +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown +|^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown + +https://spec.commonmark.org/0.30/#example-82 + + Foo *bar +baz* +| <- markup.heading.1.markdown entity.name.section.markdown markup.italic.markdown +|^^^ markup.heading.1.markdown entity.name.section.markdown markup.italic.markdown +| ^^ markup.heading.1.markdown entity.name.section.markdown - markup.italic +==== +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown +|^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown + +https://spec.commonmark.org/0.30/#example-83 + +Foo += +| <- markup.heading.1.markdown punctuation.definition.heading.setext.markdown +|^ markup.heading.1.markdown meta.whitespace.newline.markdown + +Foo +- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^ markup.heading.2.markdown meta.whitespace.newline.markdown + +https://spec.commonmark.org/0.30/#example-84 + + Foo +--- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.2.markdown meta.whitespace.newline.markdown + + Foo +----- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.2.markdown meta.whitespace.newline.markdown + + Foo + === +| <- markup.heading.1.markdown - punctuation +|^ markup.heading.1.markdown - punctuation +| ^^^ markup.heading.1.markdown punctuation.definition.heading.setext.markdown +| ^ markup.heading.1.markdown meta.whitespace.newline.markdown + +https://spec.commonmark.org/0.30/#example-85 + + Foo + --- +|^^^^^^^ markup.raw.block.markdown + + Foo +--- +| <- meta.separator.thematic-break.markdown - markup.heading +|^^^ meta.separator.thematic-break.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-86 + +Foo + ---- +|^^^^^^^^^^^^^ markup.heading.2.markdown +|^^ - punctuation +| ^^^^ punctuation.definition.heading.setext.markdown +| ^^^^^^^ - punctuation +| ^ meta.whitespace.newline.markdown + +https://spec.commonmark.org/0.30/#example-87 + +Foo + --- +| <- meta.paragraph.markdown - markup.heading +|^^^^^^^ meta.paragraph.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-88 + +Foo += = +| <- meta.paragraph.markdown - markup.heading +|^^^ meta.paragraph.markdown - markup.heading + +Foo +--- - +| <- meta.separator.thematic-break.markdown - markup.heading +|^^^^^ meta.separator.thematic-break.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-89 + +Foo +| ^^ markup.heading.2.markdown entity.name.section.markdown - meta.hard-line-break +----- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +https://spec.commonmark.org/0.30/#example-90 + +Foo\ +| ^ markup.heading.2.markdown entity.name.section.markdown - meta.hard-line-break +---- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +https://spec.commonmark.org/0.30/#example-91 + +`Foo +---- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +`Foo` +---- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +https://spec.commonmark.org/0.30/#example-92 + +> Foo +--- +| <- meta.separator.thematic-break.markdown - markup.heading +|^^^ meta.separator.thematic-break.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-93 + +> foo +bar +=== +| <- markup.quote.markdown - markup.heading +|^^^ markup.quote.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-94 +- Foo +--- +| <- meta.separator.thematic-break.markdown - markup.heading +|^^^ meta.separator.thematic-break.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-95 + +Foo +Bar +--- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +https://spec.commonmark.org/0.30/#example-96 + +--- +Foo +--- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown + +--- +Foo +--- +Bar +--- +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown +Baz + +--- +Foo +--- +Bar +--- +Baz +| <- meta.paragraph.markdown +|^^^ meta.paragraph.markdown + +https://spec.commonmark.org/0.30/#example-97 + +==== +| <- meta.paragraph.markdown +|^^^^ meta.paragraph.markdown + +https://spec.commonmark.org/0.30/#example-98 + +--- +--- +| <- meta.separator.thematic-break.markdown - markup.heading +|^^^ meta.separator.thematic-break.markdown - markup.heading + +https://spec.commonmark.org/0.30/#example-102 + +\> foo +------ +| <- markup.heading.2.markdown punctuation.definition.heading.setext.markdown +|^^^^^ markup.heading.2.markdown punctuation.definition.heading.setext.markdown ``` Fenced codeblocks are no no setext heading