diff --git a/docs/build.py b/docs/build.py index df8e329..0b9b55c 100644 --- a/docs/build.py +++ b/docs/build.py @@ -3,8 +3,8 @@ from mizu import parse from jinja2 import Template, Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('.'), trim_blocks=False) -template = env.get_template('main.tpl') +env = Environment(loader=FileSystemLoader("."), trim_blocks=False) +template = env.get_template("main.tpl") with open("main.md", "r") as f: raw = f.read() text = template.render(content=parse(raw)) diff --git a/docs/source/conf.py b/docs/source/conf.py index 586c9d9..078eb02 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -9,28 +9,24 @@ import os import sys -sys.path.insert(0, os.path.abspath('../../')) +sys.path.insert(0, os.path.abspath("../../")) -project = 'mizu' -copyright = '2022, tuna2134' -author = 'tuna2134' +project = "mizu" +copyright = "2022, tuna2134" +author = "tuna2134" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.napoleon" -] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"] -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = [] - # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'furo' -html_static_path = ['_static'] +html_theme = "furo" +html_static_path = ["_static"] diff --git a/mizu/mizu.pyi b/mizu/mizu.pyi index a46c530..dd1c01d 100644 --- a/mizu/mizu.pyi +++ b/mizu/mizu.pyi @@ -4,18 +4,8 @@ from .options import Options import asyncio - class Mizu: - def __init__( - self, options: Options = Options() - ) -> None: - ... - - def set_loop(self, loop: asyncio.AbstractEventLoop) -> None: - ... - - def parse(self, text: str) -> str: - ... - - async def aioparse(self, text: str) -> str: - ... + def __init__(self, options: Options = Options()) -> None: ... + def set_loop(self, loop: asyncio.AbstractEventLoop) -> None: ... + def parse(self, text: str) -> str: ... + async def aioparse(self, text: str) -> str: ... diff --git a/mizu/options.py b/mizu/options.py index ee2f07f..f04d222 100644 --- a/mizu/options.py +++ b/mizu/options.py @@ -1,5 +1,6 @@ # Mizu's markdown options + class Options: """Options for Markdown parsing. @@ -11,17 +12,23 @@ class Options: smart_punctuation (bool): Enable smart punctuation parsing. heading_attribute (bool): Enable heading attribute parsing. """ + tables: bool footnotes: bool strikethrough: bool tasklists: bool smart_punctuation: bool heading_attribute: bool - + def __init__( - self, *, tables: bool = False, footnotes: bool = False, - strikethrough: bool = False, tasklists: bool = False, - smart_punctuation: bool = False, heading_attribute: bool = False + self, + *, + tables: bool = False, + footnotes: bool = False, + strikethrough: bool = False, + tasklists: bool = False, + smart_punctuation: bool = False, + heading_attribute: bool = False, ) -> None: self.tables = tables self.footnotes = footnotes @@ -34,6 +41,10 @@ def __init__( def all(cls) -> "Options": """Returns an Options object with all options enabled.""" return cls( - tables=True, footnotes=True, strikethrough=True, - tasklists=True, smart_punctuation=True, heading_attribute=True + tables=True, + footnotes=True, + strikethrough=True, + tasklists=True, + smart_punctuation=True, + heading_attribute=True, ) diff --git a/mizu/parse.py b/mizu/parse.py index 81f2bf2..b2c7cbf 100644 --- a/mizu/parse.py +++ b/mizu/parse.py @@ -12,18 +12,20 @@ class Mizu: options (Options): Options for parser. loop (AbstractEventLoop): Event loop """ + def __init__( - self, options: Options = Options(), + self, + options: Options = Options(), loop: Optional[AbstractEventLoop] = None, ) -> None: self.__parser = _Mizu(options) if loop: self.__parser.set_loop(loop) - + def parse(self, text: str) -> str: """ Parse markdown text to html. - + Args: text (str): Markdown text. """ @@ -32,8 +34,8 @@ def parse(self, text: str) -> str: async def aioparse(self, text: str) -> str: """ Parse markdown text to html (async version) - + Args: text (str): Markdown text """ - return await self.__parser.aioparse(text) \ No newline at end of file + return await self.__parser.aioparse(text) diff --git a/tests/test_async.py b/tests/test_async.py index c4aa743..d361bde 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -7,4 +7,4 @@ @pytest.mark.asyncio async def test_parse(): m = Mizu(loop=asyncio.get_running_loop()) - assert await m.aioparse("# hello") == "

hello

\n" \ No newline at end of file + assert await m.aioparse("# hello") == "

hello

\n" diff --git a/tests/test_md.py b/tests/test_md.py index c3fa7c4..333019a 100644 --- a/tests/test_md.py +++ b/tests/test_md.py @@ -3,5 +3,6 @@ mizu = Mizu() + def test_parse(): - assert mizu.parse("# Hello") == "

Hello

\n" \ No newline at end of file + assert mizu.parse("# Hello") == "

Hello

\n"