How to use the pandocfilters.toJSONFilter function in pandocfilters

To help you get started, we’ve selected a few pandocfilters 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 att / MkTechDocs / bin / flt-decrement-header-3.py View on Github external
import os
import sys

from pandocfilters import toJSONFilter, Header

LEVELS=3

def dec_header(key, value, format, _):
    if key == 'Header':
        [level, attr, inline] = value
        if level > LEVELS:
            level -= LEVELS 
        return Header(level, attr, inline)

if __name__ == "__main__":
    toJSONFilter(dec_header)
github kuba-orlik / pandoc-dot2tex-filter / dot2tex-filter.py View on Github external
response = p.communicate(input=bytes(graph, "utf-8"))
        err = response[1].decode("utf-8")
        if len(err) != 0:
            raise ValueError(err)
        tikz_code = response[0].decode("utf-8")
        result = "\\begin{figure}\n\\centering\\begin{tikzpicture}[scale=" + scale + "]" + tikz_code + "\\end{tikzpicture}\\caption{" + caption + "} \\label{" + label + "}\\end{figure}"
        return {
            "c": [
                "latex",
                result
            ],
            "t": "RawBlock"
        }

if __name__ == "__main__":
    toJSONFilter(dot2tex)
github grea09 / pancake / .pancake / filters / 3_pancake_blocks.py View on Github external
def latexblock(properties, definedClass, id, content):
    param = ""
    for key_, value in properties:
        if key_ == "param":
            param = value
    name = ""
    for key_, value in properties:
        if key_ == "name":
            name = value
    return [latex(begin(definedClass) + brakets(name) + braces(param) + label(id))] + content + [latex(end(definedClass))]


if __name__ == '__main__':
    toJSONFilter(pancake_div2block)
github att / MkTechDocs / bin / flt-include-doc-map.py View on Github external
sys.stderr.write("WARNING: Can't read file '" + l + "'. Skipping.")

            # Return a flattened list using nested list comprehension
            #
            # The following is equivalent to:
            #
            # flattened = []
            # for sublist in rv:
            #    for item in sublist:
            #        flattened.append(item)
            # return flattened

            return [item for sublist in rv for item in sublist]

if __name__ == "__main__":
    toJSONFilter(docmap)
github jgm / pandocfilters / examples / abc.py View on Github external
[[ident, classes, keyvals], code] = value
        if "abc" in classes:
            caption, typef, keyvals = get_caption(keyvals)
            outfile = get_filename4code("abc", code)
            filetype = get_extension(format, "png", html="png", latex="pdf")
            dest = outfile + '.' + filetype

            if not os.path.isfile(dest):
                abc2eps(code.encode("utf-8"), filetype, outfile)
                sys.stderr.write('Created image ' + dest + '\n')

            return Para([Image([ident, [], keyvals], caption, [dest, typef])])


if __name__ == "__main__":
    toJSONFilter(abc)
github blei-lab / edward / docs / pandoc-code2raw.py View on Github external
def code2raw(key, val, format, meta):
    if key not in raw4code:
        return None
    attrs = PandocAttributes(val[0], format='pandoc')
    raw = attrs.kvs.get('raw', None)
    if raw:
        # if raw != format:     # but what if we output markdown?
        #     return []
        return raw4code[key](raw, val[-1])
    else:
        return None


if __name__ == "__main__":
    toJSONFilter(code2raw)
github att / MkTechDocs / bin / flt-comment-block.py View on Github external
def comment(k, v, fmt, meta):
    global incomment
    if k == 'RawBlock':
        fmt, s = v
        if fmt == "html":
            if re.search("", s):
                incomment = True
                return []
            elif re.search("", s):
                incomment = False
                return []
    if incomment:
        return []  # suppress anything in a comment

if __name__ == "__main__":
    toJSONFilter(comment)
github att / MkTechDocs / bin / flt-increment-header-5.py View on Github external
import sys

from pandocfilters import toJSONFilter, Header

LEVELS=5
MAX_LEVEL=6

def inc_header(key, value, format, _):
    if key == 'Header':
        [level, attr, inline] = value
        if level+LEVELS <= MAX_LEVEL:
            level += LEVELS 
        return Header(level, attr, inline)

if __name__ == "__main__":
    toJSONFilter(inc_header)
github nick-ulle / pandoc-minted / pandoc-minted.py View on Github external
Element = RawBlock
    elif key == 'Code':
        template = Template('\\mintinline[$attributes]{$language}{$contents}')
        Element = RawInline
    else:
        return

    settings = unpack_metadata(meta)

    code = unpack_code(value, settings['language'])

    return [Element(format, template.substitute(code))]


if __name__ == '__main__':
    toJSONFilter(minted)
github ospray / ospray / doc / filter-latex.py View on Github external
return [latex(r'\begin{table'+wd+'}[!h]'),
                tbl_caption(v[0]),
                latex(ha),
                latex(r'\begin{tabu}{' + tbl_alignment(v[1]) + '}'),
                latex(r'\toprule'),
                tbl_headers(v[3]),
                latex(r'\midrule'),
                tbl_contents(v[4]),
                latex(r'\bottomrule' '\n' r'\end{tabu}'),
                latex(r'\end{table'+wd+'}')]
    if k == "Header":
        return [latex(r'\hypertarget{' + v[1][0] + r'}{}'),
                pf.Header(v[0], v[1], v[2])]

if __name__ == "__main__":
    pf.toJSONFilter(do_filter)