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

Commite45f54c

Browse files
authored
Merge pull request#5307 from plotly/update-script
Exclude code blocks that aren't run
2 parentsa07ea45 +2e38a9a commite45f54c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

‎bin/check-all-md.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
frompathlibimportPath
22
importos
3-
importre
43
importsys
4+
fromrun_markdownimport_parse_md
55

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

98
forfilenameinsys.argv[1:]:
109
content=Path(filename).read_text()
11-
blocks=PAT.findall(content)
12-
fori,binenumerate(blocks):
13-
Path(TMP_FILE).write_text(b.strip())
10+
blocks=_parse_md(content)
11+
fori,blockinenumerate(blocks):
12+
Path(TMP_FILE).write_text(block["code"].strip())
1413
sys.stdout.write(f"\n{'='*40}\n{filename}:{i}\n")
1514
sys.stdout.flush()
1615
sys.stdout.write(f"{'-'*40}\n")

‎bin/run_markdown.py‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,26 @@ def _parse_md(content):
162162
blocks= []
163163
current_block=None
164164
in_code_block=False
165+
in_region_block=False
165166

166167
fori,lineinenumerate(lines):
168+
# Check for region start/end markers
169+
if"<!-- #region"inline:
170+
in_region_block=True
171+
elif"<!-- #endregion"inline:
172+
in_region_block=False
173+
167174
# Start of Python code block
168-
ifline.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+
elifline.strip().startswith("```python"):
176+
# Only process code blocks that are NOT inside region blocks
177+
ifnotin_region_block:
178+
in_code_block=True
179+
current_block= {
180+
"start_line":i,
181+
"end_line":None,
182+
"code": [],
183+
"type":"python",
184+
}
176185

177186
# End of code block
178187
elifline.strip()=="```"andin_code_block:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp