Add unified helper for jinja rendering
This commit is contained in:
parent
82fc33a1c4
commit
09b7cddcc2
1 changed files with 15 additions and 0 deletions
15
md_pdf/build/jinja.py
Normal file
15
md_pdf/build/jinja.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from jinja2 import Environment
|
||||||
|
|
||||||
|
|
||||||
|
def render_content(content, context):
|
||||||
|
env = Environment(
|
||||||
|
trim_blocks=True,
|
||||||
|
lstrip_blocks=True,
|
||||||
|
extensions=[
|
||||||
|
'jinja2.ext.with_',
|
||||||
|
'jinja2.ext.loopcontrols'
|
||||||
|
]
|
||||||
|
|
||||||
|
)
|
||||||
|
template = env.from_string(content)
|
||||||
|
return template.render(**context)
|
Reference in a new issue