Skip to content

Commit e30fffd

Browse files
author
Jason Ward
committed
refs #27: added a test showing how an sdt tag should be handled.
1 parent b1dac0a commit e30fffd

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

pydocx/tests/document_builder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'p': 'p.xml',
1010
'pict': 'pict.xml',
1111
'r': 'r.xml',
12+
'sdt': 'sdt.xml',
1213
'sectPr': 'sectPr.xml',
1314
'smartTag': 'smart_tag.xml',
1415
'style': 'style.xml',
@@ -85,6 +86,14 @@ def smart_tag(self, run_tags):
8586
}
8687
return template.render(**kwargs)
8788

89+
@classmethod
90+
def sdt_tag(self, p_tag):
91+
template = env.get_template(templates['sdt'])
92+
kwargs = {
93+
'p_tag': p_tag,
94+
}
95+
return template.render(**kwargs)
96+
8897
@classmethod
8998
def li(self, text, ilvl, numId, bold=False):
9099
if isinstance(text, str):

pydocx/tests/templates/sdt.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<w:sdt>
2+
<w:sdtPr>
3+
<w:rPr>
4+
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman"/>
5+
<w:sz w:val="22"/>
6+
</w:rPr>
7+
<w:alias w:val="PolicyTemplateTitle"/>
8+
<w:tag w:val="PolicyTemplateTitle"/>
9+
<w:id w:val="95087797"/>
10+
<w:lock w:val="sdtLocked"/>
11+
<w:text/>
12+
</w:sdtPr>
13+
<w:sdtContent>
14+
{{ p_tag }}
15+
</w:sdtContent>
16+
</w:sdt>

pydocx/tests/test_xml.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ class SameNumIdInTable(_TranslationTestCase):
764764
</ol>
765765
</body></html>
766766
'''
767+
767768
# Ensure its not failing somewhere and falling back to decimal
768769
numbering_dict = {
769770
'1': {
@@ -786,5 +787,28 @@ def get_xml(self):
786787
lis += table
787788
lis += DXB.li(text='CCC', ilvl=0, numId=1)
788789
body = lis
790+
791+
xml = DXB.xml(body)
792+
return xml
793+
794+
795+
class SDTTestCase(_TranslationTestCase):
796+
expected_output = '''
797+
<html><body>
798+
<ol data-list-type="decimal">
799+
<li>AAA<br/>
800+
BBB
801+
</li>
802+
<li>CCC</li>
803+
</ol>
804+
</body></html>
805+
'''
806+
807+
def get_xml(self):
808+
body = ''
809+
body += DXB.li(text='AAA', ilvl=0, numId=0)
810+
body += DXB.sdt_tag(p_tag=DXB.p_tag(text='BBB'))
811+
body += DXB.li(text='CCC', ilvl=0, numId=0)
812+
789813
xml = DXB.xml(body)
790814
return xml

0 commit comments

Comments
 (0)