Fix merge conflict.
This commit is contained in:
commit
f3e5923737
4 changed files with 66 additions and 18 deletions
16
README.md
16
README.md
|
|
@ -57,6 +57,22 @@ Secretary will handle multiline variable values replacing the line breaks with a
|
||||||
To be documented...
|
To be documented...
|
||||||
|
|
||||||
|
|
||||||
|
### Builtin Filters
|
||||||
|
Apart of the available Jinja2 filters. Secretary includes some additionals filters. These are:
|
||||||
|
|
||||||
|
- **markdown(value)**
|
||||||
|
Convert the value, a markdown formated string, into a ODT formated text. Example:
|
||||||
|
|
||||||
|
{{ invoice.description|markdown }}
|
||||||
|
|
||||||
|
**Output value will take the whole paragraph** so be aware of loosing text which is on the same paragraph of the markdown field.
|
||||||
|
|
||||||
|
- **pad(value, length)**
|
||||||
|
Pad zeroes to `value` to the left until output's length will equal to `length`. Default output length is 5. Example:
|
||||||
|
|
||||||
|
{{ invoice.number|pad(6) }}
|
||||||
|
|
||||||
|
|
||||||
[1]: http://jinja.pocoo.org/docs/templates/
|
[1]: http://jinja.pocoo.org/docs/templates/
|
||||||
[2]: https://github.com/mirkonasato/pyodconverter
|
[2]: https://github.com/mirkonasato/pyodconverter
|
||||||
[3]: http://jinja.pocoo.org/docs/api/#jinja2.Environment
|
[3]: http://jinja.pocoo.org/docs/api/#jinja2.Environment
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
|
||||||
# Transform map used by the markdown filter. transform_map have
|
# Transform map used by the markdown filter. transform_map have
|
||||||
# instructions of how to transform a HTML style tag into a ODT document
|
# instructions of how to transform a HTML style tag into a ODT document
|
||||||
# styled tag. Some ODT tags may need extra attributes; these are defined
|
# styled tag. Some ODT tags may need extra attributes; these are defined
|
||||||
|
|
@ -51,7 +53,8 @@ transform_map = {
|
||||||
'a': {
|
'a': {
|
||||||
'replace_with': 'text:a',
|
'replace_with': 'text:a',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'xlink:type': 'simple'
|
'xlink:type': 'simple',
|
||||||
|
'xlink:href': ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -103,4 +106,22 @@ transform_map = {
|
||||||
'style-name': 'Preformatted_20_Text'
|
'style-name': 'Preformatted_20_Text'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'ul': {
|
||||||
|
'replace_with': 'text:list',
|
||||||
|
'attributes': {
|
||||||
|
'xml:id': 'list' + str(randint(100000000000000000,900000000000000000))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'ol': {
|
||||||
|
'replace_with': 'text:list',
|
||||||
|
'attributes': {
|
||||||
|
'xml:id': 'list' + str(randint(100000000000000000,900000000000000000))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'li': {
|
||||||
|
'replace_with': 'text:list-item'
|
||||||
|
},
|
||||||
}
|
}
|
||||||
21
secretary.py
21
secretary.py
|
|
@ -38,7 +38,6 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import io
|
import io
|
||||||
from copy import deepcopy
|
|
||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
from jinja2 import Environment, Undefined
|
from jinja2 import Environment, Undefined
|
||||||
|
|
||||||
|
|
@ -337,6 +336,10 @@ class Render(object):
|
||||||
"""
|
"""
|
||||||
Convert a markdown text into a ODT formated text
|
Convert a markdown text into a ODT formated text
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not isinstance(markdown_text, basestring):
|
||||||
|
return ''
|
||||||
|
|
||||||
from xml.dom import Node
|
from xml.dom import Node
|
||||||
from markdown_map import transform_map
|
from markdown_map import transform_map
|
||||||
|
|
||||||
|
|
@ -394,12 +397,20 @@ class Render(object):
|
||||||
|
|
||||||
html_node.parentNode.replaceChild(odt_node, html_node)
|
html_node.parentNode.replaceChild(odt_node, html_node)
|
||||||
|
|
||||||
|
def node_to_string(node):
|
||||||
|
result = node.toxml()
|
||||||
|
|
||||||
result = ''.join(c.toxml() for c in xml_object.getElementsByTagName('html')[0].childNodes)
|
# linebreaks in preformated nodes should be converted to <text:line-break/>
|
||||||
# A double linebreak should be replacece with an empty paragraph
|
if (node.__class__.__name__ != 'Text') and \
|
||||||
result = result.replace('\n\n', '<text:p text:style-name="Standard"/>')
|
(node.getAttribute('text:style-name') == 'Preformatted_20_Text'):
|
||||||
return result
|
result = result.replace('\n', '<text:line-break/>')
|
||||||
|
|
||||||
|
# All double linebreak should be replaced with an empty paragraph
|
||||||
|
return result.replace('\n\n', '<text:p text:style-name="Standard"/>')
|
||||||
|
|
||||||
|
|
||||||
|
return ''.join(node_as_str for node_as_str in map(node_to_string,
|
||||||
|
xml_object.getElementsByTagName('html')[0].childNodes))
|
||||||
|
|
||||||
def render_template(template, **kwargs):
|
def render_template(template, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
4
setup.py
4
setup.py
|
|
@ -24,7 +24,7 @@ class PyTest(TestCommand):
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='secretary',
|
name='secretary',
|
||||||
version='0.0.1',
|
version='0.1.0',
|
||||||
url='https://github.com/christopher-ramirez/secretary',
|
url='https://github.com/christopher-ramirez/secretary',
|
||||||
license='BSD',
|
license='BSD',
|
||||||
author='Christopher Ramírez',
|
author='Christopher Ramírez',
|
||||||
|
|
@ -32,7 +32,7 @@ setup(
|
||||||
description=('Take the power of Jinja2 templates to OpenOffice and '
|
description=('Take the power of Jinja2 templates to OpenOffice and '
|
||||||
'LibreOffice and create reports and letters in your web applications'),
|
'LibreOffice and create reports and letters in your web applications'),
|
||||||
long_description=read('README.md'),
|
long_description=read('README.md'),
|
||||||
py_modules=['secretary'],
|
py_modules=['secretary', 'markdown_map'],
|
||||||
platforms='any',
|
platforms='any',
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'Jinja2', 'markdown2'
|
'Jinja2', 'markdown2'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue