How to use the panflute.convert_text 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
print("\nBack and forth conversions... md->json->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
    md2json = pf.convert_text(md, input_format='markdown', output_format='json')
    print("[JSON]", md2json)
    md2json2md = pf.convert_text(md2json, input_format='json', output_format='markdown')
    print("[MD]", md2json2md)
    assert md == md2json2md


    print("\nBack and forth conversions... md->panflute->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
    md2panflute = pf.convert_text(md, input_format='markdown', output_format='panflute')
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='markdown')
    print("[MD]", md2panflute2md)
    assert md == md2panflute2md

    print("\nBack and forth conversions... md->panflute(standalone)->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
    md2panflute = pf.convert_text(md, input_format='markdown', output_format='panflute', standalone=True)
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='markdown')
    print("[MD]", md2panflute2md)
    assert md == md2panflute2md

    print("\nBack and forth conversions... md table -> json(standalone) -> md table")
    md = """lorem
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()
github sergiocorreia / panflute / tests / test_convert_text.py View on Github external
c_tex_dump = f.getvalue()

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

    assert c_tex_dump == b_tex_dump


    print("\nBack and forth conversions... md->json->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
    md2json = pf.convert_text(md, input_format='markdown', output_format='json')
    print("[JSON]", md2json)
    md2json2md = pf.convert_text(md2json, input_format='json', output_format='markdown')
    print("[MD]", md2json2md)
    assert md == md2json2md


    print("\nBack and forth conversions... md->panflute->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
    md2panflute = pf.convert_text(md, input_format='markdown', output_format='panflute')
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='markdown')
    print("[MD]", md2panflute2md)
    assert md == md2panflute2md

    print("\nBack and forth conversions... md->panflute(standalone)->md")
    md = 'Some *markdown* **text** ~xyz~'
    print("[MD]", md)
github sergiocorreia / panflute / tests / test_convert_text.py View on Github external
| - | - |

ipsum"""
    print("[MD]", repr(md))
    md2json = pf.convert_text(md, input_format='gfm', output_format='json', standalone=True)
    print("[json]", md2json)
    md2json2md = pf.convert_text(md2json, input_format='json', output_format='gfm')
    print("[MD]", repr(md2json2md))
    assert md == md2json2md


    print("\nBack and forth conversions... gfm table (empty) -> panflute(standalone) -> gfm table (empty)")
    print("[MD]", repr(md))
    md2panflute = pf.convert_text(md, input_format='gfm', output_format='panflute', standalone=True)
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='gfm')
    print("[MD]", repr(md2panflute2md))
    assert md == md2panflute2md
github sergiocorreia / panflute / tests / test_convert_text.py View on Github external
md2panflute = pf.convert_text(md, input_format='markdown', output_format='panflute', standalone=True)
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='markdown')
    print("[MD]", md2panflute2md)
    assert md == md2panflute2md

    print("\nBack and forth conversions... md table -> json(standalone) -> md table")
    md = """lorem

  --- ---
  x   y
  --- ---

ipsum"""
    print("[MD]", repr(md))
    md2json = pf.convert_text(md, input_format='markdown', output_format='json', standalone=True)
    print("[json]", md2json)
    md2json2md = pf.convert_text(md2json, input_format='json', output_format='markdown')
    print("[MD]", repr(md2json2md))
    assert md == md2json2md


    print("\nBack and forth conversions... md table -> panflute(standalone) -> md table")
    print("[MD]", repr(md))
    md2panflute = pf.convert_text(md, input_format='markdown', output_format='panflute', standalone=True)
    print("[PANFLUTE]", md2panflute)
    md2panflute2md = pf.convert_text(md2panflute, input_format='panflute', output_format='markdown')
    print("[MD]", repr(md2panflute2md))
    assert md == md2panflute2md

    print("\nBack and forth conversions... gfm table (empty) -> json(standalone) -> gfm table (empty)")
    md = """lorem
github chdemko / pandoc-latex-tip / pandoc_latex_tip.py View on Github external
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 "
                + icon["variant"]
                + " for collection "
                + icon["collection"]
                + "-"
                + icon["version"]
            )
        except FileNotFoundError:
            debug("[WARNING] pandoc-latex-tip: error in generating image")
github ickc / pantable / pantable / pantable.py View on Github external
del n_col
    # get caption
    caption = options.get('caption', None)

    text = csv_to_grid_tables(
        table_list, caption, alignment,
        (len(table_list) > 1 and options.get('header', True))
    ) if use_grid_tables else csv_to_pipe_tables(
        table_list, caption, alignment
    )

    raw_markdown = options.get('raw_markdown', False)
    if raw_markdown:
        return panflute.RawBlock(text, format='markdown')
    else:
        return panflute.convert_text(text)
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def to_latex(elem):
    """
    Convert element to LaTeX.

    Arguments
    ---------
        elem: elem to convert

    Returns
    -------
        LaTex string
    """
    return convert_text(
        run_filters([remove_useless_latex], doc=Plain(elem)),
        input_format="panflute",
        output_format="latex",
        extra_args=["--no-highlight"],
    )
github chdemko / pandoc-latex-admonition / pandoc_latex_admonition.py View on Github external
def note(element, doc):
        if (
            isinstance(element, Note)
            and doc.format == "beamer"
            and not environment["localfootnotes"]
        ):
            return RawInline(
                "".join(
                    [
                        "\\footnote<.->[frame]{",
                        convert_text(
                            element.content,
                            input_format="panflute",
                            output_format="latex",
                        ),
                        "}",
                    ]
                ),
                "tex",
            )