diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py
index 06cbca1..20a659c 100644
--- a/docxtpl/__init__.py
+++ b/docxtpl/__init__.py
@@ -79,7 +79,7 @@ class DocxTemplate(object):
return Subdoc(self)
class Subdoc(object):
- """ Class for subdocumentation insertion into master document """
+ """ Class for subdocument to insert into master document """
def __init__(self, tpl):
self.tpl = tpl
self.docx = tpl.get_docx()
@@ -97,6 +97,55 @@ class Subdoc(object):
-class Tpldoc(object):
- """ class to build documenation to be passed into template variables """
- pass
\ No newline at end of file
+class RichText(object):
+ """ class to generate Rich Text when using templates variables
+
+ This is much faster than using Subdoc class, but this only for texts INSIDE an existing paragraph.
+ """
+ def __init__(self, text=None, **text_prop):
+ self.xml = ''
+ if text:
+ self.add_run(text, **text_prop)
+
+ def add(self, text, style=None,
+ color=None,
+ highlight=None,
+ size=None,
+ bold=False,
+ italic=False,
+ underline=False,
+ strike=False):
+
+ prop = ''
+
+ if style:
+ prop += '' % style
+ if color:
+ if color[0] == '#':
+ color = color[1:]
+ prop += '' % color
+ if highlight:
+ if highlight[0] == '#':
+ highlight = highlight[1:]
+ prop += '' % highlight
+ if size:
+ prop += '' % size
+ prop += '' % size
+ if bold:
+ prop += ''
+ if italic:
+ prop += ''
+ if underline:
+ if underline not in ['single','double']:
+ underline = 'single'
+ prop += '' % underline
+ if strike:
+ prop += ''
+
+ self.xml += ''
+ if prop:
+ self.xml += '%s' % prop
+ self.xml += '%s\n' % text
+
+ def __unicode__(self):
+ return xml