# Mind_Map_tab.py # Description: File contains functions for generation of PlantUML mindmaps for the gradio tab # # Imports import re # # External Libraries import gradio as gr # ###################################################################################################################### # # Functions: def parse_plantuml_mindmap(plantuml_text: str) -> dict: """Parse PlantUML mindmap syntax into a nested dictionary structure""" lines = [line.strip() for line in plantuml_text.split('\n') if line.strip() and not line.strip().startswith('@')] root = None nodes = [] stack = [] for line in lines: level_match = re.match(r'^([+\-*]+|\*+)', line) if not level_match: continue level = len(level_match.group(0)) text = re.sub(r'^([+\-*]+|\*+)\s*', '', line).strip('[]').strip('()') node = {'text': text, 'children': []} while stack and stack[-1][0] >= level: stack.pop() if stack: stack[-1][1]['children'].append(node) else: root = node stack.append((level, node)) return root def create_mindmap_html(plantuml_text: str) -> str: """Convert PlantUML mindmap to HTML visualization with collapsible nodes using CSS only""" # Parse the mindmap text into a nested structure root_node = parse_plantuml_mindmap(plantuml_text) if not root_node: return "
No valid mindmap content provided.
" html = "" colors = ['#e6f3ff', '#f0f7ff', '#f5f5f5', '#fff0f0', '#f0fff0'] def create_node_html(node, level): bg_color = colors[(level - 1) % len(colors)] if node['children']: children_html = ''.join(create_node_html(child, level + 1) for child in node['children']) return f"""