使用python将xmind转为markdown

文章介绍了如何使用Python脚本xmind2md.py将XMind文件转换为Markdown格式。用户需确保有Python和Git环境,通过pip安装Xmind库,然后运行脚本转换。转换过程中,可以自定义输出样式,例如调整标题和列表级别。然而,该脚本可能不支持复杂的Xmind功能。
摘要由CSDN通过智能技术生成

使用python将xmind转为markdown

软件要求

  • python
  • git
  • 支持可以在XMind 8版本正常打开的文件,如若不行XMind 8打开后再保存

步骤

  1. 到github上面下载代码,git

  2. 搭建python虚拟环境,安装xmind

    pip3 install XMind  
    or
    pip3 install xmind
    
  3. 根据文档执行命令

    python xmind2md.py -source {xmind的文件路径} -output {markdown的输出路径}
    

    output选项是可选的,如果不填output选项,就会默认输出一个和xmind同名的文件到本脚本所在目录下。

如果需要自定义样式

如果想要输出自己预期的样式,可以自定义xmind2md.py文件里的Print2MDListInternal()方法中的循环。

def Print2MDListInternal(dictContent: typing.Dict, level):
        if type(dictContent).__name__ != 'dict':
            return
        level = level + 1
        for topic, topicDict in dictContent.items():
        	# 一二级 topic 输出为标题
        	# 三级(包括三级) topic 以上输出为层级无序列表
        	# 也可以自定义其他样式
            if level < 3: 		
                listStr.append('#' * level) 
                listStr.append(' ')
            else: 			
                listStr.append('  ' * (level - 2)) 
                listStr.append('- ')
            
            listStr.append(topic)
            listStr.append('\n')
            Print2MDListInternal(topicDict, level)

预期效果如下
在这里插入图片描述

ps:实际使用复杂功能无法转换,只能进行简单结构的转换。

可以使用 `xmind` 和 `pandas` 库来将 xmind 换为 excel。 首先需要安装这两个库: ```python pip install xmind pandas ``` 然后使用以下代码可以将 xmind 换为 excel: ```python import pandas as pd from xmind.core import XMindDocument from xmind.core.topic import TopicElement def get_children(topics): """ 递归获取所有子话题 """ children = [] for topic in topics: children.append(topic) if topic.getSubTopics(): children.extend(get_children(topic.getSubTopics())) return children def xmind_to_excel(xmind_path, sheet_name='Sheet1'): # 读取 xmind 文件 xmind = XMindDocument.open(xmind_path) sheet_data = [] # 获取根话题 root_topic = xmind.getPrimarySheet().getRootTopic() # 获取所有子话题 topics = get_children([root_topic]) for topic in topics: # 获取话题文本 title = topic.getTitle() # 获取话题备注 notes = topic.getNotes() if notes: notes = notes.getContent() else: notes = '' # 获取话题标签 labels = ','.join([label.getName() for label in topic.getLabels()]) # 获取话题链接 links = ','.join([link.getTitle() for link in topic.getHyperlinks()]) # 获取话题优先级 priority = topic.getAttribute('priority') # 获取话题进度 progress = topic.getAttribute('progress') # 获取话题完成日期 due_date = topic.getAttribute('due-date') # 获取话题开始日期 start_date = topic.getAttribute('start-date') # 将话题数据添加进列表 sheet_data.append([title, notes, labels, links, priority, progress, due_date, start_date]) # 将数据换为 DataFrame df = pd.DataFrame(sheet_data, columns=['Title', 'Notes', 'Labels', 'Links', 'Priority', 'Progress', 'Due Date', 'Start Date']) # 写入 Excel 文件 df.to_excel('output.xlsx', sheet_name=sheet_name, index=False) ``` 使用方法: ```python xmind_to_excel('input.xmind', 'Sheet1') ``` 将会生成一个名为 `output.xlsx` 的 excel 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值