MCPcopy Index your code
hub / github.com/bhowiebkr/PyFlowGraph / FlowFormatHandler

Class FlowFormatHandler

src/data/flow_format.py:10–306  ·  view source on GitHub ↗

Handles conversion between JSON graph format and .md markdown format.

Source from the content-addressed store, hash-verified

8
9
10class FlowFormatHandler:
11 """Handles conversion between JSON graph format and .md markdown format."""
12
13 def __init__(self):
14 self.md = MarkdownIt()
15
16 def data_to_markdown(self, graph_data: Dict[str, Any], title: str = "Untitled Graph",
17 description: str = "") -> str:
18 """Convert graph data to .md markdown format."""
19
20 flow_content = f"# {title}\n\n"
21 if description:
22 flow_content += f"{description}\n\n"
23
24 # Add nodes
25 for node in graph_data.get("nodes", []):
26 flow_content += self._node_to_flow(node)
27 flow_content += "\n"
28
29 # Add groups (if any)
30 groups = graph_data.get("groups", [])
31 if groups:
32 flow_content += "## Groups\n\n"
33 flow_content += "```json\n"
34 flow_content += json.dumps(groups, indent=2)
35 flow_content += "\n```\n\n"
36
37 # Add connections
38 flow_content += "## Connections\n\n"
39 flow_content += "```json\n"
40 flow_content += json.dumps(graph_data.get("connections", []), indent=2)
41 flow_content += "\n```\n"
42
43 return flow_content
44
45 def _node_to_flow(self, node: Dict[str, Any]) -> str:
46 """Convert a single node to .md format."""
47 uuid = node.get("uuid", "")
48 title = node.get("title", "")
49 description = node.get("description", "")
50
51 content = f"## Node: {title} (ID: {uuid})\n\n"
52
53 # Add description if available
54 if description.strip():
55 cleaned_description = self._clean_description(description)
56 content += f"{cleaned_description}\n\n"
57
58 # Metadata section
59 metadata = {
60 "uuid": uuid,
61 "title": title,
62 "pos": node.get("pos", [0, 0]),
63 "size": node.get("size", [200, 150])
64 }
65
66 # Include is_reroute flag if this is a reroute node
67 if node.get("is_reroute", False):

Callers 9

copy_selectedMethod · 0.90
pasteMethod · 0.90
_load_example_dataMethod · 0.90
load_flow_fileFunction · 0.85
save_flow_fileFunction · 0.85
_save_fileMethod · 0.85
_load_fileMethod · 0.85
setUpMethod · 0.85

Calls

no outgoing calls

Tested by 3

_load_example_dataMethod · 0.72
setUpMethod · 0.68