diff --git a/Cargo.toml b/Cargo.toml index 9ff6f7e..6927dc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mizu" description = "Markdown library" -version = "0.2.0-alpha6" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/mizu/__init__.py b/mizu/__init__.py index e7acc63..1cbda9d 100644 --- a/mizu/__init__.py +++ b/mizu/__init__.py @@ -1,19 +1,8 @@ # Mizu's main module. -from .mizu import Mizu +from .parse import Mizu +from .mizu import Mizu as LowMizu from .options import Options -from warnings import warn - -def parse_ext(text: str, *args, **kwargs) -> str: - warn("parse_ext is deprecated, use Mizu class.", DeprecationWarning) - return Mizu(Options(*args, **kwargs)).parse(text) - - -def parse(*args, **kwargs) -> str: - warn("parse is deprecated, use Mizu class.", DeprecationWarning) - return Mizu(Options()).parse(*args, **kwargs) - - -__all__ = ("parse", "parse_ext", "Mizu", "Options") +__all__ = ("parse", "parse_ext", "Mizu", "Options", "LowMizu") diff --git a/mizu/mizu.pyi b/mizu/mizu.pyi index b707d0d..a46c530 100644 --- a/mizu/mizu.pyi +++ b/mizu/mizu.pyi @@ -7,9 +7,12 @@ import asyncio class Mizu: def __init__( - self, options: Options = Options(), loop_: Optional[asyncio.AbstractEventLoop] = None + self, options: Options = Options() ) -> None: ... + + def set_loop(self, loop: asyncio.AbstractEventLoop) -> None: + ... def parse(self, text: str) -> str: ... diff --git a/mizu/parse.py b/mizu/parse.py new file mode 100644 index 0000000..81f2bf2 --- /dev/null +++ b/mizu/parse.py @@ -0,0 +1,39 @@ +from .mizu import Mizu as _Mizu +from .options import Options +from asyncio import AbstractEventLoop +from typing import Optional + + +class Mizu: + """ + Markdown parser. + + Args: + options (Options): Options for parser. + loop (AbstractEventLoop): Event loop + """ + def __init__( + 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. + """ + return self.__parser.parse(text) + + 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 diff --git a/src/core.rs b/src/core.rs index b3aff78..94f570c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -7,7 +7,6 @@ use pulldown_cmark::{html, Options, Parser}; /// /// Args: /// options (Options): Options for parser. -/// loop (AbstractEventLoop): Event loop #[pyclass] #[pyo3(text_signature = "(options, loop/)")] pub struct Mizu { @@ -18,20 +17,26 @@ pub struct Mizu { #[pymethods] impl Mizu { #[new] - #[args(options = "Options::empty()")] + #[pyo3(signature = (options = Options::empty()))] pub fn new( #[pyo3(from_py_with = "get_options")] options: Options, - loop_: Option, ) -> Self { - Mizu { options, loop_ } + Mizu { + options, + loop_: None, + } + } + + fn set_loop(&mut self, loop_: PyObject) -> PyResult<()> { + self.loop_ = Some(loop_); + Ok(()) } /// Parse markdown text to html. /// /// Args: /// text (str): Markdown text. - #[args(text)] - #[pyo3(text_signature = "(text, /)")] + #[pyo3(text_signature = "(text, /)", signature = (text))] fn parse(&self, text: &str) -> PyResult { let parser: Parser = Parser::new_ext(text, self.options); diff --git a/tests/test_async.py b/tests/test_async.py index 080a458..c4aa743 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -6,5 +6,5 @@ @pytest.mark.asyncio async def test_parse(): - m = Mizu(loop_=asyncio.get_running_loop()) + m = Mizu(loop=asyncio.get_running_loop()) assert await m.aioparse("# hello") == "

hello

\n" \ No newline at end of file