Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def finalize(doc):
c1 = pf.TableCell(pf.Plain(pf.Str("Element")))
c2 = pf.TableCell(pf.Plain(pf.Str("Frequency")))
header = pf.TableRow(c1, c2)
rows = []
for tag in doc.counter:
c1 = pf.TableCell(pf.Plain(pf.Str(tag)))
c2 = pf.TableCell(pf.Plain(pf.Str(str(doc.counter[tag]))))
rows.append(pf.TableRow(c1, c2))
table = pf.Table(*rows, header=header)
doc.content = [table] # bugbug?
if backmatter:
doc.backmatter.append(ans)
msg = '\hyperref[fig:{}]{{[\Cref{{fig:{}}} Goes Here]}}'
msg = msg.format(label, label)
return pf.Plain(pf.Str(msg))
else:
return ans
else:
title = pf.convert_markdown(title)
assert len(title)==1, title
title = (title[0]).items
notes = pf.Div(*pf.convert_markdown(notes), classes=['note'])
title_text = pf.stringify(title)
img = pf.Image(*title, url=fn, title=title_text, identifier=label)
ans = pf.Div(pf.Plain(img), pf.Plain(pf.LineBreak), notes, classes=['figure'])
return ans
def to_latex(elem):
"""
Convert element to LaTeX.
Arguments
---------
elem: elem to convert
Returns
-------
LaTex string
"""
return convert_text(
run_filters([remove_useless_latex], doc=Plain(elem)),
input_format="panflute",
output_format="latex",
extra_args=["--no-highlight"],
)
pagebreak = doc.get_metadata('format.media-pagebreak', False)
w = options.get('width', 1.0)
subs['width'] = w
subs['innerwidth'] = options.get('innerwidth', w) / w
subs['notesize'] = options.get('notesize', 'small')
subs['pagebreak'] = '\\clearpage\n' if pagebreak else ''
text = LATEX_TEMPLATE.safe_substitute(subs)
ans = pf.RawBlock(text=text, format='latex')
if backmatter:
doc.backmatter.append(ans)
msg = '\hyperref[fig:{}]{{[\Cref{{fig:{}}} Goes Here]}}'
msg = msg.format(label, label)
return pf.Plain(pf.Str(msg))
else:
return ans
else:
title = pf.convert_markdown(title)
assert len(title)==1, title
title = (title[0]).items
notes = pf.Div(*pf.convert_markdown(notes), classes=['note'])
title_text = pf.stringify(title)
img = pf.Image(*title, url=fn, title=title_text, identifier=label)
ans = pf.Div(pf.Plain(img), pf.Plain(pf.LineBreak), notes, classes=['figure'])
return ans
def plain_to_table_cell(string):
return panflute.TableCell(panflute.Plain(panflute.Str(string)))
pagebreak = doc.get_metadata('format.media-pagebreak', False)
w = options.get('width', 1.0)
subs['width'] = w
subs['innerwidth'] = options.get('innerwidth', w) / w
subs['notesize'] = options.get('notesize', 'small')
subs['pagebreak'] = '\\clearpage\n' if pagebreak else ''
text = LATEX_TEMPLATE.safe_substitute(subs)
ans = pf.RawBlock(text=text, format='latex')
if backmatter:
doc.backmatter.append(ans)
msg = '\hyperref[fig:{}]{{[\Cref{{fig:{}}} Goes Here]}}'
msg = msg.format(label, label)
return pf.Plain(pf.Str(msg))
else:
return ans
else:
title = pf.convert_markdown(title)
assert len(title)==1, title
title = (title[0]).items
notes = pf.Div(*pf.convert_markdown(notes), classes=['note'])
title_text = pf.stringify(title)
img = pf.Image(*title, url=fn, title=title_text, identifier=label)
ans = pf.Div(pf.Plain(img), pf.Plain(pf.LineBreak), notes, classes=['figure'])
return ans
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)
]
Compute other code for table.
Arguments
---------
doc: pandoc document
category: category numbered
definition: definition
"""
if category in doc.collections:
# Prepare the list
elements = []
# Loop on the collection
for tag in doc.collections[category]:
# Add an item to the list
elements.append(
ListItem(Plain(Link(doc.information[tag].entry, url="#" + tag)))
)
# Return a bullet list
return BulletList(*elements)
return None