From d584137ba4c04f8334e3b08ae429a0546280e514 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 16:07:41 -0400 Subject: [PATCH 1/3] refs #30: Updated the tests for expected behaviour --- pydocx/tests/test_xml.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 4e5cf1a0..16b274c7 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -641,7 +641,7 @@ def test_performance(self): class NonStandardTextTagsTestCase(_TranslationTestCase): expected_output = ''' -

insert +

insert smarttag

''' @@ -674,8 +674,8 @@ def get_xml(self): class DeleteTagInList(_TranslationTestCase): expected_output = '''
    -
  1. AAA
    - BBB +
  2. AAA + BBB
  3. CCC
@@ -696,8 +696,7 @@ def get_xml(self): class InsertTagInList(_TranslationTestCase): expected_output = '''
    -
  1. AAA
    - BBB +
  2. AAABBB
  3. CCC
@@ -719,8 +718,7 @@ def get_xml(self): class SmartTagInList(_TranslationTestCase): expected_output = '''
    -
  1. AAA
    - BBB +
  2. AAABBB
  3. CCC
@@ -875,8 +873,7 @@ def get_xml(self): class SDTTestCase(_TranslationTestCase): expected_output = '''
    -
  1. AAA
    - BBB +
  2. AAABBB
  3. CCC
From c9c76fb0208f3ab27aa79a3025a4b29e2300db71 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 16:08:38 -0400 Subject: [PATCH 2/3] refs #30: no longer adding invalid attributes to insert and delete tags --- pydocx/parsers/Docx2Html.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pydocx/parsers/Docx2Html.py b/pydocx/parsers/Docx2Html.py index 782be941..525bdd9c 100644 --- a/pydocx/parsers/Docx2Html.py +++ b/pydocx/parsers/Docx2Html.py @@ -54,8 +54,7 @@ def heading(self, text, heading_value): def insertion(self, text, author, date): return ( - "%(text)s" + "%(text)s" ) % { 'author': author, 'date': date, @@ -88,8 +87,7 @@ def image(self, path, x, y): def deletion(self, text, author, date): return ( - "%(text)s" + "%(text)s" ) % { 'author': author, 'date': date, From 70fc06feaef7306b6e8bc285975e1dcbc31e5652 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Tue, 21 May 2013 16:10:18 -0400 Subject: [PATCH 3/3] refs #30: stopped break separating tags that were inline like (insert, delete, smart) --- pydocx/DocxParser.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pydocx/DocxParser.py b/pydocx/DocxParser.py index c57817f0..33c322d2 100644 --- a/pydocx/DocxParser.py +++ b/pydocx/DocxParser.py @@ -576,12 +576,22 @@ def parse_p(self, el, text): def _should_append_break_tag(self, next_el): paragraph_like_tags = [ 'p', - 'sdt', + ] + inline_like_tags = [ + 'smartTag', + 'ins', + 'delText', ] if next_el.is_list_item: return False if next_el.previous is None: return False + tag_is_inline_like = any( + next_el.has_descendant_with_tag(tag) for + tag in inline_like_tags + ) + if tag_is_inline_like: + return False if next_el.previous.is_last_list_item_in_root: return False if next_el.previous.tag not in paragraph_like_tags: