Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exclude code blocks that aren't run#5307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gvwilson merged 2 commits intomkdocs-conversionfromupdate-script
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsbin/check-all-md.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsbin/run_markdown.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp