go-xmind文件转换输出markdown文件
使用go解析,转换成md,或者生成自动化执行步骤等
go-code
package main
import (
"archive/zip"
"encoding/json"
"io"
"log"
"os"
"strings"
)
const (
fullFilename = `D:\Downloads\Zabbix监控项类型.xmind`
contentFilename = "content.json"
)
var (
Prefix = "#"
Data = ""
)
type Children struct {
Attached []Topic `json:"attached"`
}
type Topic struct {
Id string `json:"id"`
Title string `json:"title"`
Children `json:"children"`
}
type Sheet struct {
Id string `json:"id"`
Class string `json:"class"`
Title string `json:"title"`
RootTopic Topic `json:"rootTopic"`
}
func parseXmind(zipFp *zip.ReadCloser) (sheets []Sheet) {
for _, file := range zipFp.File {
if file.FileInfo().Name() != contentFilename {
continue
}
contentFp, openErr := file.Open()
if openErr != nil {
log.Fatalf("Failed to open file %s: %s\n", contentFilename, openErr)
}
contentByte, readErr := io.ReadAll(contentFp)
if readErr != nil {
log.Fatalf("Failed to read file %s: %s\n", contentFilename, readErr)
}
jsonErr := json.Unmarshal(contentByte, &sheets)
if jsonErr != nil {
log.Fatalf("Failed to parse json to Sheet: %s\n", jsonErr)
}
prettyJson, _ := json.MarshalIndent(sheets, "", " ")
log.Println(string(prettyJson))
}
return
}
func printMd(children *Children, prefix string) {
attached := children.Attached
for _, v := range attached {
cur_prefix := prefix + Prefix
Data += cur_prefix + " " + v.Title + "\n\n"
log.Println(v)
if len(v.Attached) != 0 {
printMd(&v.Children, prefix+Prefix)
}
}
}
func saveMd() {
mdFile := strings.ReplaceAll(fullFilename, ".xmind", ".md")
err := os.WriteFile(mdFile, []byte(Data), 0755)
if err != nil {
log.Fatal("err:", err)
return
}
log.Println("saveMd:", mdFile)
}
func main() {
zipFp, zipErr := zip.OpenReader(fullFilename)
if zipErr != nil {
log.Fatalf("Failed to open zip file %s: %s\n", fullFilename, zipErr)
}
sheets := parseXmind(zipFp)
for _, v := range sheets {
Data += Prefix + " " + v.RootTopic.Title + "\n\n"
printMd(&v.RootTopic.Children, Prefix)
}
log.Println(Data)
saveMd()
}
输出展示
$go run "d:\GoProject\xmmind2md.go"
2022/12/26 23:23:17
# Zabbix监控项类型
## Zabbix代理检查
(TCP 10050)
### Zabbix 客户端 - 被动模式,Zabbix server(或 proxy)询求数据,例如 CPU load,然后 Zabbix agent 返还结果。
### Zabbix 客户端 (主动式) - 主动模式,Agent 必须首先从 Zabbix sever 索取监控项列表以进行处理,然后会定期发送采集到的新值给 Zabbix server。
## SNMP代理检查
(UDP 161)
### SNMP即Simple Network Management
参考文章: