Skip to content

Commit 3f20390

Browse files
jackgerritsGitHub Action
andauthored
Fix escape_except_blockquotes for greater than 9 block quotes in 1 string (#317)
* Fix escape_except_blockquotes for greater than 9 block quotes in 1 string 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. * update changelog * Updated PR references in 1 changelogs. skip-checks: true --------- Co-authored-by: GitHub Action <github-action@users.noreply.github.com>
1 parent e47241f commit 3f20390

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changelog/_unreleased.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ type = "breaking change"
1818
description = "Drop Python 3.7 compatibility"
1919
author = "@NiklasRosenstein"
2020
pr = "https://github.com/NiklasRosenstein/pydoc-markdown/pull/304"
21+
22+
[[entries]]
23+
id = "78a8f6a1-eaaa-41cf-89f0-e746ddb42491"
24+
type = "fix"
25+
description = "Fix `escape_except_blockquotes` option for greater than 9 blockquotes in a docstring"
26+
author = "@jackgerrits"
27+
pr = "https://github.com/NiklasRosenstein/pydoc-markdown/pull/317"

src/pydoc_markdown/util/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def escape_except_blockquotes(string: str) -> str:
1616

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

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

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

2828
return escaped_string

0 commit comments

Comments
 (0)