Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import os
import sys
from pandocfilters import toJSONFilter, Header
LEVELS=3
def dec_header(key, value, format, _):
if key == 'Header':
[level, attr, inline] = value
if level > LEVELS:
level -= LEVELS
return Header(level, attr, inline)
if __name__ == "__main__":
toJSONFilter(dec_header)
response = p.communicate(input=bytes(graph, "utf-8"))
err = response[1].decode("utf-8")
if len(err) != 0:
raise ValueError(err)
tikz_code = response[0].decode("utf-8")
result = "\\begin{figure}\n\\centering\\begin{tikzpicture}[scale=" + scale + "]" + tikz_code + "\\end{tikzpicture}\\caption{" + caption + "} \\label{" + label + "}\\end{figure}"
return {
"c": [
"latex",
result
],
"t": "RawBlock"
}
if __name__ == "__main__":
toJSONFilter(dot2tex)
def latexblock(properties, definedClass, id, content):
param = ""
for key_, value in properties:
if key_ == "param":
param = value
name = ""
for key_, value in properties:
if key_ == "name":
name = value
return [latex(begin(definedClass) + brakets(name) + braces(param) + label(id))] + content + [latex(end(definedClass))]
if __name__ == '__main__':
toJSONFilter(pancake_div2block)
sys.stderr.write("WARNING: Can't read file '" + l + "'. Skipping.")
# Return a flattened list using nested list comprehension
#
# The following is equivalent to:
#
# flattened = []
# for sublist in rv:
# for item in sublist:
# flattened.append(item)
# return flattened
return [item for sublist in rv for item in sublist]
if __name__ == "__main__":
toJSONFilter(docmap)
[[ident, classes, keyvals], code] = value
if "abc" in classes:
caption, typef, keyvals = get_caption(keyvals)
outfile = get_filename4code("abc", code)
filetype = get_extension(format, "png", html="png", latex="pdf")
dest = outfile + '.' + filetype
if not os.path.isfile(dest):
abc2eps(code.encode("utf-8"), filetype, outfile)
sys.stderr.write('Created image ' + dest + '\n')
return Para([Image([ident, [], keyvals], caption, [dest, typef])])
if __name__ == "__main__":
toJSONFilter(abc)
def code2raw(key, val, format, meta):
if key not in raw4code:
return None
attrs = PandocAttributes(val[0], format='pandoc')
raw = attrs.kvs.get('raw', None)
if raw:
# if raw != format: # but what if we output markdown?
# return []
return raw4code[key](raw, val[-1])
else:
return None
if __name__ == "__main__":
toJSONFilter(code2raw)
def comment(k, v, fmt, meta):
global incomment
if k == 'RawBlock':
fmt, s = v
if fmt == "html":
if re.search("", s):
incomment = True
return []
elif re.search("", s):
incomment = False
return []
if incomment:
return [] # suppress anything in a comment
if __name__ == "__main__":
toJSONFilter(comment)
import sys
from pandocfilters import toJSONFilter, Header
LEVELS=5
MAX_LEVEL=6
def inc_header(key, value, format, _):
if key == 'Header':
[level, attr, inline] = value
if level+LEVELS <= MAX_LEVEL:
level += LEVELS
return Header(level, attr, inline)
if __name__ == "__main__":
toJSONFilter(inc_header)
Element = RawBlock
elif key == 'Code':
template = Template('\\mintinline[$attributes]{$language}{$contents}')
Element = RawInline
else:
return
settings = unpack_metadata(meta)
code = unpack_code(value, settings['language'])
return [Element(format, template.substitute(code))]
if __name__ == '__main__':
toJSONFilter(minted)
return [latex(r'\begin{table'+wd+'}[!h]'),
tbl_caption(v[0]),
latex(ha),
latex(r'\begin{tabu}{' + tbl_alignment(v[1]) + '}'),
latex(r'\toprule'),
tbl_headers(v[3]),
latex(r'\midrule'),
tbl_contents(v[4]),
latex(r'\bottomrule' '\n' r'\end{tabu}'),
latex(r'\end{table'+wd+'}')]
if k == "Header":
return [latex(r'\hypertarget{' + v[1][0] + r'}{}'),
pf.Header(v[0], v[1], v[2])]
if __name__ == "__main__":
pf.toJSONFilter(do_filter)