Repository: facelessuser/pymdown-extensions

Issue:
Highlight causes extra new lines to be inserted before `</code>` in rendered indented code blocks
### Description

Consider the following Markdown text (an indented code block followed by 2 empty lines):

```markdown
    int a;


```

When Highlight is enabled, it is wrongly rendered as

```html
<pre class="highlight"><code>int a;




</code></pre>
```

instead of

```html
<pre class="highlight"><code>int a;
</code></pre>
```

### Minimal Reproduction

```python
import markdown

text = '    int a;\n\n'

print(repr(markdown.markdown(text)))
print(repr(markdown.markdown(text,
                             extensions=['pymdownx.highlight'],
                             extension_configs={'pymdownx.highlight': {'use_pygments': False}})))
```

## Actual Behavior

```
'<pre><code>int a;\n</code></pre>'
'<pre class="highlight"><code>int a;\n\n\n\n\n</code></pre>'
```

## Expected Behaviod

```
'<pre><code>int a;\n</code></pre>'
'<pre class="highlight"><code>int a;\n</code></pre>'
```

### Version(s) & System Info

- Operating System: Ubuntu 20.04 (64-bit)
- Python Version: `python==3.9`
- Package Version: `Markdown==3.4.1 pymdown-extensions==9.9.2`

Discussion:
facelessuser: @gir-bot lgtm

Patch:
diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md
index 533f3214..c793ab77 100644
--- a/docs/src/markdown/about/changelog.md
+++ b/docs/src/markdown/about/changelog.md
@@ -1,5 +1,10 @@
 # Changelog
 
+## 9.9.3
+
+- **FIX**: Highlight: Remove extraneous new lines from end of indented code blocks when using
+  `#!py use_pygments = False`.
+
 ## 9.9.2
 
 - **FIX**: Snippets syntax can break in XML comments as XML comments do not allow `--`. Relax Snippets syntax such that
diff --git a/pymdownx/__meta__.py b/pymdownx/__meta__.py
index 31071ac5..50bcbc47 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, 2, "final")
+__version_info__ = Version(9, 9, 3, "final")
 __version__ = __version_info__._get_canonical()
diff --git a/pymdownx/highlight.py b/pymdownx/highlight.py
index 2d756fc9..09a97038 100644
--- a/pymdownx/highlight.py
+++ b/pymdownx/highlight.py
@@ -501,7 +501,7 @@ class HighlightTreeprocessor(Treeprocessor):
                 )
                 placeholder = self.md.htmlStash.store(
                     code.highlight(
-                        self.code_unescape(block[0].text),
+                        self.code_unescape(block[0].text).rstrip('\n'),
                         '',
                         self.config['css_class'],
                         code_block_count=self.ext.pygments_code_block


Test patch:
diff --git a/tests/test_extensions/test_highlight.py b/tests/test_extensions/test_highlight.py
index 733ab250..e4ac8a85 100644
--- a/tests/test_extensions/test_highlight.py
+++ b/tests/test_extensions/test_highlight.py
@@ -335,6 +335,28 @@ class TestNoPygments(util.MdCase):
             True
         )
 
+    def test_no_pygments_extraneous_new_lines(self):
+        """Test that extraneous new lines are not included."""
+
+        self.check_markdown(
+            r'''
+            Test
+
+                import test
+                test.test()
+
+
+            Test
+            ''',
+            r'''
+            <p>Test</p>
+            <pre class="highlight"><code>import test
+            test.test()</code></pre>
+            <p>Test</p>
+            ''',
+            True
+        )
+
 
 class TestNoPygmentsCustomLineClass(util.MdCase):
     """Test no Pygments with custom line number class."""
@@ -363,8 +385,7 @@ class TestNoPygmentsCustomLineClass(util.MdCase):
             r'''
             <p>Text</p>
             <pre class="highlight"><code>import test
-            test.test()
-            </code></pre>
+            test.test()</code></pre>
             <p>Text</p>
             ''',
             True