Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 59 additions and 6 deletions.
  1. +4 −0 CHANGELOG
  2. +12 −5 docx2html/core.py
  3. BIN docx2html/fixtures/bullet_go_gray.png
  4. +43 −1 docx2html/tests/test_xml.py
View
4 CHANGELOG
@@ -2,6 +2,10 @@
Changelog
=========
+* 0.1.11
+ * Sometimes in the OOXML an image will have a height or width of 0. If this
+ happens we are now ignoring the height and width in the OOXML and using
+ the full image instead.
* 0.1.10
* Added a user facing version
* 0.1.9
View
17 docx2html/core.py
@@ -73,6 +73,9 @@ def get_namespace(el, namespace):
def convert_image(target, image_size):
_, extension = os.path.splitext(os.path.basename(target))
+ # If the image size has a zero in it early return
+ if image_size and not all(image_size):
+ return target
# All the image types need to be converted to gif.
invalid_extensions = (
'.bmp',
@@ -1279,11 +1282,15 @@ def get_p_data(p, meta_data, is_td=False):
else:
target = meta_data.relationship_dict[image_id]
width, height = _get_image_size_from_image(target)
- p_text += '<img src="%s" height="%d" width="%d"/>' % (
- src,
- height,
- width,
- )
+ # Make sure the width and height are not zero
+ if all((width, height)):
+ p_text += '<img src="%s" height="%d" width="%d" />' % (
+ src,
+ height,
+ width,
+ )
+ else:
+ p_text += '<img src="%s" />' % src
# This function does not return a p tag since other tag types need this as
# well (td, li).
View
BIN docx2html/fixtures/bullet_go_gray.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
44 docx2html/tests/test_xml.py
@@ -1,17 +1,19 @@
+import os
import mock
from itertools import chain
from lxml import etree
from copy import copy
from docx2html.core import (
_is_top_level_upper_roman,
+ convert_image,
create_html,
get_font_size,
get_image_id,
get_li_nodes,
+ get_namespace,
get_relationship_info,
get_style_dict,
- get_namespace,
is_last_li,
)
from docx2html.tests.document_builder import DocxBuilder as DXB
@@ -356,6 +358,46 @@ def test_get_relationship_info(self):
self.assertEqual(relationship_info, {})
+class ImageNoSizeTestCase(_TranslationTestCase):
+ relationship_dict = {
+ 'rId0': os.path.join(
+ os.path.abspath(os.path.dirname(__file__)),
+ '..',
+ 'fixtures',
+ 'bullet_go_gray.png',
+ )
+ }
+ image_sizes = {
+ 'rId0': (0, 0),
+ }
+ expected_output = '''
+ <html>
+ <p>
+ <img src="%s" />
+ </p>
+ </html>
+ ''' % relationship_dict['rId0']
+
+ @staticmethod
+ def image_handler(image_id, relationship_dict):
+ return relationship_dict.get(image_id)
+
+ def get_xml(self):
+ drawing = DXB.drawing('rId0')
+ tags = [
+ drawing,
+ ]
+ body = ''
+ for el in tags:
+ body += el
+
+ xml = DXB.xml(body)
+ return etree.fromstring(xml)
+
+ def test_convert_image(self):
+ convert_image(self.relationship_dict['rId0'], self.image_sizes['rId0'])
+
+
class ListWithContinuationTestCase(_TranslationTestCase):
expected_output = '''
<html>

No commit comments for this range

Something went wrong with that request. Please try again.