Example #1
0
    def handle_mnref(self, cmd_args, elem):
        r"""Handle ``\MNRef`` command.

        This command inserts a section link.
        """
        target = cmd_args[0]
        return block_wrap(
            pf.Link(url=target, attributes={"data-mnref": "true"}), elem)
Example #2
0
    def handle_mref(self, cmd_args, elem):
        r"""Handle ``\MRef`` command.

        This command translates to ``\vref``.
        """
        url = "#%s" % cmd_args[0]
        return block_wrap(pf.Link(url=url, attributes={"data-mref": "true"}),
                          elem)
Example #3
0
    def handle_mextlink(self, cmd_args, elem):
        r"""Handle ``\MExtLink`` command.

        This command inserts an external link.
        """
        url = cmd_args[0]
        text = destringify(cmd_args[1])
        link = pf.Link(*text, url=url)
        return block_wrap(link, elem)
Example #4
0
    def handle_msref(self, cmd_args, elem):
        r"""Handle ``\MSRef`` command.

        This command inserts a fragment-style link.
        """
        url = "#%s" % cmd_args[0]
        description = destringify(cmd_args[1])
        return block_wrap(
            pf.Link(*description, url=url, attributes={"data-msref": "true"}),
            elem,
        )
Example #5
0
    def handle_myoutubevideo(self, cmd_args, elem):
        r"""Handle ``\MYoutubeVideo``.

        Just return a Link Element.
        """
        title, _, _, url = cmd_args
        link = pf.Link(
            *destringify(title),
            url=url,
            title=title,
            classes=ELEMENT_CLASSES["MYOUTUBE_VIDEO"],
        )
        return block_wrap(link, elem)
Example #6
0
    def handle_mvideo(self, cmd_args, elem):
        r"""Handle ``\MVideo``.

        Just return a Link Element.
        """
        filename = "{}.mp4".format(cmd_args[0])
        title = cmd_args[1]
        link = pf.Link(
            *destringify(title),
            url=filename,
            title=title,
            classes=ELEMENT_CLASSES["MVIDEO"],
        )
        remember(elem.doc, "label", link)
        return block_wrap(link, elem)
Example #7
0
    def handle_mindex(self, cmd_args, elem):
        r"""Handle ``\MIndex`` command.

        This command creates an invisible entry for the index.
        """

        if isinstance(elem, pf.Block):
            log("Warning: Expected Inline for MIndex: {}".format(cmd_args))

        concept = cmd_args[0]
        for repl in MATH_SUBSTITUTIONS:  # can contain LaTeX!
            concept = re.sub(repl[0], repl[1], concept)
        span = pf.Span()
        span.attributes = {INDEX_ATTRIBUTE: concept, "hidden": "hidden"}
        return block_wrap(span, elem)
Example #8
0
    def handle_mentry(self, cmd_args, elem):
        r"""Handle ``\MEntry`` command.

        This command creates an entry for the index.
        """

        if isinstance(elem, pf.Block):
            log("Warning: Expected Inline for MEntry: {}".format(cmd_args))

        text = cmd_args[0]
        concept = cmd_args[1]
        for repl in MATH_SUBSTITUTIONS:  # can contain LaTeX!
            concept = re.sub(repl[0], repl[1], concept)
        strong = pf.Strong()
        strong.content.extend(
            parse_fragment(text, elem.doc.metadata["lang"].text)[0].content)
        span = pf.Span()
        span.attributes = {INDEX_ATTRIBUTE: concept}
        span.content = [strong]
        return block_wrap(span, elem)