Skip to content

Commit 322a38a

Browse files
committed
Check if directive is a CodeBlock directive
Avoids problems on styleguide with python link
1 parent 17beaed commit 322a38a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

source/_extensions/redown.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pathlib import Path
1515
from sphinx.application import Sphinx
1616
from dataclasses import dataclass
17+
from sphinx.directives.code import CodeBlock
1718

1819

1920
LINK_CORE = r"""
@@ -73,7 +74,15 @@ def replace(match: re.Match) -> str:
7374

7475
for line in code.splitlines(keepends=True):
7576
if line.strip().startswith(":") and not firstCode:
76-
ret += cindent + line
77+
colon_start = line.find(":")
78+
colon_end = line.rfind(":")
79+
if colon_start != -1 and colon_end != -1 and colon_start < colon_end:
80+
option = line[colon_start + 1:colon_end].strip()
81+
if option in CodeBlock.option_spec:
82+
ret += cindent + line
83+
else:
84+
ret += "\n" + cindent + line
85+
firstCode = True
7786
elif line.strip() == "":
7887
if not firstCode:
7988
firstCode = True

0 commit comments

Comments
 (0)