Convert .md markdown content to graph data format.
(self, flow_content: str)
| 103 | return content |
| 104 | |
| 105 | def markdown_to_data(self, flow_content: str) -> Dict[str, Any]: |
| 106 | """Convert .md markdown content to graph data format.""" |
| 107 | |
| 108 | tokens = self.md.parse(flow_content) |
| 109 | |
| 110 | graph_data = { |
| 111 | "graph_title": "Untitled Graph", |
| 112 | "graph_description": "", |
| 113 | "nodes": [], |
| 114 | "groups": [], |
| 115 | "connections": [], |
| 116 | "requirements": [] |
| 117 | } |
| 118 | |
| 119 | current_node = None |
| 120 | current_section = None |
| 121 | current_component = None |
| 122 | node_description_tokens = [] # Collect description tokens between node header and metadata |
| 123 | graph_description_tokens = [] # Collect description tokens after H1 and before first H2 |
| 124 | skip_next_inline = False # Skip the inline token that contains heading text |
| 125 | |
| 126 | i = 0 |
| 127 | while i < len(tokens): |
| 128 | token = tokens[i] |
| 129 | |
| 130 | if token.type == "heading_open": |
| 131 | level = int(token.tag[1]) # h1 -> 1, h2 -> 2, etc. |
| 132 | |
| 133 | # Get the heading content |
| 134 | if i + 1 < len(tokens) and tokens[i + 1].type == "inline": |
| 135 | heading_text = tokens[i + 1].content |
| 136 | |
| 137 | if level == 1: |
| 138 | # Graph title - capture it |
| 139 | graph_data["graph_title"] = heading_text |
| 140 | current_section = "graph_description" |
| 141 | skip_next_inline = True # Skip this heading's inline token |
| 142 | elif level == 2: |
| 143 | # Process any collected graph description tokens before moving to nodes |
| 144 | if current_section == "graph_description" and graph_description_tokens: |
| 145 | description_text = self._extract_text_from_tokens(graph_description_tokens) |
| 146 | graph_data["graph_description"] = self._clean_description(description_text) |
| 147 | graph_description_tokens = [] |
| 148 | |
| 149 | # Process any collected description tokens from previous node |
| 150 | if node_description_tokens and current_node: |
| 151 | description_text = self._extract_text_from_tokens(node_description_tokens) |
| 152 | current_node["description"] = self._clean_description(description_text) |
| 153 | node_description_tokens = [] |
| 154 | |
| 155 | if heading_text == "Connections": |
| 156 | current_section = "connections" |
| 157 | current_node = None |
| 158 | elif heading_text == "Groups": |
| 159 | current_section = "groups" |
| 160 | current_node = None |
| 161 | elif heading_text == "Dependencies": |
| 162 | current_section = "dependencies" |