From 4cce8fb9b3417f762efbc18a619e29001bec157d Mon Sep 17 00:00:00 2001 From: Michael <2701605+michaelblyons@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:59:32 -0500 Subject: [PATCH] [Diff] Configure extensible BOL whitespace (#12) --- Diff/Diff (Basic).sublime-syntax | 16 +-- Diff/Diff.sublime-syntax | 74 ++++++------ Diff/tests/syntax_test_diff.md | 25 ---- Git Formats/Git Diff.sublime-syntax | 112 +++++++++--------- .../Diff (for Markdown).sublime-syntax | 11 ++ Markdown/Markdown.sublime-syntax | 2 +- Markdown/tests/syntax_test_markdown.md | 24 ++++ 7 files changed, 138 insertions(+), 126 deletions(-) delete mode 100644 Diff/tests/syntax_test_diff.md create mode 100644 Markdown/Embeddings/Diff (for Markdown).sublime-syntax diff --git a/Diff/Diff (Basic).sublime-syntax b/Diff/Diff (Basic).sublime-syntax index 0a83f85151..8477936b41 100644 --- a/Diff/Diff (Basic).sublime-syntax +++ b/Diff/Diff (Basic).sublime-syntax @@ -18,11 +18,11 @@ contexts: diff-header: # https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Unified - - match: ^(-{3})[ ](?!$) + - match: '{{bol}}(-{3})[ ](?!$)' captures: 1: punctuation.definition.from-file.diff push: diff-header-unified-from-file - - match: ^(\+{3})[ ](?!$) + - match: '{{bol}}(\+{3})[ ](?!$)' captures: 1: punctuation.definition.to-file.diff push: diff-header-unified-to-file @@ -52,7 +52,7 @@ contexts: diff-line-ranges: # https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Unified - - match: ^(@@)(?=[^@\n]+@@(?:\s|$)) + - match: '{{bol}}(@@)(?=[^@\n]+@@(?:\s|$))' captures: 1: punctuation.definition.range.begin.diff push: [hunk-name, inside-diff-line-ranges-unified] @@ -83,17 +83,17 @@ contexts: diff-deltas: # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Unified - - match: ^\+ + - match: '{{bol}}\+' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^- + - match: '{{bol}}-' scope: punctuation.definition.deleted.diff push: line-deleted - include: incomplete-line # https://www.gnu.org/software/diffutils/manual/diffutils.html#Incomplete-Lines incomplete-line: - - match: ^[\\/] + - match: '{{bol}}[\\/]' scope: punctuation.definition.comment.begin.diff push: line-ignored @@ -179,10 +179,12 @@ variables: git_hash64: '[0-9a-fA-F]{64}' git_hash_full: (?:{{git_hash64}}|{{git_hash40}}) git_first_line: |- - ^(?x: + {{bol}}(?x: From [ ] \w+@z [ ] Thu [ ] Jan [ ]{2} 1 [ ] 00:00:00 [ ] 1970 # git-send-email | From [ ] {{git_hash_full}} [ ] Mon [ ] Sep [ ] 17 [ ] 00:00:00 [ ] 2001 # git-format-patch ) + # No whitespace at beginning of line, unless overridden + bol: ^ eol: (?:$\n?) diff --git a/Diff/Diff.sublime-syntax b/Diff/Diff.sublime-syntax index d2c1e2603c..2494d28bd3 100644 --- a/Diff/Diff.sublime-syntax +++ b/Diff/Diff.sublime-syntax @@ -25,7 +25,7 @@ first_line_match: |- contexts: main: - - match: ^(?={{git_first_line}}) + - match: (?={{git_first_line}}) embed: Packages/Git Formats/Git Diff.sublime-syntax#email-first-line escape: (?!) # Hack for unit tests @@ -47,24 +47,24 @@ contexts: diff-header: - meta_prepend: true # https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Context - - match: ^(\*{15}){{eol}} + - match: '{{bol}}(\*{15}){{eol}}' scope: meta.separator.diff captures: 1: punctuation.separator.block.diff - - match: ^(\*{3})[ ](?!$) + - match: '{{bol}}(\*{3})[ ](?!$)' captures: 1: punctuation.definition.from-file.diff push: diff-header-context-from-file # https://svnbook.red-bean.com/en/1.7/svn-book.html#svn.ref.svn.c.patch - - match: ^(={67}|={78}|_{67}){{eol}} + - match: '{{bol}}(={67}|={78}|_{67}){{eol}}' scope: meta.separator.diff captures: 1: punctuation.separator.block.diff # File headers from extensions and SVN - match: |- - ^(?x:( + {{bol}}(?x:( Added | Copied | Deleted | Index | Modified | Prereq | Property [ ] changes [ ] on ))(:)[ \t]* @@ -75,7 +75,7 @@ contexts: # Can't find documentation for these "="-formatted headers, but there # are preexisting unit tests. - - match: ^(={4}) .+(?= - ) + - match: '{{bol}}(={4}) .+(?= - )' scope: meta.diff.header.from-file meta.header.from-file.diff captures: 1: punctuation.definition.from-file.diff @@ -106,7 +106,7 @@ contexts: - include: timestamps maybe-diff-header-context-to-file: - - match: ^(-{3})[ ](?!$) + - match: '{{bol}}(-{3})[ ](?!$)' captures: 1: punctuation.definition.to-file.diff push: diff-header-context-to-file @@ -125,9 +125,9 @@ contexts: diff-line-ranges: - meta_prepend: true # https://www.gnu.org/software/diffutils/manual/diffutils.html#Hunks - - match: ^-{3}{{eol}} + - match: '{{bol}}-{3}{{eol}}' scope: meta.separator.diff punctuation.separator.block.diff - - match: ^\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}} + - match: '{{bol}}\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}}' scope: meta.diff.range.normal meta.range.normal.diff captures: 1: punctuation.separator.range.diff @@ -135,10 +135,10 @@ contexts: 3: punctuation.separator.range.diff # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context - - match: ^(-){3}(?= .+ -{4}{{eol}}) + - match: '{{bol}}(-){3}(?= .+ -{4}{{eol}})' scope: punctuation.definition.range.begin.diff push: inside-diff-line-ranges-context - - match: ^(\*){3}(?= .+ \*{4}{{eol}}) + - match: '{{bol}}(\*){3}(?= .+ \*{4}{{eol}})' scope: punctuation.definition.range.begin.diff push: inside-diff-line-ranges-context @@ -155,21 +155,21 @@ contexts: diff-deltas: - meta_prepend: true # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Normal - - match: ^> ? + - match: '{{bol}}> ?' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^< ? + - match: '{{bol}}< ?' scope: punctuation.definition.deleted.diff push: line-deleted # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context - - match: ^\+ ? + - match: '{{bol}}\+ ?' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^- ? + - match: '{{bol}}- ?' scope: punctuation.definition.deleted.diff push: line-deleted - - match: ^! ? + - match: '{{bol}}! ?' scope: punctuation.definition.changed.diff push: line-changed @@ -177,12 +177,12 @@ contexts: # https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal diff3-normal: - - match: ^====([1-3]?){{eol}} + - match: '{{bol}}====([1-3]?){{eol}}' scope: meta.hunk.diff punctuation.section.hunk.diff captures: 1: constant.numeric.from-file.diff - - match: ^(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}} + - match: '{{bol}}(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}}' scope: meta.diff.range.normal meta.range.normal.diff captures: 1: meta.toc-list.hunk.diff @@ -196,26 +196,26 @@ contexts: diff3-normal-change: - meta_scope: meta.hunk.diff - meta_content_scope: meta.block.diff - - match: ^(?:\t| ) + - match: '{{bol}}(?:\t| )' push: line-changed - - match: ^ + - match: '{{bol}}' pop: 1 # https://www.gnu.org/software/diffutils/manual/diffutils.html#Selecting-Which-Changes-to-Incorporate diff3-edit: - - match: ^(\d+)(a){{eol}} + - match: '{{bol}}(\d+)(a){{eol}}' captures: 1: meta.diff.range.normal meta.range.normal.diff 2: support.function.diff push: diff3-edit-inserted - - match: ^(\d+)(d){{eol}} + - match: '{{bol}}(\d+)(d){{eol}}' captures: 1: meta.diff.range.normal meta.range.normal.diff 2: support.function.diff push: diff3-edit-deleted - - match: ^(\d+)(c){{eol}} + - match: '{{bol}}(\d+)(c){{eol}}' captures: 1: meta.diff.range.normal meta.range.normal.diff 2: support.function.diff @@ -237,7 +237,7 @@ contexts: - include: diff3-edit-end diff3-edit-end: - - match: ^\.$ + - match: '{{bol}}\.$' scope: punctuation.terminator.hunk.diff pop: 1 @@ -245,24 +245,24 @@ contexts: # Utility context for other files to use conflict-markers: - - match: ^({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.begin.diff captures: 1: punctuation.section.block.begin.diff 2: entity.name.section.diff - - match: ^({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.end.diff captures: 1: punctuation.section.block.end.diff 2: entity.name.section.diff - - match: ^({{conflict_base}}|{{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_base}}|{{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.separator.diff captures: 1: punctuation.section.block.diff 2: entity.name.section.diff conflicts: - - match: ^\s*({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.begin.diff captures: 1: punctuation.section.block.begin.diff @@ -271,7 +271,7 @@ contexts: conflict-deleted-lines: - meta_content_scope: meta.block.conflict.diff markup.deleted.diff - - match: ^\s*({{conflict_base}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_base}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.separator.diff captures: 1: punctuation.section.block.diff @@ -281,7 +281,7 @@ contexts: conflict-base-lines: - meta_content_scope: meta.block.conflict.diff comment.block.diff - - match: ^\s*({{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.separator.diff captures: 1: punctuation.section.block.diff @@ -291,7 +291,7 @@ contexts: conflict-new-lines: - meta_content_scope: meta.block.conflict.diff markup.inserted.diff - - match: ^\s*({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}} + - match: '{{bol}}({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}' scope: meta.block.conflict.end.diff captures: 1: punctuation.section.block.end.diff @@ -302,31 +302,31 @@ contexts: - include: invalid-conflict-marker invalid-conflict-marker: - - match: ^(?:{{conflict_any}}) + - match: '{{bol}}(?:{{conflict_any}})' scope: invalid.illegal.conflict.diff ###[ SIDE-BY-SIDE ]############################################################ # https://www.gnu.org/software/diffutils/manual/diffutils.html#Side-by-Side side-by-side: - - match: ^(.*) (<)$ + - match: '{{bol}}(.*) (<)$' captures: 1: markup.deleted.diff 2: punctuation.definition.deleted.diff - - match: ^(.*) (\()$ + - match: '{{bol}}(.*) (\()$' captures: 1: comment.line.diff 2: punctuation.definition.deleted.diff - - match: ^(.*) ([\\|/]) (.*)$ + - match: '{{bol}}(.*) ([\\|/]) (.*)$' captures: 1: markup.changed.diff 2: punctuation.definition.changed.diff 3: markup.changed.diff - - match: '^ {4,}(>)(?: (.*))?$' + - match: '{{bol}} {4,}(>)(?: (.*))?$' captures: 1: punctuation.definition.inserted.diff 2: markup.inserted.diff - - match: '^ {4,}(\))(?: (.*))?$' + - match: '{{bol}} {4,}(\))(?: (.*))?$' captures: 1: punctuation.definition.inserted.diff 2: comment.line.diff diff --git a/Diff/tests/syntax_test_diff.md b/Diff/tests/syntax_test_diff.md deleted file mode 100644 index 6427ced6b0..0000000000 --- a/Diff/tests/syntax_test_diff.md +++ /dev/null @@ -1,25 +0,0 @@ -\ SYNTAX TEST "Packages/Diff/Diff.sublime-syntax" - -1. list item with diff fenced code block - - ```diff - <<<<<<< A - \^^^^^^^^^ meta.block.conflict.begin.diff - meta.block meta.block - markup - \^^^^^^ punctuation.section.block.begin.diff - \ ^ - entity - punctuation - \ ^ entity.name.section.diff - \ ^ - entity - lines from A - \^^^^^^^^^^^^ meta.block.conflict.diff markup.deleted.diff - meta.block meta.block - ======= - \^^^^^^^ meta.block.conflict.separator.diff - meta.block meta.block - markup - \^^^^^^ punctuation.section.block.diff - lines from B - \^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff - >>>>>>> B - \^^^^^^^^^ meta.block.conflict.end.diff - meta.block meta.block - markup - \^^^^^^ punctuation.section.block.end.diff - \ ^ - entity - \ ^ entity.name.section.diff - \ ^ - entity - ``` diff --git a/Git Formats/Git Diff.sublime-syntax b/Git Formats/Git Diff.sublime-syntax index e3ddeeb31b..e9cf8b0ba4 100644 --- a/Git Formats/Git Diff.sublime-syntax +++ b/Git Formats/Git Diff.sublime-syntax @@ -26,7 +26,7 @@ first_line_match: |- contexts: main: - - match: ^(?={{git_first_line}}) + - match: (?={{git_first_line}}) push: email-first-line # If you can't find the magic first line, just highlight diffs. @@ -57,7 +57,7 @@ contexts: email-header-person: - match: |- - ^(?x: + {{bol}}(?x: ( From | To | Author | Committer | Co-authored-by | Signed-off-by @@ -80,7 +80,7 @@ contexts: - include: pop-before-eol email-header-commit: - - match: ^(In-Reply-To|References)(:) + - match: '{{bol}}(In-Reply-To|References)(:)' captures: 1: keyword.other.diff 2: punctuation.separator.mapping.key-value.diff @@ -93,7 +93,7 @@ contexts: - include: pop-before-next-email-header email-header-subject-line: - - match: ^(Subject)(:) + - match: '{{bol}}(Subject)(:)' captures: 1: keyword.other.diff 2: punctuation.separator.mapping.key-value.diff @@ -127,7 +127,7 @@ contexts: 3: meta.number.integer.decimal.diff constant.numeric.value.diff email-header-date: - - match: ^((?:Author|Committer)?Date)(:) + - match: '{{bol}}((?:Author|Committer)?Date)(:)' captures: 1: keyword.other.diff 2: punctuation.separator.mapping.key-value.diff @@ -154,7 +154,7 @@ contexts: - include: pop-before-next-email-header email-header-generic: - - match: ^\b([\w-]+)\b(:) + - match: '{{bol}}\b([\w-]+)\b(:)' captures: 1: keyword.other.diff 2: punctuation.separator.mapping.key-value.diff @@ -167,16 +167,16 @@ contexts: email-body: - meta_content_scope: meta.block.git-body.diff # https://git-scm.com/docs/git-mailinfo#Documentation/git-mailinfo.txt---scissors - - match: ^(?=--[ -]*{{scissors}}(?:{{scissors}}|[ -])*--\s*$) + - match: '{{bol}}(?=--[ -]*{{scissors}}(?:{{scissors}}|[ -])*--\s*$)' set: [email-headers, scissors-line] - - match: ^(---)\n + - match: '{{bol}}(---)\n' captures: 1: punctuation.section.block.diff set: [diffs, stat] - - match: ^{{next_diff_header}} + - match: '{{bol}}{{next_diff_header}}' set: diffs - include: Git Commit Message.sublime-syntax#commit-message - - match: ^>+ + - match: '{{bol}}>+' scope: punctuation.definition.blockquote.git push: email-quote-body @@ -195,13 +195,13 @@ contexts: stat: - include: pop-before-diff-header - - match: ^ (?=([^|]+[ ]+)\|) + - match: '{{bol}} (?=([^|]+[ ]+)\|)' push: stat-toc-line - - match: ^(?= [0-9]+ file) + - match: '{{bol}}(?= [0-9]+ file)' push: stat-shortstat - - match: ^ (?=create mode) + - match: '{{bol}} (?=create mode)' push: stat-create-file - - match: ^ (?=delete mode) + - match: '{{bol}} (?=delete mode)' push: stat-delete-file - match: '{{empty_line}}' set: diffs @@ -270,7 +270,7 @@ contexts: # https://git-scm.com/docs/diff-format#generate_patch_text_with_p diffs: - - match: ^(diff)( ((--)(?:git|combined|cc))) + - match: '{{bol}}(diff)( ((--)(?:git|combined|cc)))' captures: 1: meta.function-call.identifier.git variable.function.diff 2: meta.function-call.arguments.git @@ -282,7 +282,7 @@ contexts: # This is the Git version unless otherwise configured. You will notice # that once inside this context, you cannot leave. That seems to be how # it works for these files. - - match: ^(-- ){{eol}} + - match: '{{bol}}(-- ){{eol}}' scope: meta.separator.diff captures: 1: punctuation.section.block.diff @@ -324,13 +324,13 @@ contexts: - meta_prepend: true - meta_scope: meta.block.header.diff # Detect & switch context to changed content - - match: ^(?=@|GIT binary) + - match: '{{bol}}(?=@|GIT binary)' set: diff-content # old mode # new mode # deleted file mode - - match: ^(?=deleted file mode) + - match: '{{bol}}(?=deleted file mode)' push: - meta_content_scope: markup.deleted.diff - include: pop-before-eol @@ -338,7 +338,7 @@ contexts: - include: separator-comma # new file mode - - match: ^(?=new file mode) + - match: '{{bol}}(?=new file mode)' push: - meta_content_scope: markup.inserted.diff - include: pop-before-eol @@ -346,7 +346,7 @@ contexts: # mode .. # mode ,.. (for combined diff) - - match: ^mode(?= [106475,.]+) + - match: '{{bol}}mode(?= [106475,.]+)' scope: keyword.other.diff push: - include: pop-before-eol @@ -361,7 +361,7 @@ contexts: # move to # rename from # rename to - - match: ^((?:copy|move|rename) (?:from|to))[ \t]+ + - match: '{{bol}}((?:copy|move|rename) (?:from|to))[ \t]+' captures: 1: keyword.other.diff push: @@ -371,7 +371,7 @@ contexts: # similarity index # dissimilarity index - - match: ^(?:dis)?similarity index + - match: '{{bol}}(?:dis)?similarity index' scope: keyword.other.diff push: - include: pop-before-eol @@ -382,7 +382,7 @@ contexts: 2: constant.numeric.suffix.git # index .. - - match: ^index(?= [0-9a-f,.]+) + - match: '{{bol}}index(?= [0-9a-f,.]+)' scope: keyword.other.diff push: - include: pop-before-eol @@ -403,34 +403,34 @@ contexts: diff-deltas: - meta_prepend: true - - match: ^(?=-- {{eol}}) + - match: '{{bol}}(?=-- {{eol}})' pop: 1 # https://github.com/git/git/commit/051308f6e9cebeb76b8fb4f52b7e9e7ce064445c - - match: ^GIT binary patch + - match: '{{bol}}GIT binary patch' scope: keyword.other.diff push: binary-diff-delta-content binary-diff-delta-content: # Binary type - - match: ^(delta|literal) ([0-9]+) + - match: '{{bol}}(delta|literal) ([0-9]+)' captures: 1: support.function.diff 2: meta.number.integer.decimal.diff constant.numeric.value.diff # Empty file - - match: ^(H)cmV\?d00001$ + - match: '{{bol}}(H)cmV\?d00001$' scope: constant.language.null.diff captures: 1: punctuation.definition.string.begin.diff # Base85-encoded binary data - - match: ^([A-Za-z]){{base85}}{1,66}$ + - match: '{{bol}}([A-Za-z]){{base85}}{1,66}$' scope: meta.string.diff string.other.raw.diff captures: 1: punctuation.definition.string.begin.diff # Bail if anything else is encountered - - match: ^(?!delta|literal|$) + - match: '{{bol}}(?!delta|literal|$)' pop: 2 ###[ COMBINED DIFF ]########################################################### @@ -438,84 +438,84 @@ contexts: diff-line-ranges: - meta_prepend: true # https://git-scm.com/docs/diff-format#_combined_diff_format - - match: ^(@@{2})(?=[^@\n]+@@{2}(?:\s|$)) + - match: '{{bol}}(@@{2})(?=[^@\n]+@@{2}(?:\s|$))' captures: 1: punctuation.definition.range.begin.diff push: [deltas-combined-2, hunk-name, inside-diff-line-ranges-combined] - - match: ^(@@{3})(?=[^@\n]+@@{3}(?:\s|$)) + - match: '{{bol}}(@@{3})(?=[^@\n]+@@{3}(?:\s|$))' captures: 1: punctuation.definition.range.begin.diff push: [deltas-combined-3, hunk-name, inside-diff-line-ranges-combined] - - match: ^(@@{4})(?=[^@\n]+@@{4}(?:\s|$)) + - match: '{{bol}}(@@{4})(?=[^@\n]+@@{4}(?:\s|$))' captures: 1: punctuation.definition.range.begin.diff push: [deltas-combined-4, hunk-name, inside-diff-line-ranges-combined] - - match: ^(@@{5})(?=[^@\n]+@@{5}(?:\s|$)) + - match: '{{bol}}(@@{5})(?=[^@\n]+@@{5}(?:\s|$))' captures: 1: punctuation.definition.range.begin.diff push: [deltas-combined-5, hunk-name, inside-diff-line-ranges-combined] deltas-combined-2: - include: pop-empty-line - - match: ^[ ]{2} - - match: ^[+ ]{2} + - match: '{{bol}}[ ]{2}' + - match: '{{bol}}[+ ]{2}' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^[- ]{2} + - match: '{{bol}}[- ]{2}' scope: punctuation.definition.deleted.diff push: line-deleted - - match: ^[\\/ ]{2} + - match: '{{bol}}[\\/ ]{2}' scope: punctuation.definition.comment.begin.diff push: line-ignored - - match: ^[+-]{2} + - match: '{{bol}}[+-]{2}' scope: punctuation.definition.changed.diff push: line-changed deltas-combined-3: - include: pop-empty-line - - match: ^[ ]{3} - - match: ^[+ ]{3} + - match: '{{bol}}[ ]{3}' + - match: '{{bol}}[+ ]{3}' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^[- ]{3} + - match: '{{bol}}[- ]{3}' scope: punctuation.definition.deleted.diff push: line-deleted - - match: ^[\\/ ]{3} + - match: '{{bol}}[\\/ ]{3}' scope: punctuation.definition.comment.begin.diff push: line-ignored - - match: ^[+-]{3} + - match: '{{bol}}[+-]{3}' scope: punctuation.definition.changed.diff push: line-changed deltas-combined-4: - include: pop-empty-line - - match: ^[ ]{4} - - match: ^[+ ]{4} + - match: '{{bol}}[ ]{4}' + - match: '{{bol}}[+ ]{4}' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^[- ]{4} + - match: '{{bol}}[- ]{4}' scope: punctuation.definition.deleted.diff push: line-deleted - - match: ^[\\/ ]{4} + - match: '{{bol}}[\\/ ]{4}' scope: punctuation.definition.comment.begin.diff push: line-ignored - - match: ^[+-]{4} + - match: '{{bol}}[+-]{4}' scope: punctuation.definition.changed.diff push: line-changed deltas-combined-5: - include: pop-empty-line - - match: ^[ ]{5} - - match: ^[+ ]{5} + - match: '{{bol}}[ ]{5}' + - match: '{{bol}}[+ ]{5}' scope: punctuation.definition.inserted.diff push: line-inserted - - match: ^[- ]{5} + - match: '{{bol}}[- ]{5}' scope: punctuation.definition.deleted.diff push: line-deleted - - match: ^[\\/ ]{5} + - match: '{{bol}}[\\/ ]{5}' scope: punctuation.definition.comment.begin.diff push: line-ignored - - match: ^[+-]{5} + - match: '{{bol}}[+-]{5}' scope: punctuation.definition.changed.diff push: line-changed @@ -558,12 +558,12 @@ contexts: pop: 1 pop-before-diff-header: - - match: ^{{next_diff_header}} + - match: '{{bol}}{{next_diff_header}}' pop: 1 pop-before-next-email-header: # Hack in `\` to support unit tests - - match: ^(?! \S|\\) + - match: '{{bol}}(?! \S|\\)' pop: 1 ############################################################################### @@ -573,7 +573,7 @@ variables: day3: (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) month3: (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) base85: '[0-9a-zA-Z!#$%&()*+\-;<=>?@^_`{|}~]' - empty_line: ^(?=\n) + empty_line: '{{bol}}(?=\n)' scissors: (?:>8|8<) # https://git-scm.com/docs/git-am#_discussion next_diff_header: '(?=Index: |diff -)' diff --git a/Markdown/Embeddings/Diff (for Markdown).sublime-syntax b/Markdown/Embeddings/Diff (for Markdown).sublime-syntax new file mode 100644 index 0000000000..f49afec111 --- /dev/null +++ b/Markdown/Embeddings/Diff (for Markdown).sublime-syntax @@ -0,0 +1,11 @@ +%YAML 1.2 +--- +scope: source.diff.embedded.markdown +version: 2 +hidden: true + +extends: + - Packages/Diff/Diff.sublime-syntax + +variables: + bol: ^\s* diff --git a/Markdown/Markdown.sublime-syntax b/Markdown/Markdown.sublime-syntax index 7cd66b7139..d3161a7d4e 100644 --- a/Markdown/Markdown.sublime-syntax +++ b/Markdown/Markdown.sublime-syntax @@ -1303,7 +1303,7 @@ contexts: 5: constant.other.language-name.markdown 6: comment.line.infostring.markdown 7: meta.fold.code-fence.begin.markdown - embed: scope:source.diff + embed: scope:source.diff.embedded.markdown embed_scope: markup.raw.code-fence.diff.markdown-gfm source.diff diff --git a/Markdown/tests/syntax_test_markdown.md b/Markdown/tests/syntax_test_markdown.md index 7ce426db9f..8318af172d 100644 --- a/Markdown/tests/syntax_test_markdown.md +++ b/Markdown/tests/syntax_test_markdown.md @@ -1878,6 +1878,30 @@ $ cmd # no interactive shell marker |^^ meta.code-fence.definition.end.diff.markdown-gfm punctuation.definition.raw.code-fence.end.markdown | ^ meta.code-fence.definition.end.diff.markdown-gfm meta.fold.code-fence.end - punctuation +1. list item with diff fenced code block + + ```diff + <<<<<<< A + \^^^^^^^^^ meta.block.conflict.begin.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.begin.diff + \ ^ - entity - punctuation + \ ^ entity.name.section.diff + \ ^ - entity + lines from A + \^^^^^^^^^^^^ meta.block.conflict.diff markup.deleted.diff - meta.block meta.block + ======= + \^^^^^^^ meta.block.conflict.separator.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.diff + lines from B + \^^^^^^^^^^^ meta.block.conflict.diff markup.inserted.diff + >>>>>>> B + \^^^^^^^^^ meta.block.conflict.end.diff - meta.block meta.block - markup + \^^^^^^ punctuation.section.block.end.diff + \ ^ - entity + \ ^ entity.name.section.diff + \ ^ - entity + ``` + ```dot |^^^^^ meta.code-fence.definition.begin - meta.fold | ^ meta.code-fence.definition.begin meta.fold.code-fence.begin