Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bin/check-all-md.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from pathlib import Path
import os
import re
import sys
from run_markdown import _parse_md

PAT = re.compile(r"^```python\n(.+?)\n```", re.MULTILINE | re.DOTALL)
TMP_FILE = "tmp.py"

for filename in sys.argv[1:]:
content = Path(filename).read_text()
blocks = PAT.findall(content)
for i, b in enumerate(blocks):
Path(TMP_FILE).write_text(b.strip())
blocks = _parse_md(content)
for i, block in enumerate(blocks):
Path(TMP_FILE).write_text(block["code"].strip())
sys.stdout.write(f"\n{'=' * 40}\n{filename}: {i}\n")
sys.stdout.flush()
sys.stdout.write(f"{'-' * 40}\n")
Expand Down
25 changes: 17 additions & 8 deletions bin/run_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,26 @@ def _parse_md(content):
blocks = []
current_block = None
in_code_block = False
in_region_block = False

for i, line in enumerate(lines):
# Check for region start/end markers
if "<!-- #region" in line:
in_region_block = True
elif "<!-- #endregion" in line:
in_region_block = False

# Start of Python code block
if line.strip().startswith("```python"):
in_code_block = True
current_block = {
"start_line": i,
"end_line": None,
"code": [],
"type": "python",
}
elif line.strip().startswith("```python"):
# Only process code blocks that are NOT inside region blocks
if not in_region_block:
in_code_block = True
current_block = {
"start_line": i,
"end_line": None,
"code": [],
"type": "python",
}

# End of code block
elif line.strip() == "```" and in_code_block:
Expand Down