加入「拾脉」:XMind 学习目录与在线预览
- mindmaps 增加目录模型,脑图归属目录,支持子目录 - 前端上传 .xmind,后台解析 Zen / 旧版并入库 - simple-mind-map 只读预览:缩放、适应、全屏、文字大纲 - 目录与脑图增删改查,复用拾匣密码 - 首页页脚新增拾脉入口,保留旧脑图数据
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""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 [])
|
||||
Reference in New Issue
Block a user