diff --git a/CHANGES.txt b/CHANGES.txt index c8d7e41..e7e7da3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,13 @@ Changelog 1.0b4 (unreleased) ------------------ +- Add alt and title tags to images. + [elro] + +- Get various image properties from the imaging view to work better with + Dexterity. + [elro] + - small fix so it is possible to create object without need of REQUEST or without need of mocking it. [garbas] diff --git a/plone/outputfilters/filters/resolveuid_and_caption.py b/plone/outputfilters/filters/resolveuid_and_caption.py index bb47756..a4ffb17 100644 --- a/plone/outputfilters/filters/resolveuid_and_caption.py +++ b/plone/outputfilters/filters/resolveuid_and_caption.py @@ -35,6 +35,10 @@ class IResolveUidsEnabler(Interface): singleton_tags = ["img", "area", "br", "hr", "input", "meta", "param", "col"] +def tag(img, **attributes): + if hasattr(aq_base(img), 'tag'): + return img.tag(**attributes) + class ResolveUIDAndCaptionFilter(SGMLParser): """ Parser to convert UUID links and captioned images """ @@ -199,6 +203,21 @@ def handle_captioned_image(self, attributes, image, fullimage, caption): klass = attributes['class'] del attributes['class'] del attributes['src'] + view = fullimage.restrictedTraverse('@@images', None) + if view is not None: + original_width, original_height = view.getImageSize() + else: + original_width, original_height = fullimage.width, fullimage.height + if image is not fullimage: + # image is a scale object + tag = image.tag + width = image.width + else: + if hasattr(aq_base(image), 'tag'): + tag = image.tag + else: + tag = view.tag + width = original_width options = { 'class': klass, 'originalwidth': attributes.get('width', None), @@ -207,10 +226,11 @@ def handle_captioned_image(self, attributes, image, fullimage, caption): 'caption': newline_to_br(html_quote(caption)), 'image': image, 'fullimage': fullimage, - 'tag': image.tag(**attributes), - 'isfullsize': (image.width == fullimage.width and - image.height == fullimage.height), - 'width': attributes.get('width', image.width), + 'tag': tag(**attributes), + 'isfullsize': image is fullimage or ( + image.width == original_width and + image.height == original_height), + 'width': attributes.get('width', width), } if self.in_link: # Must preserve original link, don't overwrite @@ -267,7 +287,13 @@ def unknown_starttag(self, tag, attrs): caption) return True else: - # Nothing happens with the image, so add it normally + if fullimage is not None: + # Check to see if the alt / title tags need setting + title = fullimage.Title() + if 'alt' not in attributes: + attributes['alt'] = title + if 'title' not in attributes: + attributes['title'] = title attrs = attributes.iteritems() # Add the tag to the result diff --git a/plone/outputfilters/tests/test_resolveuid_and_caption.py b/plone/outputfilters/tests/test_resolveuid_and_caption.py index 727bf12..c0ab67d 100644 --- a/plone/outputfilters/tests/test_resolveuid_and_caption.py +++ b/plone/outputfilters/tests/test_resolveuid_and_caption.py @@ -172,7 +172,7 @@ def test_BBB_uuidToObject(self): def test_image_captioning_absolutizes_uncaptioned_image(self): text_in = """""" - text_out = """""" + text_out = """Image""" self._assertTransformsTo(text_in, text_out) def test_image_captioning_absolute_path(self):