How to use the panflute.Span 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_span(self):
        doc = Doc(
            Para(
                Span(classes=["tip", "listing"]),
                Span(classes=["tip"]),
                Span(classes=["warning"]),
                Span(classes=["v5.0"]),
                Span(
                    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].content[1].format, "tex")
        self.assertEqual(doc.content[0].content[3].format, "tex")
        self.assertEqual(doc.content[0].content[5].format, "tex")
        self.assertEqual(doc.content[0].content[7].format, "tex")
github chdemko / pandoc-latex-tip / tests / test_tip.py View on Github external
def test_span(self):
        doc = Doc(
            Para(
                Span(classes=["tip", "listing"]),
                Span(classes=["tip"]),
                Span(classes=["warning"]),
                Span(classes=["v5.0"]),
                Span(
                    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].content[1].format, "tex")
        self.assertEqual(doc.content[0].content[3].format, "tex")
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
else:
            self._get_content()[0].content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-text-classic"]
            )
            self._link.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-link-classic"]
            )
            self._entry.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-entry-classic"]
            )
            self._caption = self._doc.defined[self._basic_category][
                "format-caption-classic"
            ]

        # Compute caption (delay replacing %c at the end since it is not known for the moment)
        title = stringify(Span(*self._title))
        description = stringify(Span(*self._description))
        self._caption = self._caption.replace("%t", title.lower())
        self._caption = self._caption.replace("%T", title)
        self._caption = self._caption.replace("%d", description.lower())
        self._caption = self._caption.replace("%D", description)
        self._caption = self._caption.replace("%s", self._section_number)
        self._caption = self._caption.replace("%g", self._global_number)
        self._caption = self._caption.replace("%n", self._local_number)
        self._caption = self._caption.replace("#", self._local_number)
        if self._doc.format == "latex":
            self._caption = self._caption.replace("%p", "\\pageref{" + self._tag + "}")

        # Compute content
        replace_description(self._elem, self._description)
        replace_title(self._elem, self._title)
        replace_global_number(self._elem, self._global_number)
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def _compute_data(self):
        classes = self._doc.defined[self._basic_category]["classes"]
        self._set_content(
            [Span(classes=["pandoc-numbering-text"] + classes, identifier=self._tag)]
        )
        self._link.classes = self._link.classes + classes
        self._entry.classes = self._entry.classes + classes

        # Prepare the final data
        if self._title:
            self._get_content()[0].content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-text-title"]
            )
            self._link.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-link-title"]
            )
            self._entry.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-entry-title"]
            )
            self._caption = self._doc.defined[self._basic_category][
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
doc: pandoc document
    """
    match = re.match("^#(?P([a-zA-Z][\\w:.-]*))$", elem.url)
    if match:
        tag = match.group("tag")
        if tag in doc.information:
            replace_title(elem, doc.information[tag].title)
            replace_description(elem, doc.information[tag].description)
            replace_global_number(elem, doc.information[tag].global_number)
            replace_section_number(elem, doc.information[tag].section_number)
            replace_local_number(elem, doc.information[tag].local_number)
            replace_count(elem, str(doc.count[doc.information[tag].category]))
            if doc.format == "latex":
                replace_page_number(elem, tag)

            title = stringify(Span(*doc.information[tag].title))
            description = stringify(Span(*doc.information[tag].description))
            elem.title = elem.title.replace("%t", title.lower())
            elem.title = elem.title.replace("%T", title)
            elem.title = elem.title.replace("%d", description.lower())
            elem.title = elem.title.replace("%D", description)
            elem.title = elem.title.replace("%s", doc.information[tag].section_number)
            elem.title = elem.title.replace("%g", doc.information[tag].global_number)
            elem.title = elem.title.replace("%n", doc.information[tag].local_number)
            elem.title = elem.title.replace("#", doc.information[tag].local_number)
            elem.title = elem.title.replace(
                "%c", str(doc.count[doc.information[tag].category])
            )
            if doc.format == "latex":
                elem.title = elem.title.replace("%p", "\\pageref{" + tag + "}")
github sergiocorreia / panflute / examples / panflute / myemph.py View on Github external
def myemph(e, doc):
    if type(e)==pf.Emph and doc.format=='latex':
        return pf.Span(latex('\\myemph{'), *e.items, latex('}'))
github chdemko / pandoc-latex-tip / pandoc_latex_tip.py View on Github external
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]
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 chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
"""
    match = re.match("^#(?P([a-zA-Z][\\w:.-]*))$", elem.url)
    if match:
        tag = match.group("tag")
        if tag in doc.information:
            replace_title(elem, doc.information[tag].title)
            replace_description(elem, doc.information[tag].description)
            replace_global_number(elem, doc.information[tag].global_number)
            replace_section_number(elem, doc.information[tag].section_number)
            replace_local_number(elem, doc.information[tag].local_number)
            replace_count(elem, str(doc.count[doc.information[tag].category]))
            if doc.format == "latex":
                replace_page_number(elem, tag)

            title = stringify(Span(*doc.information[tag].title))
            description = stringify(Span(*doc.information[tag].description))
            elem.title = elem.title.replace("%t", title.lower())
            elem.title = elem.title.replace("%T", title)
            elem.title = elem.title.replace("%d", description.lower())
            elem.title = elem.title.replace("%D", description)
            elem.title = elem.title.replace("%s", doc.information[tag].section_number)
            elem.title = elem.title.replace("%g", doc.information[tag].global_number)
            elem.title = elem.title.replace("%n", doc.information[tag].local_number)
            elem.title = elem.title.replace("#", doc.information[tag].local_number)
            elem.title = elem.title.replace(
                "%c", str(doc.count[doc.information[tag].category])
            )
            if doc.format == "latex":
                elem.title = elem.title.replace("%p", "\\pageref{" + tag + "}")
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def __init__(self, elem, doc):
        self._elem = elem
        self._doc = doc
        self._tag = None
        self._entry = Span(classes=["pandoc-numbering-entry"])
        self._link = Span(classes=["pandoc-numbering-link"])
        self._caption = None
        self._title = None
        self._description = None
        self._category = None
        self._basic_category = None
        self._first_section_level = None
        self._last_section_level = None
        self._leading = None
        self._number = None
        self._global_number = None
        self._section_number = None
        self._local_number = None

        if self._get_content() and isinstance(self._get_content()[-1], Str):
            self._match = re.match(Numbered.marker_regex, self._get_content()[-1].text)
            if self._match: