Skip to content

Commit

Permalink
Support only enable glightbox with on-glb class in given page (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueswen committed Dec 30, 2023
1 parent c61c0fa commit 8fa0e04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mkdocs_glightbox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ def wrap_img_with_anchor(self, match, plugin_config, skip_class, meta):
classes = re.findall(r'class="([^"]+)"', img_attr)
classes = [c for match in classes for c in match.split()]

if set(skip_class) & set(classes):
return img_tag
if meta.get("glightbox-manual", False):
if "on-glb" not in classes:
return img_tag
else:
if set(skip_class) & set(classes):
return img_tag

if self.using_material_privacy:
# skip href attribute if using material privacy plugin, will be set by js code
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/docs/enable_by_image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
glightbox-manual: true
---

![image](img.png){.on-glb}

![image](img.png)
21 changes: 21 additions & 0 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,24 @@ def test_privacy(tmp_path):
rf"{patch_script}",
contents,
)


def test_enable_by_image(tmp_path):
"""
Enable by the image with on-glb class
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/enable_by_image/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
assert re.search(
rf'<p><img alt="image" src="{re.escape(path)}img\.png" \/><\/p>',
contents,
)
assert re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?class="on-glb".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)

0 comments on commit 8fa0e04

Please sign in to comment.