@@ -160,7 +160,7 @@ def cellbg(m):
160160 flags = re .DOTALL ,
161161 )
162162 src_xml = re .sub (
163- r"({{r\s.*?}}|{%r\s.*?%})" ,
163+ r"({{r. \s.*?}}|{%r. \s.*?%})" ,
164164 r'</w:t></w:r><w:r><w:t xml:space="preserve">\1</w:t></w:r><w:r><w:t xml:space="preserve">' ,
165165 src_xml ,
166166 flags = re .DOTALL ,
@@ -173,7 +173,7 @@ def cellbg(m):
173173 r"-%}(?:(?!<w:t[ >]|{%|{{).)*?<w:t[^>]*?>" , "%}" , src_xml , flags = re .DOTALL
174174 )
175175
176- for y in ["tr" , "tc" , "p" , "r" ]:
176+ for y in ["tr" , "tc" , "p" ]:
177177 # replace into xml code the row/paragraph/run containing
178178 # {%y xxx %} or {{y xxx}} template tag
179179 # by {% xxx %} or {{ xx }} without any surrounding <w:y> tags :
@@ -183,6 +183,18 @@ def cellbg(m):
183183 % {"y" : y }
184184 )
185185 src_xml = re .sub (pat , r"\1 \2" , src_xml , flags = re .DOTALL )
186+
187+ for y in ["p" , "r" ]:
188+ # replace into xml paragraph or run containing
189+ # {%rp xxx %} or {{rp xxx}} template tag
190+ # by {% xxx %} or {{ xx }} without any surrounding <w:p> tags
191+ # This allow for inline {rr <var> }} and paragraph {rp <var> }) styling
192+ # This is mandatory to have jinja2 generating correct xml code
193+ pat = (
194+ r"<w:%(y)s[ >](?:(?!<w:%(y)s[ >]).)*({%%|{{)r%(y)s ([^}%%]*(?:%%}|}})).*?</w:%(y)s>"
195+ % {"y" : y }
196+ )
197+ src_xml = re .sub (pat , r"\1 \2" , src_xml , flags = re .DOTALL )
186198
187199 for y in ["tr" , "tc" , "p" ]:
188200 # same thing, but for {#y xxx #} (but not where y == 'r', since that
0 commit comments