reduce to only pandoc pipeline + fix script according to downstream patches
This commit is contained in:
parent
5660ac2021
commit
028ae6b26f
19 changed files with 54 additions and 231 deletions
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Pandoc filter for adding LaTeX environement on specific div
|
||||
"""
|
||||
|
||||
from pandocfilters import toJSONFilters, stringify, RawBlock, Para
|
||||
|
||||
import re
|
||||
|
||||
def environment(key, value, format, meta):
|
||||
# Is it a div and the right format?
|
||||
if key == 'Div' and format in ['latex', 'beamer']:
|
||||
|
||||
# Get the attributes
|
||||
[[id, classes, properties], content] = value
|
||||
|
||||
currentClasses = set(classes)
|
||||
|
||||
for environment, definedClasses in getDefined(meta).items():
|
||||
# Is the classes correct?
|
||||
if currentClasses >= definedClasses:
|
||||
if id != '':
|
||||
label = '\n\\label{' + id + '}'
|
||||
else:
|
||||
label = ''
|
||||
|
||||
currentProperties = dict(properties)
|
||||
if 'title' in currentProperties:
|
||||
title = '[' + currentProperties['title'] + ']'
|
||||
else:
|
||||
title = ''
|
||||
|
||||
before = RawBlock('tex', '\\begin{' + environment + '}' + title + label)
|
||||
after = RawBlock('tex', '\\end{' + environment + '}')
|
||||
|
||||
value[1] = [before] + content + [after]
|
||||
break
|
||||
|
||||
def getDefined(meta):
|
||||
# Return the latex-environment defined in the meta
|
||||
if not hasattr(getDefined, 'value'):
|
||||
getDefined.value = {}
|
||||
if 'pandoc-latex-environment' in meta and meta['pandoc-latex-environment']['t'] == 'MetaMap':
|
||||
for environment, classes in meta['pandoc-latex-environment']['c'].items():
|
||||
if classes['t'] == 'MetaList':
|
||||
getDefined.value[environment] = []
|
||||
for klass in classes['c']:
|
||||
string = stringify(klass)
|
||||
if re.match('^[a-zA-Z][\w.:-]*$', string):
|
||||
getDefined.value[environment].append(string)
|
||||
getDefined.value[environment] = set(getDefined.value[environment])
|
||||
return getDefined.value
|
||||
|
||||
def main():
|
||||
toJSONFilters([environment])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue