From 4ed4104f7ce7b636c2c0459eabe110c4b62bff32 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 12 Sep 2021 17:27:50 +0200 Subject: [PATCH] Syntax: Use branches to highlight SETEXT headings This commit is compatible with ST4107+ It adds support for setext headings highlighting from default Markdown syntax. --- syntaxes/Markdown.sublime-syntax | 25 ++- tests/syntax_test_markdown.md | 257 ++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 12 deletions(-) diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index dbaa4ff9..a5dc9993 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -317,28 +317,43 @@ contexts: # 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-heading-or-paragraph + branch: + - paragraph + - setext-heading2 + - setext-heading1 setext-heading1: + # https://spec.commonmark.org/0.30/#setext-headings + - meta_scope: markup.heading.1.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 - 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-heading-or-paragraph + - include: inline-bold-italic + - include: scope:text.html.basic paragraph: + # https://spec.commonmark.org/0.30/#paragraphs - meta_scope: meta.paragraph.markdown - - include: setext-heading1 - - include: setext-heading2 + - match: '{{setext_escape}}' + fail: setext-heading-or-paragraph - include: paragraph-end - include: inline-bold-italic-linebreak - include: tag-kbd diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index 642cf8c6..31f9fec8 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -133,24 +133,267 @@ this must not be bold italic*** | <- - meta.bold - markup.italic |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.bold - markup.italic -Alternate Heading +SETEXT Heading Level 1 +| <- markup.heading.1.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 ------------------------------ -| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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.block-level 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 +|^^^^^^^^^ markup.heading.1.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 +|^^^^^^^^^ markup.heading.2.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 +|^^^^^^^^^ markup.heading.1.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 +|^^^^^^^^^ markup.heading.2.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 markup.italic.markdown +|^^^ markup.heading.1.markdown markup.italic.markdown +| ^ markup.heading.1.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 markup.italic.markdown +|^^^ markup.heading.1.markdown markup.italic.markdown +| ^^ markup.heading.1.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 - 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 - 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