From 3ef29b89427592152e6fd3982ece08d480c3465e Mon Sep 17 00:00:00 2001 From: ouhammou rachid <93659459+ouhammmourachid@users.noreply.github.com> Date: Sun, 2 Mar 2025 10:05:04 +0000 Subject: [PATCH 1/3] fix: allow graph parameter to accept both Graph instance and string representation --- mermaid/__main__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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() From 9413a4c5326299bb8241b4c4b4af86216af87b1d Mon Sep 17 00:00:00 2001 From: ouhammou rachid <93659459+ouhammmourachid@users.noreply.github.com> Date: Sun, 2 Mar 2025 10:11:44 +0000 Subject: [PATCH 2/3] test: update Mermaid tests to use script as instance variable and add string script test --- tests/test_mermaid.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) From 0b9de0a38c9fc014c884f25e55346ee3da147503 Mon Sep 17 00:00:00 2001 From: ouhammou rachid <93659459+ouhammmourachid@users.noreply.github.com> Date: Sun, 2 Mar 2025 10:13:25 +0000 Subject: [PATCH 3/3] fix: update contact email in CODE_OF_CONDUCT and modify example in README --- CODE_OF_CONDUCT.md | 2 +- README.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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. ```