File tree Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
import os
3
- import re
4
3
import sys
4
+ from run_markdown import _parse_md
5
5
6
- PAT = re .compile (r"^```python\n(.+?)\n```" , re .MULTILINE | re .DOTALL )
7
6
TMP_FILE = "tmp.py"
8
7
9
8
for filename in sys .argv [1 :]:
10
9
content = Path (filename ).read_text ()
11
- blocks = PAT . findall (content )
12
- for i , b in enumerate (blocks ):
13
- Path (TMP_FILE ).write_text (b .strip ())
10
+ blocks = _parse_md (content )
11
+ for i , block in enumerate (blocks ):
12
+ Path (TMP_FILE ).write_text (block [ "code" ] .strip ())
14
13
sys .stdout .write (f"\n { '=' * 40 } \n { filename } : { i } \n " )
15
14
sys .stdout .flush ()
16
15
sys .stdout .write (f"{ '-' * 40 } \n " )
Original file line number Diff line number Diff line change @@ -162,17 +162,26 @@ def _parse_md(content):
162
162
blocks = []
163
163
current_block = None
164
164
in_code_block = False
165
+ in_region_block = False
165
166
166
167
for i , line in enumerate (lines ):
168
+ # Check for region start/end markers
169
+ if "<!-- #region" in line :
170
+ in_region_block = True
171
+ elif "<!-- #endregion" in line :
172
+ in_region_block = False
173
+
167
174
# Start of Python code block
168
- if line .strip ().startswith ("```python" ):
169
- in_code_block = True
170
- current_block = {
171
- "start_line" : i ,
172
- "end_line" : None ,
173
- "code" : [],
174
- "type" : "python" ,
175
- }
175
+ elif line .strip ().startswith ("```python" ):
176
+ # Only process code blocks that are NOT inside region blocks
177
+ if not in_region_block :
178
+ in_code_block = True
179
+ current_block = {
180
+ "start_line" : i ,
181
+ "end_line" : None ,
182
+ "code" : [],
183
+ "type" : "python" ,
184
+ }
176
185
177
186
# End of code block
178
187
elif line .strip () == "```" and in_code_block :
You can’t perform that action at this time.
0 commit comments