From 3c143f6b2b434f7b5bbbaf1928aa653e91662e66 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Thu, 25 Jun 2026 15:58:35 +0200 Subject: [PATCH] fix: add highlighting of snippet sections outside of comments Signed-off-by: squidfunk --- .../src/python-markdown.tmLanguage.yml | 33 ++++-- .../snapshots/preprocess/snippet.scopes.json | 109 ++++-------------- .../test/specs/preprocess/snippet.md | 10 +- .../syntaxes/python-markdown.tmLanguage.json | 73 +++++++++--- 4 files changed, 111 insertions(+), 114 deletions(-) diff --git a/grammars/textmate/python-markdown/src/python-markdown.tmLanguage.yml b/grammars/textmate/python-markdown/src/python-markdown.tmLanguage.yml index c823bd7..6fb9702 100644 --- a/grammars/textmate/python-markdown/src/python-markdown.tmLanguage.yml +++ b/grammars/textmate/python-markdown/src/python-markdown.tmLanguage.yml @@ -50,12 +50,30 @@ repository: patterns: - name: meta.snippet.section.markdown match: >- - (?:^|\G)(.*?)(?)([ \t]*)$ captures: - 1: - name: meta.snippet.section.prefix.markdown - patterns: - - include: "#inline_flow" + 1: { name: punctuation.whitespace.leading.markdown } + 2: { name: punctuation.definition.comment.begin.html } + 3: { name: punctuation.whitespace.markdown } + 4: { name: keyword.control.snippet.markdown } + 5: { name: comment.snippet.separator.markdown } + 6: { name: punctuation.definition.snippet-section.begin.markdown } + 7: { name: punctuation.whitespace.markdown } + 8: { name: keyword.control.snippet.section.markdown } + 9: { name: punctuation.whitespace.markdown } + 10: { name: punctuation.separator.snippet-section.markdown } + 11: { name: punctuation.whitespace.markdown } + 12: { name: entity.name.section.snippet.markdown } + 13: { name: punctuation.whitespace.markdown } + 14: { name: punctuation.definition.snippet-section.end.markdown } + 15: { name: punctuation.whitespace.markdown } + 16: { name: punctuation.definition.comment.end.html } + 17: { name: punctuation.whitespace.trailing.markdown } + - name: meta.snippet.section.markdown + match: >- + (?:^|\G)([ \t]*)(-{1,}8<-{1,})([ \t]+)(\[)([ \t]*)(?i:(start|end))([ \t]*)(:)([ \t]*)([a-z][-_0-9a-z]*)([ \t]*)(\])([ \t]*)$ + captures: + 1: { name: punctuation.whitespace.leading.markdown } 2: { name: keyword.control.snippet.markdown } 3: { name: comment.snippet.separator.markdown } 4: { name: punctuation.definition.snippet-section.begin.markdown } @@ -67,10 +85,7 @@ repository: 10: { name: entity.name.section.snippet.markdown } 11: { name: punctuation.whitespace.markdown } 12: { name: punctuation.definition.snippet-section.end.markdown } - 13: - name: meta.snippet.section.suffix.markdown - patterns: - - include: "#inline_flow" + 13: { name: punctuation.whitespace.trailing.markdown } - name: meta.snippet.inline.markdown match: >- (?:^|\G)([ \t]*)(-{1,}8<-{1,})([ \t]+)(")((?:\\"|[^"\r\n])+?)((?::-?[0-9]*){1,2}(?:(?:,(?=[-0-9:])-?[0-9]*)(?::-?[0-9]*)?)*)(")$ diff --git a/grammars/textmate/python-markdown/test/snapshots/preprocess/snippet.scopes.json b/grammars/textmate/python-markdown/test/snapshots/preprocess/snippet.scopes.json index 6be6d01..da2ae2b 100644 --- a/grammars/textmate/python-markdown/test/snapshots/preprocess/snippet.scopes.json +++ b/grammars/textmate/python-markdown/test/snapshots/preprocess/snippet.scopes.json @@ -911,18 +911,10 @@ "tokens": [] } ], - "accept_with_prefix_and_suffix": [ + "accept_uppercase_keyword": [ { - "line": "prefix --8<-- [start:example] suffix", + "line": "--8<-- [START:example]", "tokens": [ - { - "text": "prefix ", - "scopes": [ - "text.html.markdown.python", - "meta.snippet.section.markdown", - "meta.snippet.section.prefix.markdown" - ] - }, { "text": "--8<--", "scopes": [ @@ -948,7 +940,7 @@ ] }, { - "text": "start", + "text": "START", "scopes": [ "text.html.markdown.python", "meta.snippet.section.markdown", @@ -978,14 +970,6 @@ "meta.snippet.section.markdown", "punctuation.definition.snippet-section.end.markdown" ] - }, - { - "text": " suffix", - "scopes": [ - "text.html.markdown.python", - "meta.snippet.section.markdown", - "meta.snippet.section.suffix.markdown" - ] } ] }, @@ -994,16 +978,16 @@ "tokens": [] } ], - "accept_uppercase_keyword": [ + "accept_html_comment_wrapped": [ { - "line": "--8<-- [START:example]", + "line": "", "tokens": [ { - "text": "--8<--", + "text": "", + "scopes": [ + "text.html.markdown.python", + "meta.snippet.section.markdown", + "punctuation.definition.comment.end.html" + ] } ] }, diff --git a/grammars/textmate/python-markdown/test/specs/preprocess/snippet.md b/grammars/textmate/python-markdown/test/specs/preprocess/snippet.md index 9a7869e..07c5c92 100644 --- a/grammars/textmate/python-markdown/test/specs/preprocess/snippet.md +++ b/grammars/textmate/python-markdown/test/specs/preprocess/snippet.md @@ -118,20 +118,14 @@ index.md --8<-- [end:example] ``` -### accept_with_prefix_and_suffix - -``` md -prefix --8<-- [start:example] suffix -``` - ### accept_uppercase_keyword ``` md --8<-- [START:example] ``` -### reject_escaped +### accept_html_comment_wrapped ``` md -;--8<-- [start:example] + ``` diff --git a/integrations/code/syntaxes/python-markdown.tmLanguage.json b/integrations/code/syntaxes/python-markdown.tmLanguage.json index acfe8f0..d01d6ab 100644 --- a/integrations/code/syntaxes/python-markdown.tmLanguage.json +++ b/integrations/code/syntaxes/python-markdown.tmLanguage.json @@ -47,15 +47,67 @@ "patterns": [ { "name": "meta.snippet.section.markdown", - "match": "(?:^|\\G)(.*?)(?)([ \\t]*)$", "captures": { "1": { - "name": "meta.snippet.section.prefix.markdown", - "patterns": [ - { - "include": "#inline_flow" - } - ] + "name": "punctuation.whitespace.leading.markdown" + }, + "2": { + "name": "punctuation.definition.comment.begin.html" + }, + "3": { + "name": "punctuation.whitespace.markdown" + }, + "4": { + "name": "keyword.control.snippet.markdown" + }, + "5": { + "name": "comment.snippet.separator.markdown" + }, + "6": { + "name": "punctuation.definition.snippet-section.begin.markdown" + }, + "7": { + "name": "punctuation.whitespace.markdown" + }, + "8": { + "name": "keyword.control.snippet.section.markdown" + }, + "9": { + "name": "punctuation.whitespace.markdown" + }, + "10": { + "name": "punctuation.separator.snippet-section.markdown" + }, + "11": { + "name": "punctuation.whitespace.markdown" + }, + "12": { + "name": "entity.name.section.snippet.markdown" + }, + "13": { + "name": "punctuation.whitespace.markdown" + }, + "14": { + "name": "punctuation.definition.snippet-section.end.markdown" + }, + "15": { + "name": "punctuation.whitespace.markdown" + }, + "16": { + "name": "punctuation.definition.comment.end.html" + }, + "17": { + "name": "punctuation.whitespace.trailing.markdown" + } + } + }, + { + "name": "meta.snippet.section.markdown", + "match": "(?:^|\\G)([ \\t]*)(-{1,}8<-{1,})([ \\t]+)(\\[)([ \\t]*)(?i:(start|end))([ \\t]*)(:)([ \\t]*)([a-z][-_0-9a-z]*)([ \\t]*)(\\])([ \\t]*)$", + "captures": { + "1": { + "name": "punctuation.whitespace.leading.markdown" }, "2": { "name": "keyword.control.snippet.markdown" @@ -91,12 +143,7 @@ "name": "punctuation.definition.snippet-section.end.markdown" }, "13": { - "name": "meta.snippet.section.suffix.markdown", - "patterns": [ - { - "include": "#inline_flow" - } - ] + "name": "punctuation.whitespace.trailing.markdown" } } },