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
6 changes: 6 additions & 0 deletions .github/scripts/wiki_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
_FENCE = re.compile(r"^( {0,3})(`{3,}|~{3,})")
_ASSET_DIR = "assets"
_ASSET_SUFFIXES = (".png",)
# The wiki's own image URL, root-relative: the same from every page, including Home,
# which GitHub serves at /OWNER/REPO/wiki where a relative assets/ path misses the wiki.
_ROOTED_ASSET = re.compile(r"^/[^/]+/[^/]+/wiki/(assets/[^/?#]+)$")
_ASSET_REFERENCE = re.compile(r"""(?:src|srcset)\s*=\s*["']([^"']+)["']|!\[[^]\n]*\]\(([^)\s]+)""")


Expand Down Expand Up @@ -166,6 +169,9 @@ def validate(wiki_dir: Path) -> list[str]:
visible_text = _without_code(text)
for match in _ASSET_REFERENCE.finditer(visible_text):
reference = (match.group(1) or match.group(2)).strip()
rooted = _ROOTED_ASSET.match(reference)
if rooted:
reference = rooted.group(1)
if _is_external(reference) or not reference.startswith(f"{_ASSET_DIR}/"):
continue
if reference not in assets:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_wiki_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def test_rejects_missing_image(tmp_path: Path) -> None:
assert "references a missing image: assets/flow-dark.png" in result.stderr


def test_checks_root_relative_images_against_assets(tmp_path: Path) -> None:
wiki_dir = tmp_path / "wiki"
page = '<img alt="Flow" src="/Owner/Repo/wiki/assets/flow-light.png">\n'
_write_pages(wiki_dir, **{"Flow.md": page, "Lost.md": page.replace("flow-light", "lost")})
_write_assets(wiki_dir, "flow-light.png")

result = _run_validator(wiki_dir)

assert result.returncode == 1
assert "references a missing image: assets/lost.png" in result.stderr
assert "flow-light" not in result.stderr


def test_rejects_non_png_files_in_assets(tmp_path: Path) -> None:
wiki_dir = tmp_path / "wiki"
_write_pages(wiki_dir)
Expand Down
6 changes: 3 additions & 3 deletions wiki/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ It is written for proteomics first, where a protein can be missing from a whole

<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/batch-shift-dark.png">
<source media="(prefers-color-scheme: light)" srcset="assets/batch-shift-light.png">
<img alt="Four proteins measured in two batches: batch 2 reads about 1.5 units higher before correction, and the two batch means come within 0.3 of each other after harmonize()." src="assets/batch-shift-light.png">
<source media="(prefers-color-scheme: dark)" srcset="/LangeLab/HarmonizePy/wiki/assets/batch-shift-dark.png">
<source media="(prefers-color-scheme: light)" srcset="/LangeLab/HarmonizePy/wiki/assets/batch-shift-light.png">
<img alt="Four proteins measured in two batches: batch 2 reads about 1.5 units higher before correction, and the two batch means come within 0.3 of each other after harmonize()." src="/LangeLab/HarmonizePy/wiki/assets/batch-shift-light.png">
</picture>
</p>
<p align="center"><sub><b>Figure 1.</b> Four proteins from the <a href="Quick-Start">Quick start</a> example. Each short bar is a batch mean: the dashed line between them is the batch effect, and after correction it is nearly flat while each protein keeps its own level.</sub></p>
Expand Down
Loading