Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_all():
md = 'Some *markdown* **text** ~xyz~'
c_md = pf.convert_text(md)
b_md = [pf.Para(pf.Str("Some"), pf.Space,
pf.Emph(pf.Str("markdown")), pf.Space,
pf.Strong(pf.Str("text")), pf.Space,
pf.Subscript(pf.Str("xyz")))]
print("Benchmark MD:")
print(b_md)
print("Converted MD:")
print(c_md)
assert repr(c_md) == repr(b_md)
with io.StringIO() as f:
doc = pf.Doc(*c_md)
pf.dump(doc, f)
c_md_dump = f.getvalue()
with io.StringIO() as f:
def define(category, doc):
"""
Define a category in document.
Arguments
---------
category: category to define
doc: pandoc document
"""
# pylint: disable=line-too-long
doc.defined[category] = {
"first-section-level": 0,
"last-section-level": 0,
"format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
"format-text-title": [
Strong(Str("%D"), Space(), Str("%n")),
Space(),
Emph(Str("(%T)")),
],
"format-link-classic": [Str("%D"), Space(), Str("%n")],
"format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
"format-caption-classic": "%D %n",
"format-caption-title": "%D %n (%T)",
"format-entry-title": [Str("%T")],
"classes": [category],
"cite-shortcut": True,
"listing-title": None,
"listing-unnumbered": True,
"listing-unlisted": True,
"listing-identifier": True,
def graphviz(elem, doc):
if type(elem) == CodeBlock and 'graphviz' in elem.classes:
code = elem.text
caption = "caption"
G = pygraphviz.AGraph(string=code)
G.layout()
filename = sha1(code)
filetype = {'html': 'png', 'latex': 'pdf'}.get(doc.format, 'png')
alt = Str(caption)
src = imagedir + '/' + filename + '.' + filetype
if not os.path.isfile(src):
try:
os.mkdir(imagedir)
sys.stderr.write('Created directory ' + imagedir + '\n')
except OSError:
pass
G.draw(src)
sys.stderr.write('Created image ' + src + '\n')
return Para(Image(alt, url=source, title=''))
def replace_count(where, count):
"""
Replace count in where.
Arguments
---------
where: where to replace
count: replace %c by count
"""
where.walk(partial(replacing, search="%c", replace=[Str(count)]))
def action(elem, doc):
if isinstance(elem, pf.Doc):
version = pkg_resources.get_distribution("panflute").version
json_serializer = lambda elem: elem.to_json()
raw = json.dumps(elem, default=json_serializer)
raw = json.loads(raw)
raw = json.dumps(raw, check_circular=False,
indent=4, separators=(',', ': '))
disclaimer = pf.Para(pf.Emph(pf.Str('Note: sort order not preserved')))
elem.content = [
pf.Header(pf.Str('Python version:'), level=2),
pf.Para(pf.Str(sys.version)),
pf.Header(pf.Str('Panflute version:'), level=2),
pf.Para(pf.Str(version)),
pf.Header(pf.Str('sys.argv:'), level=2),
pf.Plain(pf.Str(str(sys.argv))),
pf.Header(pf.Str('JSON Input:'), level=2),
disclaimer,
pf.CodeBlock(raw)
]
Arguments
---------
category: category to define
doc: pandoc document
"""
# pylint: disable=line-too-long
doc.defined[category] = {
"first-section-level": 0,
"last-section-level": 0,
"format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
"format-text-title": [
Strong(Str("%D"), Space(), Str("%n")),
Space(),
Emph(Str("(%T)")),
],
"format-link-classic": [Str("%D"), Space(), Str("%n")],
"format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
"format-caption-classic": "%D %n",
"format-caption-title": "%D %n (%T)",
"format-entry-title": [Str("%T")],
"classes": [category],
"cite-shortcut": True,
"listing-title": None,
"listing-unnumbered": True,
"listing-unlisted": True,
"listing-identifier": True,
"entry-tab": 1.5,
"entry-space": 2.3,
}
if doc.format == "latex":
doc.defined[category]["format-entry-classic"] = [Str("%D")]
doc.defined[category]["entry-tab"] = 1.5
---------
category: category to define
doc: pandoc document
"""
# pylint: disable=line-too-long
doc.defined[category] = {
"first-section-level": 0,
"last-section-level": 0,
"format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
"format-text-title": [
Strong(Str("%D"), Space(), Str("%n")),
Space(),
Emph(Str("(%T)")),
],
"format-link-classic": [Str("%D"), Space(), Str("%n")],
"format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
"format-caption-classic": "%D %n",
"format-caption-title": "%D %n (%T)",
"format-entry-title": [Str("%T")],
"classes": [category],
"cite-shortcut": True,
"listing-title": None,
"listing-unnumbered": True,
"listing-unlisted": True,
"listing-identifier": True,
"entry-tab": 1.5,
"entry-space": 2.3,
}
if doc.format == "latex":
doc.defined[category]["format-entry-classic"] = [Str("%D")]
doc.defined[category]["entry-tab"] = 1.5
doc.defined[category]["entry-space"] = 2.3