How to use the panflute.Image 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-admonition / pandoc_latex_admonition.py View on Github external
def extract_images(element, _doc):
        # Extract image which is alone with a title
        if (
            isinstance(element, Para)
            and len(element.content) == 1
            and isinstance(element.content[0], Image)
            and bool(element.content[0].content)
        ):
            images.append(element)
            return []
github chdemko / pandoc-latex-tip / pandoc_latex_tip.py View on Github external
# Create the image if not existing in the cache
        try:
            if not os.path.isfile(image):
                # Create the image in the cache
                category = _category(
                    icon["collection"], icon["version"], icon["variant"]
                )
                doc.get_icon_font[category]["font"].export_icon(
                    icon["extended-name"],
                    512,
                    color=icon["color"],
                    export_dir=image_dir,
                )

            # Add the LaTeX image
            image = Image(
                url=image, attributes={"width": size + "pt", "height": size + "pt"}
            )
            if icon["link"] == "":
                elem = image
            else:
                elem = Link(image, url=icon["link"])
            images.append(
                convert_text(
                    Plain(elem), input_format="panflute", output_format="latex"
                )
            )
        except TypeError:
            debug(
                "[WARNING] pandoc-latex-tip: icon name "
                + icon["name"]
                + " does not exist in variant "
github sergiocorreia / panflute / examples / panflute / lilypond.py View on Github external
code = doc.read()
            return Image(url=png(code, staffsize))

    if type(elem) == CodeBlock and 'ly' in elem.classes:
        staffsize = int(elem.attributes.get('staffsize', '20'))
        if doc.format == "latex":
            if elem.identifier == "":
                label = ""
            else:
                label = '\\label{' + elem.identifier + '}'
            return latexblock(
                '\\lily[staffsize=%s]{%s}' % (staffsize, code) +
                label
            )
        else:
            return Para(Image(url=png(code, staffsize)))
github sergiocorreia / panflute / examples / panflute / graphviz.py View on Github external
caption = "caption"
        G = pygraphviz.AGraph(string=code)
        G.layout()
        filename = sha1(code)
        filetype = {'html': 'png', 'latex': 'pdf'}.get(doc.format, 'png')
        alt = Str(caption)
        src = imagedir + '/' + filename + '.' + filetype
        if not os.path.isfile(src):
            try:
                os.mkdir(imagedir)
                sys.stderr.write('Created directory ' + imagedir + '\n')
            except OSError:
                pass
            G.draw(src)
            sys.stderr.write('Created image ' + src + '\n')
        return Para(Image(alt, url=source, title=''))
github sergiocorreia / panflute-filters / filters / figure.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
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 / examples / panflute / plantuml.py View on Github external
os.mkdir(imagedir)
                sys.stderr.write('Created directory ' + imagedir + '\n')
            except OSError:
                pass

            txt =  code.encode("utf-8")
            if not txt.startswith("@start"):
                txt = "@startuml\n" + txt + "\n@enduml\n"
            with open(src, "w") as f:
                f.write(txt)

            call(["java", "-jar", "plantuml.jar", "-t"+filetype, src])

            sys.stderr.write('Created image ' + dest + '\n')

        return Para(Image(*caption, identifier=elem.identifier,
            attributes=elem.attributes, url=dest, title=typef))
github kiwi0fruit / knitty / knitty / self_contained_raw_html_img.py View on Github external
def action(elem, doc):
    if isinstance(elem, pf.Image):
        raw_html = re.search(
            r'<figure>.*?</figure>|',
            pf.convert_text(pf.Para(elem), input_format='panflute',
                            output_format='html', standalone=True,
                            extra_args=['--self-contained']),
            re.DOTALL
        ).group(0).replace('\n', '').replace('\r', '')
        return pf.RawInline(raw_html, format='html')