diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index effc6a3..973cd23 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -60,7 +60,7 @@ representative at an online or offline event. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at -rachidouhammou21@gmail.com. +ouhammmourachid@gmail.com. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the diff --git a/README.md b/README.md index 728b5d6..a879f36 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ pip install mermaid-py import mermaid as md from mermaid.graph import Graph -sequence = Graph('Sequence-diagram',""" +render = md.Mermaid(""" stateDiagram-v2 [*] --> Still Still --> [*] @@ -42,7 +42,6 @@ stateDiagram-v2 Moving --> Crash Crash --> [*] """) -render = md.Mermaid(sequence) render # !! note this only works in the notebook that rendered the html. ``` diff --git a/mermaid/__main__.py b/mermaid/__main__.py index 9900b9d..2eb8c6f 100644 --- a/mermaid/__main__.py +++ b/mermaid/__main__.py @@ -34,7 +34,7 @@ class Mermaid: def __init__( self, - graph: Graph, + graph: Union[Graph, str], width: Optional[int] = None, height: Optional[int] = None, scale: Optional[float] = None, @@ -44,7 +44,7 @@ def __init__( The constructor for the Mermaid class. Parameters: - graph (Graph): The Graph object containing the Mermaid diagram script. + graph (Graph): The Mermaid diagram. It can be an instance of the Graph class or a string representing the script. width (Optional[int]): The width of the SVG image. height (Optional[int]): The height of the SVG image. scale (Optional[float]): The scale of the SVG image. @@ -62,7 +62,9 @@ def __init__( self.__width = width if width else None self.__scale = scale if scale else None - self._diagram = self._process_diagram(graph.script) + self._diagram = self._process_diagram( + graph if isinstance(graph, str) else graph.script + ) if any([self.__width, self.__height, self.__scale]): self._diagram += "?" + self._build_query_params() diff --git a/tests/test_mermaid.py b/tests/test_mermaid.py index babccba..80fe6ee 100644 --- a/tests/test_mermaid.py +++ b/tests/test_mermaid.py @@ -8,13 +8,13 @@ class TestMermaid(unittest.TestCase): def setUp(self) -> None: - script: str = """graph TD; + self.script: str = """graph TD; A-->B; A-->C; B-->D; C-->D;""" self.name: str = "simple-graph" - self.graph: Graph = Graph(self.name, script) + self.graph: Graph = Graph(self.name, self.script) self.mermaid_object = Mermaid(self.graph) def test_make_request_to_mermaid_api_for_svg(self): @@ -23,6 +23,11 @@ def test_make_request_to_mermaid_api_for_svg(self): def test_make_request_to_mermaid_api_for_png(self): self.assertTrue(self.mermaid_object.img_response.status_code == 200) + def test_using_mermaid_with_str_script(self): + mermaid_with_str_script = Mermaid(self.script) + self.assertTrue(mermaid_with_str_script.svg_response.status_code == 200) + self.assertTrue(mermaid_with_str_script.img_response.status_code == 200) + def test_query_params_to_mermaid_api_for_svg(self): mermaid_with_params = Mermaid(self.graph, height=1024, scale=2) self.assertTrue(mermaid_with_params.img_response.status_code == 200)