|
@ -22,7 +22,7 @@ _LATEX_SUBS = ( |
|
|
(re.compile(r'\.\.\.+'), r'\\ldots'), |
|
|
(re.compile(r'\.\.\.+'), r'\\ldots'), |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
VARIABLE_REGEXP = re.compile(r""" |
|
|
_VARIABLE_REGEXP = re.compile(r""" |
|
|
\(\*\ *variables\ *\*\) # Match (* variables *) |
|
|
\(\*\ *variables\ *\*\) # Match (* variables *) |
|
|
( # Match and capture the following: |
|
|
( # Match and capture the following: |
|
|
(?: # Start of non-capturing group, used to match a single character |
|
|
(?: # Start of non-capturing group, used to match a single character |
|
@ -41,24 +41,22 @@ VARIABLE_REGEXP = re.compile(r""" |
|
|
\(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.""", |
|
|
\(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.""", |
|
|
re.VERBOSE|re.DOTALL) |
|
|
re.VERBOSE|re.DOTALL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VariablesExtension(Extension): |
|
|
class VariablesExtension(Extension): |
|
|
"""Extension to jinja2 to silently ignore variable block. |
|
|
"""Extension to jinja2 to silently ignore variable block. |
|
|
|
|
|
|
|
|
Instead, they are parsed by this module. |
|
|
Instead, they are parsed by this module. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
tags = set(['variables']) |
|
|
tags = set(['variables']) |
|
|
|
|
|
|
|
|
def parse(self, parser): |
|
|
def parse(self, parser): |
|
|
parser.stream.next() |
|
|
parser.stream.next() |
|
|
|
|
|
|
|
|
parser.parse_statements( |
|
|
parser.parse_statements( |
|
|
end_tokens=['name:endvariables'], |
|
|
end_tokens=['name:endvariables'], |
|
|
drop_needle=True, |
|
|
drop_needle=True, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
return nodes.Const("") |
|
|
return nodes.Const("") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _escape_tex(value): |
|
|
def _escape_tex(value): |
|
|
'''Escape TeX special characters''' |
|
|
'''Escape TeX special characters''' |
|
|
newval = value |
|
|
newval = value |
|
@ -95,8 +93,8 @@ class TexRenderer(object): |
|
|
self.texenv.block_end_string = '*)' |
|
|
self.texenv.block_end_string = '*)' |
|
|
self.texenv.variable_start_string = '((' |
|
|
self.texenv.variable_start_string = '((' |
|
|
self.texenv.variable_end_string = '))' |
|
|
self.texenv.variable_end_string = '))' |
|
|
self.texenv.comment_start_string = '(#' |
|
|
self.texenv.comment_start_string = '(% comment %)' |
|
|
self.texenv.comment_end_string = '#)' |
|
|
self.texenv.comment_end_string = '(% endcomment %)' |
|
|
self.texenv.line_comment_prefix = '%!' |
|
|
self.texenv.line_comment_prefix = '%!' |
|
|
self.texenv.filters['escape_tex'] = _escape_tex |
|
|
self.texenv.filters['escape_tex'] = _escape_tex |
|
|
self.texenv.trim_blocks = True |
|
|
self.texenv.trim_blocks = True |
|
@ -191,7 +189,7 @@ class TexRenderer(object): |
|
|
) as template_file: |
|
|
) as template_file: |
|
|
content = template_file.read() |
|
|
content = template_file.read() |
|
|
subtemplates = list(find_templates(self.texenv.parse(content))) |
|
|
subtemplates = list(find_templates(self.texenv.parse(content))) |
|
|
match = re.findall(VARIABLE_REGEXP, content) |
|
|
match = re.findall(_VARIABLE_REGEXP, content) |
|
|
if match: |
|
|
if match: |
|
|
for var in match: |
|
|
for var in match: |
|
|
try: |
|
|
try: |
|
|