Skip to content

Commit

Permalink
Merge pull request #29 from michalfapso/main
Browse files Browse the repository at this point in the history
added "manual" option
  • Loading branch information
blueswen authored May 4, 2024
2 parents dc38a6c + 6895d4e commit d7747e7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GLightbox is a pure javascript lightbox library with mobile support.
caption_position: bottom
background: white
shadow: true
manual: false
```

| Option | Default | Description |
Expand All @@ -70,6 +71,7 @@ GLightbox is a pure javascript lightbox library with mobile support.
| caption_position | bottom | Default captions position. (bottom, top, left, right) |
| background | white | The background CSS of lightbox image. The background will shown when the image is transparent. You can use any CSS value for the background for example `#74b9ff` or `Gainsboro` or `none` for nothing. |
| shadow | true | Enable or disable the shadow of lightbox image. Disable it when the background is `none` to prevent shadow around the transparent image. |
| manual | false | When true, lightbox has to be enabled for each image manually by adding 'on-glb' class to it. |

Check more options information on [GLightbox Docs](https://github.com/biati-digital/glightbox#lightbox-options).

Expand Down
2 changes: 2 additions & 0 deletions demo-mkdocs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ GLightbox is a pure javascript lightbox library with mobile support.
caption_position: bottom
background: white
shadow: true
manual: false
```

| Option | Default | Description |
Expand All @@ -68,6 +69,7 @@ GLightbox is a pure javascript lightbox library with mobile support.
| caption_position | bottom | Default captions position. (bottom, top, left, right) |
| background | white | The background CSS of lightbox image. The background will shown when the image is transparent. You can use any CSS value for the background for example `#74b9ff` or `Gainsboro` or `none` for nothing. |
| shadow | true | Enable or disable the shadow of lightbox image. Disable it when the background is `none` to prevent shadow around the transparent image. |
| manual | false | When true, lightbox has to be enabled for each image manually by adding 'on-glb' class to it. |

Check more options information on [GLightbox Docs](https://github.com/biati-digital/glightbox#lightbox-options).

Expand Down
3 changes: 2 additions & 1 deletion mkdocs_glightbox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LightboxPlugin(BasePlugin):
),
("background", config_options.Type(str, default="white")),
("shadow", config_options.Type(bool, default=True)),
("manual", config_options.Type(bool, default=False)),
)

def on_config(self, config):
Expand Down Expand Up @@ -156,7 +157,7 @@ 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 meta.get("glightbox-manual", False):
if meta.get("glightbox-manual", False) or self.config["manual"]:
if "on-glb" not in classes:
return img_tag
else:
Expand Down
6 changes: 6 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
"markdownDescription": "https://blueswen.github.io/mkdocs-glightbox/#usage",
"type": "boolean",
"default": true
},
"manual": {
"title": "When true, lightbox has to be enabled for each image manually by adding 'on-glb' class to it",
"markdownDescription": "https://blueswen.github.io/mkdocs-glightbox/#usage",
"type": "boolean",
"default": false
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/docs/manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![image](img.png){ .on-glb }
9 changes: 9 additions & 0 deletions tests/fixtures/mkdocs-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
site_name: test mkdocs_glightbox
use_directory_urls: true

markdown_extensions:
- attr_list

plugins:
- glightbox:
manual: true
1 change: 1 addition & 0 deletions tests/fixtures/mkdocs-options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ plugins:
auto_caption: true
background: none
shadow: false
manual: false
28 changes: 28 additions & 0 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,31 @@ def test_enable_by_image(tmp_path):
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?class="on-glb".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)


def test_manual(tmp_path):
"""
Manual mode
"""
mkdocs_file = "mkdocs-manual.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert (
re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
is None
)

file = testproject_path / "site/manual/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="..\/img\.png".*?>\s*<img.*?src="..\/img\.png".*?\/><\/a>',
contents,
)

0 comments on commit d7747e7

Please sign in to comment.