11"""Utilities for generating Mermaid diagrams."""
22from collections import defaultdict
33
4+ # Color constants
5+ COLOR_BLACK = "#000"
6+ COLOR_GRAY = "#888888"
7+ COLOR_WHITE = "white"
8+
9+ # Style constants
10+ STROKE_DASHARRAY = "5 5"
11+
412
513class MermaidDiagram :
614 """
@@ -79,15 +87,15 @@ def _generate_node_styles(self):
7987 style = attrs .get ("style" , "" )
8088
8189 # Map colors
82- if color == "#888888" :
83- stroke_color = "#888888"
90+ if color == COLOR_GRAY :
91+ stroke_color = COLOR_GRAY
8492 else :
85- stroke_color = "#000"
93+ stroke_color = COLOR_BLACK
8694
87- if fontcolor == "#888888" :
88- text_color = "#888888"
95+ if fontcolor == COLOR_GRAY :
96+ text_color = COLOR_GRAY
8997 else :
90- text_color = "#000"
98+ text_color = COLOR_BLACK
9199
92100 # Determine stroke width based on bold
93101 if "bold" in style :
@@ -97,7 +105,7 @@ def _generate_node_styles(self):
97105
98106 # Determine stroke style based on dashed
99107 if "dashed" in style :
100- stroke_style = "stroke-dasharray: 5 5 "
108+ stroke_style = f "stroke-dasharray: { STROKE_DASHARRAY } "
101109 else :
102110 stroke_style = ""
103111
@@ -131,12 +139,12 @@ def _generate_edge_styles(self):
131139 # Determine link style based on attributes
132140 if "dashed" in style :
133141 # Mermaid uses linkStyle to style edges
134- if color == "#888888" :
135- edge_styles [idx ] = "stroke:#888888 ,stroke-dasharray: 5 5 "
142+ if color == COLOR_GRAY :
143+ edge_styles [idx ] = f "stroke:{ COLOR_GRAY } ,stroke-dasharray: { STROKE_DASHARRAY } "
136144 else :
137- edge_styles [idx ] = "stroke:#000 ,stroke-dasharray: 5 5 "
138- elif color == "#888888" :
139- edge_styles [idx ] = "stroke:#888888 "
145+ edge_styles [idx ] = f "stroke:{ COLOR_BLACK } ,stroke-dasharray: { STROKE_DASHARRAY } "
146+ elif color == COLOR_GRAY :
147+ edge_styles [idx ] = f "stroke:{ COLOR_GRAY } "
140148 # else: default black stroke
141149
142150 # Generate linkStyle commands
0 commit comments