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_div(self):
doc = Doc(
Div(classes=["tip", "listing"]),
Div(classes=["tip"]),
Div(classes=["warning"]),
Div(
attributes={
"latex-tip-icon": "warning",
"latex-tip-position": "right",
"latex-tip-size": 24,
}
),
metadata=self.metadata(),
format="latex",
api_version=(1, 17, 2),
)
pandoc_latex_tip.main(doc)
self.assertEqual(doc.content[0].format, "tex")
self.assertEqual(doc.content[1].format, "tex")
def test_div(self):
doc = Doc(
Div(classes=["tip", "listing"]),
Div(classes=["tip"]),
Div(classes=["warning"]),
Div(
attributes={
"latex-tip-icon": "warning",
"latex-tip-position": "right",
"latex-tip-size": 24,
}
),
metadata=self.metadata(),
format="latex",
api_version=(1, 17, 2),
)
pandoc_latex_tip.main(doc)
self.assertEqual(doc.content[0].format, "tex")
self.assertEqual(doc.content[1].format, "tex")
self.assertEqual(doc.content[3].format, "tex")
self.assertEqual(doc.content[4].format, "tex")
def collapse(elem, doc):
if isinstance(elem, pf.CodeBlock) and "html" in doc.format:
content = [
pf.RawBlock("<details>", format="html"),
pf.RawBlock(
"""
<summary> Show code </summary>
"""
),
elem,
pf.RawBlock("</details>", format="html"),
]
div = pf.Div(*content, classes=["collapsible_code"])
return div
def add_latex(elem, color, bgcolor):
# Is it a Span?
if isinstance(elem, Span):
if bgcolor:
elem.content.insert(0, RawInline(bgcolor + "\\hl{", "tex"))
elem.content.append(RawInline("}", "tex"))
elem.content.insert(0, RawInline(color, "tex"))
# Is it a Div?
elif isinstance(elem, Div):
if bgcolor:
elem.content.insert(0, RawBlock("{" + color + bgcolor + "\\hl{", "tex"))
elem.content.append(RawBlock("}", "tex"))
else:
elem.content.insert(0, RawBlock("{" + color, "tex"))
elem.content.append(RawBlock("}", "tex"))
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
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 finalize(doc):
if doc.backmatter:
doc.replacement_ok = False
backmatter = pf.Div(*doc.backmatter, identifier='backmatter')
pf.replace_keyword(doc, '$backmatter', backmatter)
assert doc.replacement_ok, "Couldn't replace '$backmatter'"
else:
pf.replace_keyword(doc, '$backmatter', pf.Null())
def finalize(doc):
if doc.backmatter:
doc.replacement_ok = False
backmatter = pf.Div(*doc.backmatter, identifier='backmatter')
pf.replace_keyword(doc, '$backmatter', backmatter)
assert doc.replacement_ok, "Couldn't replace '$backmatter'"
else:
pf.replace_keyword(doc, '$backmatter', pf.Null())
-------
[]: if elem is an instance to remove
None: otherwise
"""
if isinstance(
elem,
(
BlockQuote,
BulletList,
Citation,
Cite,
CodeBlock,
Definition,
DefinitionItem,
DefinitionList,
Div,
Header,
HorizontalRule,
Image,
LineBlock,
LineBreak,
LineItem,
ListItem,
Note,
Para,
RawBlock,
RawInline,
SoftBreak,
Table,
TableCell,
TableRow,
),
def theorems(e, doc):
if type(e) == Div and 'theorem' in e.classes:
doc.theoremcount += 1
if doc.format == 'latex':
label = '\\label{' + e.identifier + '}' if e.identifier else ''
left = RawBlock('\\begin{theorem}' + label, format='latex')
right = RawBlock('\\end{theorem}', format='latex')
elif doc.format in ('html', 'html5'):
label = '<dt>Theorem {}</dt>\n<dd>'.format(doc.theoremcount)
left = RawBlock(label, format='html')
right = RawBlock('</dd>\n', format='html')
else:
return
e.content = [left] + list(e.content) + [right]
return e