コード例 #1
0
ファイル: __main__.py プロジェクト: HJSang/markdown-katex
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
コード例 #2
0
ファイル: __main__.py プロジェクト: mbarkhau/markdown-katex
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
コード例 #3
0
    def __init__(self, **kwargs) -> None:
        self.config = {
            'no_inline_svg': ["", "Replace inline <svg> with <img> tags."],
            'insert_fonts_css': ["", "Insert font loading stylesheet."],
        }
        for name, options_text in wrapper.parse_options().items():
            self.config[name] = ["", options_text]

        self.options: wrapper.Options = {}
        for name in self.config:
            val_configured = self.getConfig(name, "")
            val = kwargs.get(name, val_configured)

            if val != "":
                self.options[name] = val

        self.math_html: typ.Dict[str, str] = {}
        super().__init__(**kwargs)
コード例 #4
0
    def __init__(self, **kwargs) -> None:
        self.config = {
            "no_inline_svg": ["", "Replace inline <svg> with <img> tags."],
            "insert_fonts_css": ["", "Insert font loading stylesheet."],
        }
        for name, options_text in wrapper.parse_options().items():
            self.config[name] = ["", options_text]

        self.options: wrapper.Options = {}
        for name in self.config.keys():
            if name in kwargs:
                val = kwargs[name]
            else:
                val = self.getConfig(name, "")

            if val != "":
                self.options[name] = val

        self.math_html: typ.Dict[str, str] = {}
        super(KatexExtension, self).__init__(**kwargs)