Extract Python code blocks from a Markdown file.
(markdown_file_path: str)
| 15 | logger.setLevel(logging.INFO) |
| 16 | |
| 17 | def extract_python_code_blocks(markdown_file_path: str) -> List[Tuple[str, int]]: |
| 18 | """Extract Python code blocks from a Markdown file.""" |
| 19 | with open(markdown_file_path, "r", encoding="utf-8") as file: |
| 20 | lines = file.readlines() |
| 21 | |
| 22 | code_blocks: List[Tuple[str, int]] = [] |
| 23 | in_code_block = False |
| 24 | current_block: List[str] = [] |
| 25 | |
| 26 | for i, line in enumerate(lines): |
| 27 | if line.strip().startswith("```python"): |
| 28 | in_code_block = True |
| 29 | current_block = [] |
| 30 | elif line.strip().startswith("```"): |
| 31 | in_code_block = False |
| 32 | code_blocks.append(("\n".join(current_block), i - len(current_block) + 1)) |
| 33 | elif in_code_block: |
| 34 | current_block.append(line) |
| 35 | |
| 36 | return code_blocks |
| 37 | |
| 38 | def check_code_blocks(markdown_file_paths: List[str]) -> None: |
| 39 | """Check Python code blocks in a Markdown file for syntax errors.""" |
no test coverage detected