@@ -202,25 +202,27 @@ def _format_section(self, keyword: str, raw_lines: t.List[str]) -> t.List[str]:
202202 codeblock_indent = min (max (section_indent - preserve_indent , 0 ), self ._get_indentation (raw_line ))
203203 rebased = self ._remove_indentation (raw_line , codeblock_indent ).rstrip ()
204204 rebased_indent = self ._get_indentation (rebased )
205- list_content_indent : t .Optional [int ] = None
205+ container_content_indent : t .Optional [int ] = None
206206 for previous_index in range (len (result ) - 1 , - 1 , - 1 ):
207207 previous = result [previous_index ]
208208 if not previous .strip ():
209209 continue
210210 previous_indent = self ._get_indentation (previous )
211211 if previous_indent > rebased_indent :
212212 continue
213+ is_nested = self ._get_indentation (raw_line ) > self ._get_indentation (raw_lines [previous_index ])
213214 list_match = re .match (r"^\s*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)" , previous )
214- if list_match and self ._get_indentation (raw_line ) > self ._get_indentation (
215- raw_lines [previous_index ]
216- ):
217- list_content_indent = len (list_match .group ().expandtabs (4 ))
215+ if list_match and is_nested :
216+ container_content_indent = len (list_match .group ().expandtabs (4 ))
218217 if list_match .end () == len (previous ):
219- list_content_indent += 1
218+ container_content_indent += 1
219+ admonition_match = re .match (r"^\s*(?:!!!|\?{3}\+?)(?:[ \t]+|$)" , previous )
220+ if admonition_match and is_nested :
221+ container_content_indent = previous_indent + 4
220222 break
221223 codeblock_prefix = (
222- " " * max (list_content_indent - rebased_indent , 0 )
223- if list_content_indent is not None and rebased_indent
224+ " " * max (container_content_indent - rebased_indent , 0 )
225+ if container_content_indent is not None and rebased_indent
224226 else ""
225227 )
226228 result .append (codeblock_prefix + rebased )
0 commit comments