Skip to content

Commit 17beaed

Browse files
committed
Make redown handle code block options
Don't automatically add 2 newlines after a code block, check to see if there's options after, and only add a newline after the options are added. This fixes the code blocks in the stacktrace page. Fixes #2728
1 parent b328880 commit 17beaed

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

source/_extensions/redown.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,22 @@ def replace(match: re.Match) -> str:
6767

6868
ret = ""
6969
ret += start
70-
ret += btindent + f".. code-block:: {lang}\n\n"
70+
ret += btindent + f".. code-block:: {lang}\n"
7171
cindent = 3 * " "
72+
firstCode = False
7273

7374
for line in code.splitlines(keepends=True):
74-
if line.strip() == "":
75+
if line.strip().startswith(":") and not firstCode:
76+
ret += cindent + line
77+
elif line.strip() == "":
78+
if not firstCode:
79+
firstCode = True
80+
ret += "\n"
7581
ret += "\n"
7682
else:
83+
if not firstCode:
84+
firstCode = True
85+
ret += "\n"
7786
ret += cindent + line
7887

7988
return ret

0 commit comments

Comments
 (0)