How to use the panflute.Str 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 / tests / test_convert_text.py View on Github external
def test_all():
    md = 'Some *markdown* **text** ~xyz~'
    c_md = pf.convert_text(md)
    b_md = [pf.Para(pf.Str("Some"), pf.Space,
                    pf.Emph(pf.Str("markdown")), pf.Space,
                    pf.Strong(pf.Str("text")), pf.Space,
                    pf.Subscript(pf.Str("xyz")))]

    print("Benchmark MD:")
    print(b_md)
    print("Converted MD:")
    print(c_md)
    assert repr(c_md) == repr(b_md)

    with io.StringIO() as f:
        doc = pf.Doc(*c_md)
        pf.dump(doc, f)
        c_md_dump = f.getvalue()

    with io.StringIO() as f:
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def define(category, doc):
    """
    Define a category in document.

    Arguments
    ---------
        category: category to define
        doc: pandoc document
    """
    # pylint: disable=line-too-long
    doc.defined[category] = {
        "first-section-level": 0,
        "last-section-level": 0,
        "format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
        "format-text-title": [
            Strong(Str("%D"), Space(), Str("%n")),
            Space(),
            Emph(Str("(%T)")),
        ],
        "format-link-classic": [Str("%D"), Space(), Str("%n")],
        "format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
        "format-caption-classic": "%D %n",
        "format-caption-title": "%D %n (%T)",
        "format-entry-title": [Str("%T")],
        "classes": [category],
        "cite-shortcut": True,
        "listing-title": None,
        "listing-unnumbered": True,
        "listing-unlisted": True,
        "listing-identifier": True,
github sergiocorreia / panflute / examples / panflute / graphviz.py View on Github external
def graphviz(elem, doc):
    if type(elem) == CodeBlock and 'graphviz' in elem.classes:
        code = elem.text
        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 chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def replace_count(where, count):
    """
    Replace count in where.

    Arguments
    ---------
        where: where to replace
        count: replace %c by count
    """
    where.walk(partial(replacing, search="%c", replace=[Str(count)]))
github sergiocorreia / panflute-filters / filters / debug.py View on Github external
def action(elem, doc):
    if isinstance(elem, pf.Doc):
        version = pkg_resources.get_distribution("panflute").version
        json_serializer = lambda elem: elem.to_json()
        raw = json.dumps(elem, default=json_serializer)
        raw = json.loads(raw)
        raw = json.dumps(raw, check_circular=False,
                         indent=4, separators=(',', ': '))
        disclaimer = pf.Para(pf.Emph(pf.Str('Note: sort order not preserved')))
        elem.content = [
          pf.Header(pf.Str('Python version:'), level=2),
          pf.Para(pf.Str(sys.version)),
          pf.Header(pf.Str('Panflute version:'), level=2),
          pf.Para(pf.Str(version)),
          pf.Header(pf.Str('sys.argv:'), level=2),
          pf.Plain(pf.Str(str(sys.argv))),
          pf.Header(pf.Str('JSON Input:'), level=2),
          disclaimer,
          pf.CodeBlock(raw)
        ]
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
Arguments
    ---------
        category: category to define
        doc: pandoc document
    """
    # pylint: disable=line-too-long
    doc.defined[category] = {
        "first-section-level": 0,
        "last-section-level": 0,
        "format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
        "format-text-title": [
            Strong(Str("%D"), Space(), Str("%n")),
            Space(),
            Emph(Str("(%T)")),
        ],
        "format-link-classic": [Str("%D"), Space(), Str("%n")],
        "format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
        "format-caption-classic": "%D %n",
        "format-caption-title": "%D %n (%T)",
        "format-entry-title": [Str("%T")],
        "classes": [category],
        "cite-shortcut": True,
        "listing-title": None,
        "listing-unnumbered": True,
        "listing-unlisted": True,
        "listing-identifier": True,
        "entry-tab": 1.5,
        "entry-space": 2.3,
    }
    if doc.format == "latex":
        doc.defined[category]["format-entry-classic"] = [Str("%D")]
        doc.defined[category]["entry-tab"] = 1.5
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
---------
        category: category to define
        doc: pandoc document
    """
    # pylint: disable=line-too-long
    doc.defined[category] = {
        "first-section-level": 0,
        "last-section-level": 0,
        "format-text-classic": [Strong(Str("%D"), Space(), Str("%n"))],
        "format-text-title": [
            Strong(Str("%D"), Space(), Str("%n")),
            Space(),
            Emph(Str("(%T)")),
        ],
        "format-link-classic": [Str("%D"), Space(), Str("%n")],
        "format-link-title": [Str("%D"), Space(), Str("%n"), Space(), Str("(%T)")],
        "format-caption-classic": "%D %n",
        "format-caption-title": "%D %n (%T)",
        "format-entry-title": [Str("%T")],
        "classes": [category],
        "cite-shortcut": True,
        "listing-title": None,
        "listing-unnumbered": True,
        "listing-unlisted": True,
        "listing-identifier": True,
        "entry-tab": 1.5,
        "entry-space": 2.3,
    }
    if doc.format == "latex":
        doc.defined[category]["format-entry-classic"] = [Str("%D")]
        doc.defined[category]["entry-tab"] = 1.5
        doc.defined[category]["entry-space"] = 2.3