From 5ff70778f46e565a383fcf6b3d0dc34fd40b53d5 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 2 Jul 2013 13:18:57 -0400 Subject: [PATCH 1/4] refs #48: added a test showing that val=0 should not add the style --- pydocx/tests/test_xml.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 53841507..0ad2f2ad 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -15,6 +15,7 @@ class BoldTestCase(_TranslationTestCase): expected_output = """

AAA

BBB

+

CCC

""" def get_xml(self): @@ -35,6 +36,14 @@ def get_xml(self): ), ], ), + DXB.p_tag( + [ + DXB.r_tag( + [DXB.t_tag('CCC')], + rpr=DXB.rpr_tag({'b': '0'}), + ), + ], + ), ] body = '' From 0f7dad087a63c83370ddf33bdd7c06163d7cc083 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 2 Jul 2013 13:19:15 -0400 Subject: [PATCH 2/4] refs #48: val=0 no longer adds a style --- pydocx/DocxParser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pydocx/DocxParser.py b/pydocx/DocxParser.py index 0f734b5e..7f676c66 100644 --- a/pydocx/DocxParser.py +++ b/pydocx/DocxParser.py @@ -572,7 +572,10 @@ def _is_style_on(self, el): sufficient. You need to check to make sure it is not set to "false" as well. """ - return el.get('val') != 'false' + val = el.get('val') + if val is None: + return True + return val.lower() not in ['false', '0'] def parse_t(self, el, parsed): return self.escape(el.text) From 6a14f56c2189a941003ad39420ae3d42e286255d Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 2 Jul 2013 13:20:30 -0400 Subject: [PATCH 3/4] refs #48: update note --- CHANGELOG | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a3c57d6f..4c9fa946 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,9 +3,11 @@ Changelog ========= * 0.3.2 * We were not taking into account that vertical merges should have a - continue attribute, but sometimes they do not, and in those cases word - assumes the continue attribute. We updated the parser to handle the - cases in which the continue attribute is not there. + continue attribute, but sometimes they do not, and in those cases word + assumes the continue attribute. We updated the parser to handle the + cases in which the continue attribute is not there. + * In rare cases, some text would be output with a style when it should not + have been. This issue has been fixed. * 0.3.1 * Added support for several more OOXML tags including: * caps From d47be5b0f4354f12df2d352a6e21ca5793341992 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 2 Jul 2013 14:54:26 -0400 Subject: [PATCH 4/4] refs #48: refactor --- pydocx/DocxParser.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pydocx/DocxParser.py b/pydocx/DocxParser.py index 7f676c66..465d2786 100644 --- a/pydocx/DocxParser.py +++ b/pydocx/DocxParser.py @@ -30,6 +30,7 @@ INDENTATION_RIGHT = 'right' INDENTATION_LEFT = 'left' INDENTATION_FIRST_LINE = 'firstLine' +DISABLED_VALUES = ['false', '0'] # Add some helper functions to Element to make it slightly more readable @@ -572,10 +573,8 @@ def _is_style_on(self, el): sufficient. You need to check to make sure it is not set to "false" as well. """ - val = el.get('val') - if val is None: - return True - return val.lower() not in ['false', '0'] + val = el.get('val', '').lower() + return val.lower() not in DISABLED_VALUES def parse_t(self, el, parsed): return self.escape(el.text)