How to use the panflute.Div function in panflute

To help you get started, we’ve selected a few panflute examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chdemko / pandoc-latex-tip / tests / test_tip.py View on Github external
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")
github chdemko / pandoc-latex-tip / tests / test_tip.py View on Github external
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")
github sergiocorreia / panflute-filters / filters / collapse_code.py View on Github external
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
github chdemko / pandoc-latex-color / pandoc_latex_color.py View on Github external
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"))
github sergiocorreia / panflute-filters / filters / figure.py View on Github external
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
github sergiocorreia / panflute-filters / filters / table.py View on Github external
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
github sergiocorreia / panflute-filters / filters / table.py View on Github external
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())
github sergiocorreia / panflute-filters / filters / figure.py View on Github external
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())
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
-------
        []: 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,
        ),
github sergiocorreia / panflute / examples / panflute / theorem.py View on Github external
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