Exemplo n.º 1
0
def _selftest() -> ExitCode:
    import markdown_katex.wrapper as wrp

    print("Command options:")
    print(json.dumps(wrp.parse_options(), indent=4))
    print()

    html_parts: typ.List[str] = []
    test_formulas = markdown_katex.TEST_FORMULAS

    for tex_formula in test_formulas:
        html_part = wrp.tex2html(tex_formula)
        if not html_part:
            return 1

        html_parts.append(html_part)

    formula_html = "\n<hr/>\n".join(html_parts)
    html_text = HTML_TEMPLATE.replace("{{content}}", formula_html)

    with open("test.html", mode="wb") as fobj:
        fobj.write(html_text.encode("utf-8"))

    print("Created 'test.html'")
    return 0
Exemplo n.º 2
0
def _selftest() -> ExitCode:
    # pylint:disable=import-outside-toplevel  ; lazy import to improve cli responsiveness
    from markdown_katex import wrapper

    print("Command options:")
    print(json.dumps(wrapper.parse_options(), indent=4))
    print()

    html_parts: typ.List[str] = []
    test_formulas = markdown_katex.TEST_FORMULAS

    for tex_formula in test_formulas:
        html_part = wrapper.tex2html(tex_formula)
        if not html_part:
            return 1

        html_parts.append(html_part)

    formula_html = "\n<hr/>\n".join(html_parts)
    html_text = html.HTML_TEMPLATE.replace("{{content}}", formula_html)

    with open("test.html", mode="wb") as fobj:
        fobj.write(html_text.encode("utf-8"))

    print("Created 'test.html'")
    return 0
Exemplo n.º 3
0
def tex2html(tex: str, options: wrapper.Options = None) -> str:
    if options:
        no_inline_svg = options.get("no_inline_svg", False)
    else:
        no_inline_svg = False

    # These are options of the extension, not of the katex-cli program.
    if options:
        options.pop('no_inline_svg', None)
        options.pop('insert_fonts_css', None)

    result = wrapper.tex2html(tex, options)
    if no_inline_svg:
        result = svg2img(result)
    return result