Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix escape_except_blockquotes for greater than 9 block quotes in 1 st…
Browse files Browse the repository at this point in the history
…ring

When there are more than 9 block quotes in a string `escape_except_blockquotes` will fail do to the fact that the `BLOCKQUOTE_TOKEN_{i}` replacement will incorrectly match for both `BLOCKQUOTE_TOKEN_1` and `BLOCKQUOTE_TOKEN_10`

This just extends it to `BLOCKQUOTE_TOKEN_{i}_END` so this accidental match doesn't happen.
jackgerrits authored Feb 20, 2024
1 parent e47241f commit c9b0470
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pydoc_markdown/util/misc.py
Original file line number Diff line number Diff line change
@@ -16,13 +16,13 @@ def escape_except_blockquotes(string: str) -> str:

# Replace all blockquotes with placeholder tokens to preserve their contents
for i, match in enumerate(blockquote_matches):
string = string.replace(match, f"BLOCKQUOTE_TOKEN_{i}")
string = string.replace(match, f"BLOCKQUOTE_TOKEN_{i}_END")

# Escape the remaining string
escaped_string = html.escape(string)

# Replace the placeholder tokens with their original contents
for i, match in enumerate(blockquote_matches):
escaped_string = escaped_string.replace(f"BLOCKQUOTE_TOKEN_{i}", match)
escaped_string = escaped_string.replace(f"BLOCKQUOTE_TOKEN_{i}_END", match)

return escaped_string

0 comments on commit c9b0470

Please sign in to comment.