1、当导出Markdown时,如果当前文档没有内容,则将文档标题作为内容

2、修复导入文档时链接处理错误的BUG
pull/244/head
Minho 2018-03-27 00:55:11 +08:00
parent 95408e4b0d
commit bf1b38a36e
2 changed files with 44 additions and 40 deletions

View File

@ -615,9 +615,9 @@ func (book *Book) ImportBook(zipPath string) error {
filetil.CopyFile(linkPath, dstPath) filetil.CopyFile(linkPath, dstPath)
tempLink := strings.TrimPrefix(strings.Replace(dstPath, "\\", "/", -1), strings.Replace(conf.WorkingDirectory, "\\", "/", -1)) tempLink := conf.BaseUrl + strings.TrimPrefix(strings.Replace(dstPath, "\\", "/", -1), strings.Replace(conf.WorkingDirectory, "\\", "/", -1))
link = strings.TrimSuffix(tempLink, originalLink+")") + link + ")" link = strings.TrimSuffix(link, originalLink+")") + tempLink + ")"
} }
} }

View File

@ -451,12 +451,13 @@ func exportMarkdown(p string, parentId int, bookId int,baseDir string) error {
dirPath := filepath.Dir(docPath) dirPath := filepath.Dir(docPath)
os.MkdirAll(dirPath, 0766) os.MkdirAll(dirPath, 0766)
markdown := doc.Markdown
//如果当前文档不为空
if strings.TrimSpace(doc.Markdown) != "" {
re := regexp.MustCompile(`!\[(.*?)\]\((.*?)\)`) re := regexp.MustCompile(`!\[(.*?)\]\((.*?)\)`)
//处理文档中图片 //处理文档中图片
markdown := re.ReplaceAllStringFunc(doc.Markdown, func(image string) string { markdown = re.ReplaceAllStringFunc(doc.Markdown, func(image string) string {
images := re.FindAllSubmatch([]byte(image), -1) images := re.FindAllSubmatch([]byte(image), -1)
if len(images) <= 0 || len(images[0]) < 3 { if len(images) <= 0 || len(images[0]) < 3 {
return image return image
@ -498,6 +499,9 @@ func exportMarkdown(p string, parentId int, bookId int,baseDir string) error {
return link return link
}) })
}else{
markdown = "# " + doc.DocumentName + "\n"
}
if err := ioutil.WriteFile(docPath, []byte(markdown), 0644); err != nil { if err := ioutil.WriteFile(docPath, []byte(markdown), 0644); err != nil {
beego.Error("导出Markdown失败=>", err) beego.Error("导出Markdown失败=>", err)
return err return err