diff --git a/mkdocs_glightbox/plugin.py b/mkdocs_glightbox/plugin.py index a156d17..a7ca89e 100644 --- a/mkdocs_glightbox/plugin.py +++ b/mkdocs_glightbox/plugin.py @@ -96,8 +96,16 @@ def on_post_page(self, output, page, config, **kwargs): js_code = "" if self.using_material_privacy: js_code += """document.querySelectorAll('.glightbox').forEach(function(element) { - var imgSrc = element.querySelector('img').src; - element.setAttribute('href', imgSrc); + try { + var img = element.querySelector('img'); + if (img && img.src) { + element.setAttribute('href', img.src); + } else { + console.log('No img element with src attribute found'); + } + } catch (error) { + console.log('Error:', error); + } }); """ js_code += f"const lightbox = GLightbox({json.dumps(lb_config)});\n" diff --git a/tests/fixtures/docs/edge_cases.md b/tests/fixtures/docs/edge_cases.md new file mode 100644 index 0000000..23c7ba6 --- /dev/null +++ b/tests/fixtures/docs/edge_cases.md @@ -0,0 +1 @@ +

Not an image