diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 7fb8fc0..012c718 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3777,7 +3777,7 @@ def clean_input(text, ignore=None): 'p', 'br', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'table', 'td', 'tr', 'th', 'thead', 'tbody', 'col', 'pre', 'img', 'hr', 'dl', 'dt', 'dd', 'span', - 'kbd', 'var', 'del', 'cite', + 'kbd', 'var', 'del', 'cite', 'noscript' ] if ignore: for tag in ignore: diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py index 8a012f4..3eedb8c 100644 --- a/pagure/pfmarkdown.py +++ b/pagure/pfmarkdown.py @@ -326,10 +326,25 @@ class ImagePatternLazyLoad(markdown.inlinepatterns.ImagePattern): def handleMatch(self, m): el = super(ImagePatternLazyLoad, self).handleMatch(m) - el.set('class', 'lazyload') - el.set('data-src', el.get('src')) - el.set('src', '') - return el + + # Add a noscript tag with the untouched img tag + noscript = markdown.util.etree.Element("noscript") + noscript.append(el) + + # Modify the origina img tag + img = markdown.util.etree.Element("img") + img.set('data-src', el.get('src')) + img.set('src', '') + img.set('alt', el.get('alt')) + img.set('class', 'lazyload') + + # Create a global span in which we add both the new img tag and the + # noscript one + outel = markdown.util.etree.Element("span") + outel.append(img) + outel.append(noscript) + + return outel class PagureExtension(markdown.extensions.Extension): diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 5dccd74..fc18239 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -4352,10 +4352,13 @@ class PagureLibtests(tests.Modeltests): # '[![Fedora_infinity_small.png]' # '(/test/issue/raw/Fedora_infinity_small.png)]' # '(/test/issue/raw/Fedora_infinity_small.png)', - '
', ] with self.app.application.app_context():