Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
latex_category = re.sub("[^a-z]+", "", category)
latex = [
link_color(doc),
"\\makeatletter",
"\\newcommand*\\l@"
+ latex_category
+ "{\\@dottedtocline{1}{"
+ str(definition["entry-tab"])
+ "em}{"
+ str(definition["entry-space"])
+ "em}}",
"\\@starttoc{" + latex_category + "}",
"\\makeatother",
]
# Return a RawBlock
return RawBlock("".join(latex), "tex")
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"))
def htmlblock(code):
"""Html block"""
return RawBlock(code, format='html')
# parse alignment
alignment = parse_alignment(options.get('alignment', None), n_col)
del n_col
# get caption
caption = options.get('caption', None)
text = csv_to_grid_tables(
table_list, caption, alignment,
(len(table_list) > 1 and options.get('header', True))
) if use_grid_tables else csv_to_pipe_tables(
table_list, caption, alignment
)
raw_markdown = options.get('raw_markdown', False)
if raw_markdown:
return panflute.RawBlock(text, format='markdown')
else:
return panflute.convert_text(text)
def latexblock(code):
"""LaTeX block"""
return RawBlock(code, format='latex')
# It is a Div: try to insert an inline raw before the first inline element
inserted = [False]
def insert(element, _):
if (
not inserted[0]
and isinstance(element, Inline)
and not isinstance(element.parent, Inline)
):
inserted[0] = True
return [RawInline(latex, "tex"), element]
return None
elem.walk(insert)
if not inserted[0]:
return [RawBlock("\\needspace{5em}", "tex"), RawBlock(latex, "tex"), elem]
return [RawBlock("\\needspace{5em}", "tex"), elem]
return None
def _add_latex(elem, latex):
if bool(latex):
# Is it a Span or a Code?
if isinstance(elem, (Span, Code)):
return [elem, RawInline(latex, "tex")]
# It is a CodeBlock: create a minipage to ensure the _tip to be on the same page as the codeblock
if isinstance(elem, CodeBlock):
return [
RawBlock("\\begin{minipage}{\\textwidth}" + latex, "tex"),
elem,
RawBlock("\\end{minipage}", "tex"),
]
# It is a Div: try to insert an inline raw before the first inline element
inserted = [False]
def insert(element, _):
if (
not inserted[0]
and isinstance(element, Inline)
and not isinstance(element.parent, Inline)
):
inserted[0] = True
return [RawInline(latex, "tex"), element]
return None
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