"""XMind 解析:兼容 Zen(content.json)与旧版(content.xml)。""" from xmindparser import xmind_to_dict def parse_xmind(file_path): """返回 (simple-mind-map 数据, 元信息)。""" parsed = xmind_to_dict(file_path) if not parsed: raise ValueError("XMind 文件里没有画布") sheet = parsed[0] or {} root = sheet.get("topic") if not root: raise ValueError("XMind 第一个画布没有根节点") data = _convert_topic(root) return data, { "root_title": str(root.get("title") or "").strip(), "sheet_count": len(parsed), "node_count": _count_nodes(data), } def _convert_topic(topic): node = { "data": { "text": str(topic.get("title") or "(无标题)"), } } children = topic.get("topics") or [] if children: node["children"] = [_convert_topic(child) for child in children] return node def _count_nodes(node): return 1 + sum(_count_nodes(child) for child in node.get("children") or [])