How to use the panflute.toJSONFilter 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 sergiocorreia / panflute / examples / panflute / table.py View on Github external
for row in e.items:
            for cell in row:
                if len(cell) == 1 and len(cell[0].items)==1:
                    text = cell[0].items[0].text
                    if text.isdigit():
                        cell[0].items[0].text = str(int(text)+1)
        return e

def idea(e, doc):
    selector = 'Table Items Rows Cells'

    if any(type(a)==pf.Table for a in e.ancestors()):
        pass

if __name__ == '__main__':
    pf.toJSONFilter(add_one)
github sergiocorreia / panflute-filters / filters / table.py View on Github external
def main():
    #tags = {'figure': figure, 'table': table}
    pf.toJSONFilter(pf.yaml_filter, prepare=prepare, finalize=finalize,
                    tag='figure', function=figure)
github sergiocorreia / panflute / examples / panflute / comments.py View on Github external
"""

def prepare(doc):
    doc.ignore = False

def comment(el, doc):
    is_relevant = (type(el) == pf.RawBlock) and (el.format == 'html')
    if is_relevant and re.search("", el.text):
        doc.ignore = True
    if doc.ignore:
        if is_relevant and re.search("", el.text):
            doc.ignore = False
        return []

if __name__ == "__main__":
    pf.toJSONFilter(comment, prepare=prepare)
github sergiocorreia / panflute / examples / panflute / lilypond.py View on Github external
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)))

if __name__ == "__main__":
    toJSONFilter(lily)
github sergiocorreia / panflute / examples / panflute / gabc.py View on Github external
if elem.identifier == "":
                label = ""
            else:
                label = '\\label{' + elem.identifier + '}'
            return latexblock(
                "\n\\smallskip\n{%\n" +
                latexsnippet('\\gabcsnippet{' + elem.text + '}', elem.attributes) +
                "%\n}" +
                label
                )
        else:
            return Para(Image(url=png(elem.text, latexsnippet('\\gabcsnippet', elem.attributes))))


if __name__ == "__main__":
    toJSONFilter(gabc)
github sergiocorreia / panflute / examples / panflute / deemph.py View on Github external
def deemph(elem, doc):
    if type(elem) == Emph:
        # Make Str elements in Emph uppercase
        elem.walk(caps)

        # Append them to Emph's parent (after the emph)
        for i, item in enumerate(elem.content, elem.index + 1):
            elem.parent.content.insert(i, item)

        # Delete the emph
        return []


if __name__ == "__main__":
    toJSONFilter(deemph)
github sergiocorreia / panflute / examples / panflute / tikz.py View on Github external
outfile = imagedir + '/' + sha1(code)
            filetype = {'html': 'png', 'latex': 'pdf'}.get(doc.format, 'png')
            src = outfile + '.' + filetype
            if not os.path.isfile(src):
                try:
                    os.mkdir(imagedir)
                    sys.stderr.write('Created directory ' + imagedir + '\n')
                except OSError:
                    pass
                tikz2image(code, filetype, outfile)
                sys.stderr.write('Created image ' + src + '\n')
            return Para(Image(url=src))


if __name__ == "__main__":
    toJSONFilter(tikz)
github sergiocorreia / panflute / examples / panflute / graphviz.py View on Github external
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=''))


if __name__ == "__main__":
    toJSONFilter(graphviz)
github sergiocorreia / panflute-filters / filters / figure.py View on Github external
def main():
    pf.toJSONFilter(pf.yaml_filter, prepare=prepare, finalize=finalize,
                    tag='figure', function=figure)