Updated RichText Jinja tags from rr/rp to r/q and updated test template
This commit is contained in:
parent
aa7b7a77e3
commit
ebc770a291
@ -160,7 +160,7 @@ class DocxTemplate(object):
|
||||
flags=re.DOTALL,
|
||||
)
|
||||
src_xml = re.sub(
|
||||
r"({{r.\s.*?}}|{%r.\s.*?%})",
|
||||
r"({{[rq]\s.*?}}|{%[rq].\s.*?%})",
|
||||
r'</w:t></w:r><w:r><w:t xml:space="preserve">\1</w:t></w:r><w:r><w:t xml:space="preserve">',
|
||||
src_xml,
|
||||
flags=re.DOTALL,
|
||||
@ -173,7 +173,7 @@ class DocxTemplate(object):
|
||||
r"-%}(?:(?!<w:t[ >]|{%|{{).)*?<w:t[^>]*?>", "%}", src_xml, flags=re.DOTALL
|
||||
)
|
||||
|
||||
for y in ["tr", "tc", "p"]:
|
||||
for y in ["tr", "tc", "p", "r"]:
|
||||
# replace into xml code the row/paragraph/run containing
|
||||
# {%y xxx %} or {{y xxx}} template tag
|
||||
# by {% xxx %} or {{ xx }} without any surrounding <w:y> tags :
|
||||
@ -184,17 +184,17 @@ class DocxTemplate(object):
|
||||
)
|
||||
src_xml = re.sub(pat, r"\1 \2", src_xml, flags=re.DOTALL)
|
||||
|
||||
for y in ["p", "r"]:
|
||||
# replace into xml paragraph or run containing
|
||||
# {%rp xxx %} or {{rp xxx}} template tag
|
||||
# by {% xxx %} or {{ xx }} without any surrounding <w:p> tags
|
||||
# This allow for inline {rr <var> }} and paragraph {rp <var> }) styling
|
||||
# This is mandatory to have jinja2 generating correct xml code
|
||||
pat = (
|
||||
r"<w:%(y)s[ >](?:(?!<w:%(y)s[ >]).)*({%%|{{)r%(y)s ([^}%%]*(?:%%}|}})).*?</w:%(y)s>"
|
||||
% {"y": y}
|
||||
)
|
||||
src_xml = re.sub(pat, r"\1 \2", src_xml, flags=re.DOTALL)
|
||||
# For paragraph level richtext
|
||||
# replace into xml paragraph containing
|
||||
# {%q xxx %} or {{q xxx}} template tag
|
||||
# by {% xxx %} or {{ xx }} without any surrounding <w:p> tags
|
||||
# This allow for inline {r <var> }} and paragraph {q <var> }) styling
|
||||
# This is mandatory to have jinja2 generating correct xml code
|
||||
pat = (
|
||||
r"<w:p[ >](?:(?!<w:p[ >]).)*({%%|{{)q ([^}%%]*(?:%%}|}})).*?</w:p>"
|
||||
|
||||
)
|
||||
src_xml = re.sub(pat, r"\1 \2", src_xml, flags=re.DOTALL)
|
||||
|
||||
for y in ["tr", "tc", "p"]:
|
||||
# same thing, but for {#y xxx #} (but not where y == 'r', since that
|
||||
|
||||
@ -12,9 +12,20 @@ rtp = RichTextParagraph()
|
||||
rt = RichText()
|
||||
|
||||
rtp.add("The rich text paragraph function allows paragraph styles to be added to text",parastyle="myrichparastyle")
|
||||
rtp.add("Any built in paragraph style can be used", parastyle="IntenseQuote")
|
||||
rtp.add("or you can add your own, unlocking all style options", parastyle="createdStyle")
|
||||
rtp.add("To use, just create a style in your template word doc with the formatting you want and call it in the code.", parastyle="normal")
|
||||
|
||||
rtp.add("This allows for the use of")
|
||||
rtp.add("bullet\apoints.", parastyle="SquareBullet")
|
||||
rtp.add("custom bullet\apoints", parastyle="SquareBullet")
|
||||
rtp.add("Numbered Bullet Points", parastyle="BasicNumbered")
|
||||
rtp.add("and Alpha Bullet Points.", parastyle="alphaBracketNumbering")
|
||||
rtp.add("You can", parastyle="normal")
|
||||
rtp.add("set the", parastyle="centerAlign")
|
||||
rtp.add("text alignment", parastyle="rightAlign")
|
||||
rtp.add("as well as the spacing between lines of text. Like this for example, this text has very tight spacing between the lines.\aIt also has no space between paragraphs of the same style.", parastyle="TightLineSpacing")
|
||||
rtp.add("Unlike this one, which has extra large spacing between lines for when you want to space things out a bit or just write a little less.", parastyle="WideLineSpacing")
|
||||
rtp.add("You can also set the background colour of a line.", parastyle="LineShadingGreen")
|
||||
|
||||
rt.add("This works with ")
|
||||
rt.add("Rich ", bold=True)
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user