File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ def r_elms(self):
4545 return ()
4646 return tuple ([r for r in self .r ])
4747
48+ @property
49+ def style (self ):
50+ """
51+ String contained in w:val attribute of <w:pPr><w:pStyle> child, or
52+ None if that element is not present.
53+ """
54+ return self .pPr .style if hasattr (self , 'pPr' ) else None
55+
4856
4957class CT_PPr (OxmlBaseElement ):
5058 """
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ def it_can_add_an_r_to_itself(self):
3535 assert p .xml == a_p ().with_nsdecls ().with_r ().xml
3636 assert isinstance (r , CT_R )
3737
38+ def it_knows_its_paragraph_style (self ):
39+ # effectively an integration test with CT_PPr
40+ pPr = a_pPr ().with_style ('foobar' )
41+ cases = (
42+ (a_p (), None ),
43+ (a_p ().with_pPr (pPr ), 'foobar' ),
44+ )
45+ for builder , expected_value in cases :
46+ print builder .with_nsdecls ().xml
47+ p = builder .with_nsdecls ().element
48+ assert p .style == expected_value
49+
3850
3951class DescribeCT_PPr (object ):
4052
Original file line number Diff line number Diff line change @@ -121,11 +121,19 @@ class CT_PBuilder(BaseBuilder):
121121 def __init__ (self ):
122122 """Establish instance variables with default values"""
123123 super (CT_PBuilder , self ).__init__ ()
124+ self ._pPr = None
124125 self ._r = []
125126
126127 @property
127128 def is_empty (self ):
128- return len (self ._r ) == 0
129+ return self ._pPr is None and len (self ._r ) == 0
130+
131+ def with_pPr (self , pPr = None ):
132+ """Add a <w:pPr> child element"""
133+ if pPr is None :
134+ pPr = a_pPr ()
135+ self ._pPr = pPr
136+ return self
129137
130138 def with_r (self , count = 1 ):
131139 """Add *count* empty run elements"""
@@ -141,6 +149,8 @@ def xml(self):
141149 xml = '%s<w:p%s/>\n ' % (indent , self ._nsdecls )
142150 else :
143151 xml = '%s<w:p%s>\n ' % (indent , self ._nsdecls )
152+ if self ._pPr :
153+ xml += self ._pPr .with_indent (self ._indent + 2 ).xml
144154 for r in self ._r :
145155 xml += r .with_indent (self ._indent + 2 ).xml
146156 xml += '%s</w:p>\n ' % indent
You can’t perform that action at this time.
0 commit comments