From 51e109968beb0c4f2fc4ac8524c3bbf1b74da369 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 12 Apr 2020 15:09:16 +0100 Subject: Only parse integer font sizes --- mammoth/docx/body_xml.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'mammoth/docx') diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 7bb8628..e65c5b2 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -81,7 +81,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f font = properties.find_child_or_null("w:rFonts").attributes.get("w:ascii") font_size_string = properties.find_child_or_null("w:sz").attributes.get("w:val") - if font_size_string: + if _is_int(font_size_string): # w:sz gives the font size in half points, so halve the value to get the size in points font_size = int(font_size_string) / 2 else: @@ -602,3 +602,15 @@ def _add_attrs(obj, **kwargs): setattr(obj, key, value) return obj + + +def _is_int(value): + if value is None: + return False + + try: + int(value) + except ValueError: + return False + + return True -- cgit v1.2.3