Skip to content

Commit

Permalink
Merge pull request #506 from Crozzers/fix-505
Browse files Browse the repository at this point in the history
Fix `_uniform_outdent` failing with empty strings (issue #505)
  • Loading branch information
nicholasserra committed Apr 10, 2023
2 parents 7bae1f9 + e0a7d72 commit d657fca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@

- [pull #500] Add `<thead>` tag to html-classes extra
- [pull #502] Replace deprecated `optparse` with `argparse`
- [pull #506] Fix `_uniform_outdent` failing with empty strings (issue #505)


## python-markdown2 2.4.8
Expand Down
9 changes: 7 additions & 2 deletions lib/markdown2.py
Expand Up @@ -2609,12 +2609,17 @@ def _uniform_outdent(self, text, min_outdent=None, max_outdent=None):
re.findall(r'^[ \t]*', line)[0] if line else None
for line in text.splitlines()
]
whitespace_not_empty = [i for i in whitespace if i is not None]

# if no whitespace detected (ie: no lines in code block, issue #505)
if not whitespace_not_empty:
return '', text

# get minimum common whitespace
outdent = min(i for i in whitespace if i is not None)
outdent = min(whitespace_not_empty)
# adjust min common ws to be within bounds
if min_outdent is not None:
outdent = min([i for i in whitespace if i is not None and i >= min_outdent] or [min_outdent])
outdent = min([i for i in whitespace_not_empty if i >= min_outdent] or [min_outdent])
if max_outdent is not None:
outdent = min(outdent, max_outdent)

Expand Down
20 changes: 20 additions & 0 deletions test/tm-cases/empty_fenced_code_blocks.html
@@ -0,0 +1,20 @@
<div class="codehilite">
<pre><span></span><code>
</code></pre>
</div>

<pre><code>
</code></pre>

<p>Pygments removes the empty line whitespace from the next code block</p>

<div class="codehilite">
<pre><span></span><code>
</code></pre>
</div>

<pre><code>



</code></pre>
1 change: 1 addition & 0 deletions test/tm-cases/empty_fenced_code_blocks.opts
@@ -0,0 +1 @@
{"extras": ["fenced-code-blocks"]}
20 changes: 20 additions & 0 deletions test/tm-cases/empty_fenced_code_blocks.text
@@ -0,0 +1,20 @@
```shell
```

```
```

Pygments removes the empty line whitespace from the next code block
```shell




```

```




```

0 comments on commit d657fca

Please sign in to comment.