[silva.core.editor][Emiliano D'Alterio] Added fix to the image b...
[email protected] Tue, 17 Sep 2013 14:57:22 +0200
| Newsgroups | gmane.comp.web.zope.silva.cvs |
|---|---|
| Message-ID | <[email protected]> |
author: Emiliano D'Alterio
date: Tue Sep 17 14:57:16 2013 +0200
revision: 266:13da072f66cf in silva.core.editor
branch:
details: https://hg.infrae.com/silva.core.editor?cmd=changeset;node=13da072f66cf
modified: src/silva/core/editor/tests/test_transform_output_image.py src/silva/core/editor/transform/editor/output.py
added:
removed:
log: Added fix to the image block cleaning function to cover the case of
an image block without any image inside. Added a new test.
diffstat:
src/silva/core/editor/tests/test_transform_output_image.py | 22 ++++++++++++++
src/silva/core/editor/transform/editor/output.py | 7 ++++
2 files changed, 29 insertions(+), 0 deletions(-)
diffs (49 lines):
diff -r 58e796014b19 -r 13da072f66cf src/silva/core/editor/tests/test_transform_output_image.py
--- a/src/silva/core/editor/tests/test_transform_output_image.py Tue Sep 17 11:21:13 2013 +0200
+++ b/src/silva/core/editor/tests/test_transform_output_image.py Tue Sep 17 14:57:16 2013 +0200
@@ -309,6 +309,28 @@
self.assertXMLEqual(expected_image_block, actual_image_block)
+ def test_block_without_img(self):
+ """ An image block without an image inside has to be removed.
+ """
+ editor_image_block = """
+ <div class="image ">
+ <a class="wrong-class"
+ data-silva-anchor="Infrae"
+ data-silva-url="http://infrae.com"
+ target="_self"
+ title="Silva 3.0 Documentation">
+ </a>
+ <span class="wrong-class">CAPTION</span>
+ </div>
+ """
+
+ actual_image_block = self.transform(editor_image_block,
+ ISaveEditorFilter)
+
+ expected_image_block = """"""
+
+ self.assertXMLEqual(expected_image_block, actual_image_block)
+
def test_suite():
suite = unittest.TestSuite()
diff -r 58e796014b19 -r 13da072f66cf src/silva/core/editor/transform/editor/output.py
--- a/src/silva/core/editor/transform/editor/output.py Tue Sep 17 11:21:13 2013 +0200
+++ b/src/silva/core/editor/transform/editor/output.py Tue Sep 17 14:57:16 2013 +0200
@@ -87,6 +87,13 @@
## If the class has been modified we put the correct one.
caption.attrib['class'] = 'image-caption'
+ ## If the image block has no image inside
+ ## then it's invalid and we remove it.
+ if image is None:
+ block_tree.tag = 'invalid_image_block'
+ etree.strip_elements(block_tree, 'invalid_image_block')
+ return
+
## Sanitazing the caption, we strip out every element inside the span
## preserving the content and thus all the texts present.
if caption is not None: