diff --git a/pydocx/DocxParser.py b/pydocx/DocxParser.py index c24e0ae8..c57817f0 100644 --- a/pydocx/DocxParser.py +++ b/pydocx/DocxParser.py @@ -23,6 +23,7 @@ TAGS_HOLDING_CONTENT_TAGS = ( 'p', 'tbl', + 'sdt', ) @@ -573,15 +574,19 @@ def parse_p(self, el, text): return parsed def _should_append_break_tag(self, next_el): + paragraph_like_tags = [ + 'p', + 'sdt', + ] if next_el.is_list_item: return False if next_el.previous is None: return False if next_el.previous.is_last_list_item_in_root: return False - if next_el.previous.tag != 'p': + if next_el.previous.tag not in paragraph_like_tags: return False - if next_el.tag != 'p': + if next_el.tag not in paragraph_like_tags: return False return True diff --git a/pydocx/tests/document_builder.py b/pydocx/tests/document_builder.py index 3a011159..cf67f2cc 100644 --- a/pydocx/tests/document_builder.py +++ b/pydocx/tests/document_builder.py @@ -10,6 +10,7 @@ 'p': 'p.xml', 'pict': 'pict.xml', 'r': 'r.xml', + 'sdt': 'sdt.xml', 'sectPr': 'sectPr.xml', 'smartTag': 'smart_tag.xml', 'style': 'style.xml', @@ -95,6 +96,14 @@ def smart_tag(self, run_tags): } return template.render(**kwargs) + @classmethod + def sdt_tag(self, p_tag): + template = env.get_template(templates['sdt']) + kwargs = { + 'p_tag': p_tag, + } + return template.render(**kwargs) + @classmethod def li(self, text, ilvl, numId, bold=False): if isinstance(text, str): diff --git a/pydocx/tests/templates/sdt.xml b/pydocx/tests/templates/sdt.xml new file mode 100644 index 00000000..fe9a7e77 --- /dev/null +++ b/pydocx/tests/templates/sdt.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + {{ p_tag }} + + diff --git a/pydocx/tests/test_xml.py b/pydocx/tests/test_xml.py index 801f4210..84eba75d 100644 --- a/pydocx/tests/test_xml.py +++ b/pydocx/tests/test_xml.py @@ -891,6 +891,7 @@ class SameNumIdInTable(_TranslationTestCase): ''' + # Ensure its not failing somewhere and falling back to decimal numbering_dict = { '1': { @@ -913,5 +914,28 @@ def get_xml(self): lis += table lis += DXB.li(text='CCC', ilvl=0, numId=1) body = lis + + xml = DXB.xml(body) + return xml + + +class SDTTestCase(_TranslationTestCase): + expected_output = ''' + +
    +
  1. AAA
    + BBB +
  2. +
  3. CCC
  4. +
+ + ''' + + def get_xml(self): + body = '' + body += DXB.li(text='AAA', ilvl=0, numId=0) + body += DXB.sdt_tag(p_tag=DXB.p_tag(text='BBB')) + body += DXB.li(text='CCC', ilvl=0, numId=0) + xml = DXB.xml(body) return xml