Repository: facelessuser/pymdown-extensions

Issue:
Import Snippet Section from XML file
### Discussed in https://github.com/facelessuser/pymdown-extensions/discussions/1914

<div type='discussions-op-text'>

<sup>Originally posted by **maciejwalkowiak** January 19, 2023</sup>
I want to use Snippet Sections in an XML file:

```xml
<dependencies>
    <!-- --8<-- [start:func] -->
    <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>dynamodb-enhanced</artifactId>
    </dependency>
    <!-- --8<-- [end:func] -->
</dependencies>
```

`--8<--` within an XML comment makes the XML invalid which as a result breaks the XML tooling. The error is following:

```
in comment after two dashes (--) next character must be > not 8 (position: START_TAG seen ...<dependencies>\n        <!-- --8... @21:17) 
```

Is there a way to use different "tag" than `--8<--` or any other way to make snippet sections work with XML files?</div>

Discussion:
facelessuser: @gir-bot lgtm

Patch:
diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 0d3efae8..533f3214 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/docs/src/markdown/about/changelog.md
@@ -1,5 +1,10 @@
 # Changelog
 
+## 9.9.2
+
+- **FIX**: Snippets syntax can break in XML comments as XML comments do not allow `--`. Relax Snippets syntax such that
+  `-8<-` (single `-`) are allowed.
+
 ## 9.9.1
 
 - **FIX**: Use a different CDN for Twemoji icons as MaxCDN is no longer available.
diff --git a/docs/src/markdown/extensions/snippets.md b/docs/src/markdown/extensions/snippets.md
index 1682b7f2..c50a4305 100644
--- a/docs/src/markdown/extensions/snippets.md
+++ b/docs/src/markdown/extensions/snippets.md
@@ -50,7 +50,7 @@ As you can see, the notation is ASCII scissors cutting a line followed by the fi
 variant, the file name follows directly after the scissors and is quoted.  In the case of the block format, the file
 names follow on separate lines and an additional scissor is added afterwards to signal the end of the block.
 
-The dashes can be as few as 2 (`--8<--`) or longer if desired (`---8<---------`); whatever your preference is.  The
+The dashes can be as few as 1 (`-8<-`) or longer if desired (`---8<---------`); whatever your preference is.  The
 important thing is that the notation must reside on a line(s) by itself, and the path, must be quoted in the case of the
 single line notation.  If the file name is indented, the content will be indented to that level as well.
 
@@ -163,7 +163,7 @@ And then just include it in our document:
 !!! new "New 9.6"
 
 If it is necessary to demonstrate the snippet syntax, an escaping method is required. If you need to escape snippets,
-just place a `;` right before `--8<--`. This will work for both single line and block format. An escaped snippet
+just place a `;` right before `-8<-`. This will work for both single line and block format. An escaped snippet
 notation will be passed through the Markdown parser with the first `;` removed.
 
 === "Markdown"
@@ -183,7 +183,7 @@ notation will be passed through the Markdown parser with the first `;` removed.
     ```
 
 !!! warning "Legacy Escaping"
-    The legacy escape method required placing a space at the end of the line with `--8<--`, while this should still
+    The legacy escape method required placing a space at the end of the line with `-8<-`, while this should still
     work, this behavior will be removed at sometime in the future and is discouraged.
 
 ## Specifying Snippet Locations
diff --git a/pymdownx/__meta__.py b/pymdownx/__meta__.py
index 0656d3a2..31071ac5 100644
--- a/pymdownx/__meta__.py
+++ b/pymdownx/__meta__.py
@@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
     return Version(major, minor, micro, release, pre, post, dev)
 
 
-__version_info__ = Version(9, 9, 1, "final")
+__version_info__ = Version(9, 9, 2, "final")
 __version__ = __version_info__._get_canonical()
diff --git a/pymdownx/snippets.py b/pymdownx/snippets.py
index 24dd6f0d..cf5f903b 100644
--- a/pymdownx/snippets.py
+++ b/pymdownx/snippets.py
@@ -49,9 +49,9 @@ class SnippetPreprocessor(Preprocessor):
         ^(?P<space>[ \t]*)
         (?P<escape>;*)
         (?P<all>
-            (?P<inline_marker>-{2,}8<-{2,}[ \t]+)
+            (?P<inline_marker>-{1,}8<-{1,}[ \t]+)
             (?P<snippet>(?:"(?:\\"|[^"\n\r])+?"|'(?:\\'|[^'\n\r])+?'))(?![ \t]) |
-            (?P<block_marker>-{2,}8<-{2,})(?![ \t])
+            (?P<block_marker>-{1,}8<-{1,})(?![ \t])
         )\r?$
         '''
     )
@@ -66,7 +66,7 @@ class SnippetPreprocessor(Preprocessor):
     RE_SNIPPET_SECTION = re.compile(
         r'''(?xi)
         ^.*?
-        (?P<inline_marker>-{2,}8<-{2,}[ \t]+)
+        (?P<inline_marker>-{1,}8<-{1,}[ \t]+)
         \[[ \t]*(?P<type>start|end)[ \t]*:[ \t]*(?P<name>[a-z][0-9a-z]*)[ \t]*\]
         .*?$
         '''
@@ -324,7 +324,7 @@ class SnippetPreprocessor(Preprocessor):
 
         self.seen = set()
         if self.auto_append:
-            lines.extend("\n\n--8<--\n{}\n--8<--\n".format('\n\n'.join(self.auto_append)).split('\n'))
+            lines.extend("\n\n-8<-\n{}\n-8<-\n".format('\n\n'.join(self.auto_append)).split('\n'))
 
         return self.parse_snippets(lines)
 


Test patch:
diff --git a/tests/test_extensions/_snippets/section.txt b/tests/test_extensions/_snippets/section.txt
index 8a05e940..ea43f9f4 100644
--- a/tests/test_extensions/_snippets/section.txt
+++ b/tests/test_extensions/_snippets/section.txt
@@ -4,9 +4,9 @@ div {
 }
 /* --8<-- [end: cssSection] */
 
-<!-- --8<-- [start: htmlSection] -->
+<!-- -8<- [start: htmlSection] -->
 <div><p>content</p></div>
-<!-- --8<-- [end: htmlSection] -->
+<!-- -8<- [end: htmlSection] -->
 
 /* --8<-- [end: cssSection2] */
 /* --8<-- [start: cssSection2] */
diff --git a/tests/test_extensions/test_snippets.py b/tests/test_extensions/test_snippets.py
index 5261b2d3..4bb03d90 100644
--- a/tests/test_extensions/test_snippets.py
+++ b/tests/test_extensions/test_snippets.py
@@ -241,8 +241,26 @@ class TestSnippets(util.MdCase):
             True
         )
 
+    def test_section_inline_min(self):
+        """Test section partial in inline snippet using minimum tokens."""
+
+        self.check_markdown(
+            R'''
+            ```
+            -8<- "section.txt:cssSection"
+            ```
+            ''',
+            '''
+            <div class="highlight"><pre><span></span><code>div {
+                color: red;
+            }
+            </code></pre></div>
+            ''',
+            True
+        )
+
     def test_section_block(self):
-        """Test section partial in inline snippet."""
+        """Test section partial in block snippet."""
 
         self.check_markdown(
             R'''
@@ -256,6 +274,21 @@ class TestSnippets(util.MdCase):
             True
         )
 
+    def test_section_block_min(self):
+        """Test section partial in block snippet using minimum tokens."""
+
+        self.check_markdown(
+            R'''
+            -8<-
+            section.txt:htmlSection
+            -8<-
+            ''',
+            '''
+            <div><p>content</p></div>
+            ''',
+            True
+        )
+
     def test_section_end_first(self):
         """Test section when the end is specified first."""