@@ -80,10 +80,8 @@ def _process_rst_content(self, content: str) -> str:
8080 """
8181 lines = content .split ("\n " )
8282 result_lines = []
83- in_code_block = False
8483 in_license_header = False
8584 in_directive_block = False
86- code_block_indent = 0
8785 directive_indent = 0
8886
8987 # Check if we start with a license header
@@ -116,23 +114,7 @@ def _process_rst_content(self, content: str) -> str:
116114 i = next_i
117115 continue
118116
119- # Handle code blocks
120- if self ._is_code_block_start (line ):
121- in_code_block = True
122- code_block_indent = self ._get_indent_level (line )
123- result_lines .append (line )
124- i += 1
125- continue
126-
127- if in_code_block :
128- if self ._is_code_block_end (line , code_block_indent ):
129- in_code_block = False
130- else :
131- result_lines .append (line )
132- i += 1
133- continue
134-
135- # Handle RST directive blocks
117+ # Handle RST directive blocks (including code blocks)
136118 if self ._is_rst_directive_start (line ):
137119 in_directive_block = True
138120 directive_indent = self ._get_indent_level (line )
@@ -149,7 +131,7 @@ def _process_rst_content(self, content: str) -> str:
149131 continue
150132
151133 # Process regular content (only when not in special blocks)
152- if not in_code_block and not in_license_header and not in_directive_block :
134+ if not in_license_header and not in_directive_block :
153135 paragraph_lines , next_i = self ._collect_paragraph (lines , i )
154136 processed_lines = self ._process_paragraph (paragraph_lines )
155137 result_lines .extend (processed_lines )
@@ -317,51 +299,10 @@ def _collect_table(self, lines: List[str], start_idx: int) -> Tuple[List[str], i
317299
318300 return table_lines , i
319301
320- def _is_code_block_start (self , line : str ) -> bool :
321- """Check if line starts a code block."""
322- return bool (re .match (r"^\s*\.\.\s+(code-block|literalinclude)::" , line ))
323-
324- def _is_code_block_end (self , line : str , code_block_indent : int ) -> bool :
325- """Check if code block ends."""
326- if not line .strip ():
327- return False
328- current_indent = self ._get_indent_level (line )
329- return current_indent <= code_block_indent
330-
331302 def _is_rst_directive_start (self , line : str ) -> bool :
332303 """Check if line starts an RST directive that has indented content."""
333- # Match RST directives that typically have indented content
334- directive_patterns = [
335- r"^\s*\.\.\s+list-table::" ,
336- r"^\s*\.\.\s+table::" ,
337- r"^\s*\.\.\s+csv-table::" ,
338- r"^\s*\.\.\s+image::" ,
339- r"^\s*\.\.\s+figure::" ,
340- r"^\s*\.\.\s+note::" ,
341- r"^\s*\.\.\s+warning::" ,
342- r"^\s*\.\.\s+attention::" ,
343- r"^\s*\.\.\s+caution::" ,
344- r"^\s*\.\.\s+danger::" ,
345- r"^\s*\.\.\s+error::" ,
346- r"^\s*\.\.\s+hint::" ,
347- r"^\s*\.\.\s+important::" ,
348- r"^\s*\.\.\s+tip::" ,
349- r"^\s*\.\.\s+admonition::" ,
350- r"^\s*\.\.\s+sidebar::" ,
351- r"^\s*\.\.\s+topic::" ,
352- r"^\s*\.\.\s+rubric::" ,
353- r"^\s*\.\.\s+epigraph::" ,
354- r"^\s*\.\.\s+highlights::" ,
355- r"^\s*\.\.\s+pull-quote::" ,
356- r"^\s*\.\.\s+compound::" ,
357- r"^\s*\.\.\s+container::" ,
358- r"^\s*\.\.\s+raw::" ,
359- r"^\s*\.\.\s+include::" ,
360- r"^\s*\.\.\s+math::" ,
361- r"^\s*\.\.\s+\w+::" , # Generic directive pattern
362- ]
363-
364- return any (re .match (pattern , line ) for pattern in directive_patterns )
304+ # Match any RST directive pattern (allowing hyphens in directive names)
305+ return bool (re .match (r"^\s*\.\.\s+[\w-]+::" , line ))
365306
366307 def _is_directive_block_end (self , line : str , directive_indent : int ) -> bool :
367308 """Check if directive block ends."""
0 commit comments