Repository: adamchainz/pygments-git (language: python)

Issue:
git-text-merge-markers lexer
### Description

Highlight merge markers, branches, and commits appropriately in otherwise plain text files like:

```
74. Fly me to the moon
75. Talking to the moon
<<<<<<< HEAD
76. Moonlight sonata
||||||| 4d21c67
=======
76. Dancing in the moonlight
>>>>>>> main
```


Discussion / hints:
More complete:

```
<<<<<<< HEAD
red
||||||| parent of 09fb2fb (Make it blue)
yellow
=======
blue
>>>>>>> 09fb2fb (Make it blue)
```

Fix patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index fdacfed..7d7cad8 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,8 @@
 Changelog
 =========
 
+* Add ``git-conflict-markers``.
+
 1.1.0 (2023-04-06)
 ------------------
 
diff --git a/README.rst b/README.rst
index 159233a..35a5f42 100644
--- a/README.rst
+++ b/README.rst
@@ -55,6 +55,8 @@ Within Sphinx/docutils, you can refer to them in ``code-block`` directives:
         91e9879 Aye carumba! Grammar mistake
         61c4c08 Cowabunga! Update bibliography
 
+To preview the lexers, open the ``tests/index.html`` file within the repository.
+
 ``git-commit-edit-msg``
 -----------------------
 
@@ -67,6 +69,12 @@ __ https://pygments.org/docs/lexers/#pygments.lexers.diff.DiffLexer
 .. |git commit --verbose| replace:: ``git commit --verbose``
 __ https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--v
 
+``git-conflict-markers``
+------------------------
+
+A lexer for the conflict markers that Git adds to indicate conflicts during a merge.
+All other text in the file is lexed as plain text.
+
 ``git-console``
 ---------------
 
diff --git a/setup.cfg b/setup.cfg
index 66e4d89..c1d625c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -45,6 +45,7 @@ where = src
 [options.entry_points]
 pygments.lexers =
     git-commit-edit-msg=pygments_git:GitCommitEditMsgLexer
+    git-conflict-markers=pygments_git:GitConflictMarkersLexer
     git-console=pygments_git:GitBashSessionLexer
     git-rebase-todo=pygments_git:GitRebaseTodoLexer
 
diff --git a/src/pygments_git/__init__.py b/src/pygments_git/__init__.py
index c44c306..fe1ffb6 100644
--- a/src/pygments_git/__init__.py
+++ b/src/pygments_git/__init__.py
@@ -12,6 +12,7 @@
 from pygments.token import Keyword
 from pygments.token import Name
 from pygments.token import Number
+from pygments.token import Punctuation
 from pygments.token import String
 from pygments.token import Text
 
@@ -61,6 +62,77 @@ class GitCommitEditMsgLexer(RegexLexer):
     }
 
 
+class GitConflictMarkersLexer(RegexLexer):
+    name = "Git Conflict Markers"
+    aliases = ("git-conflict-markers",)
+    flags = re.MULTILINE
+
+    tokens = {
+        "root": [
+            (
+                r"^(<{7})( )?(.+)?$",
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker, Text, Name.Label
+                ),
+            ),
+            (
+                r"""(?x)
+                    ^
+                    (\|{7})
+                    (\ parent\ of\ )
+                    ([0-9a-f]{7})
+                    (\ \()
+                    (.*?)
+                    (\))
+                    $
+                """,
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker,
+                    Name.Label,
+                    Number.Hex,
+                    Text,
+                    Name.Label,
+                    Text,
+                ),
+            ),
+            (
+                r"^(\|{7})( )?(.*)$",
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker, Text, Name.Label
+                ),
+            ),
+            (
+                r"^(={7})( )?(.*)$",
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker, Text, Name.Label
+                ),
+            ),
+            (
+                r"""(?x)
+                    ^
+                    (>{7})
+                    (\ )
+                    ([0-9a-f]{7})
+                    (\ \()
+                    (.*?)
+                    (\))
+                    $
+                """,
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker, Text, Number.Hex, Text, Name.Label, Text
+                ),
+            ),
+            (
+                r"^(>{7})(\ )?(.*)?$",
+                bygroups(  # type: ignore [no-untyped-call]
+                    Punctuation.Marker, Text, Name.Label
+                ),
+            ),
+            (r".*\n", Text),
+        ]
+    }
+
+
 class GitBashSessionLexer(RegexLexer):
     name = "Git Bash Session"
     aliases = ("git-console",)


Test patch:
diff --git a/tests/index.html b/tests/index.html
index 06638bd..95a66b1 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -89,6 +89,11 @@
 .highlight .vi { color: #3333BB } /* Name.Variable.Instance */
 .highlight .vm { color: #996633 } /* Name.Variable.Magic */
 .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
+.highlight .pm { /* Punctuation.Marker */
+    color: #540099;
+    font-weight: bold;
+}
+
 </style>
 </head>
 <body>
@@ -144,6 +149,65 @@ <h2 id=test_git_commit_edit_msg>
 <span class="gi">+bopped</span>
 </pre></div>
 </div>
+<h2 id=test_git_conflict_markers>
+test_git_conflict_markers
+<a href=#test_git_conflict_markers>#</a>
+</h2>
+<p>
+Lexer: git-conflict-markers
+</p>
+<div class=compare><code>
+<pre>
+&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
+red
+||||||| parent of 09fb2fb (Make it blue)
+yellow
+=======
+blue
+&gt;&gt;&gt;&gt;&gt;&gt;&gt; 09fb2fb (Make it blue)
+
+&lt;&lt;&lt;&lt;&lt;&lt;&lt; current
+teal
+||||||| original
+cerulean
+======= bla
+cyan
+&gt;&gt;&gt;&gt;&gt;&gt;&gt; incoming
+
+&lt;&lt;&lt;&lt;&lt;&lt;&lt;
+purple
+|||||||
+puce
+=======
+cerise
+&gt;&gt;&gt;&gt;&gt;&gt;&gt;
+</pre>
+</code>
+<div class="highlight"><pre><span></span><span class="pm">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> <span class="nl">HEAD</span>
+red
+<span class="pm">|||||||</span><span class="nl"> parent of </span><span class="mh">09fb2fb</span> (<span class="nl">Make it blue</span>)
+yellow
+<span class="pm">=======</span>
+blue
+<span class="pm">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span> <span class="mh">09fb2fb</span> (<span class="nl">Make it blue</span>)
+
+<span class="pm">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> <span class="nl">current</span>
+teal
+<span class="pm">|||||||</span> <span class="nl">original</span>
+cerulean
+<span class="pm">=======</span> <span class="nl">bla</span>
+cyan
+<span class="pm">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span> <span class="nl">incoming</span>
+
+<span class="pm">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span>
+purple
+<span class="pm">|||||||</span>
+puce
+<span class="pm">=======</span>
+cerise
+<span class="pm">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span>
+</pre></div>
+</div>
 <h2 id=test_git_console>
 test_git_console
 <a href=#test_git_console>#</a>
diff --git a/tests/test_pygments_git.py b/tests/test_pygments_git.py
index f47e111..8f139ef 100644
--- a/tests/test_pygments_git.py
+++ b/tests/test_pygments_git.py
@@ -78,6 +78,14 @@ def check(self, testid: str, lexer: str, given: str) -> None:
                 """
             ),
             formatter.get_style_defs(".highlight"),
+            dedent(
+                """\
+                .highlight .pm { /* Punctuation.Marker */
+                    color: #540099;
+                    font-weight: bold;
+                }
+                """
+            ),
             "</style>",
             "</head>",
             "<body>",
@@ -139,6 +147,38 @@ def test_git_commit_edit_msg(golden_file):
     )
 
 
+def test_git_conflict_markers(golden_file):
+    golden_file.check(
+        "test_git_conflict_markers",
+        "git-conflict-markers",
+        """\
+        <<<<<<< HEAD
+        red
+        ||||||| parent of 09fb2fb (Make it blue)
+        yellow
+        =======
+        blue
+        >>>>>>> 09fb2fb (Make it blue)
+
+        <<<<<<< current
+        teal
+        ||||||| original
+        cerulean
+        ======= bla
+        cyan
+        >>>>>>> incoming
+
+        <<<<<<<
+        purple
+        |||||||
+        puce
+        =======
+        cerise
+        >>>>>>>
+        """,
+    )
+
+
 def test_git_console(golden_file):
     golden_file.check(
         "test_git_console",