mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-06-28 15:45:35 +08:00
修复附件不能下载问题
fixes #850 1. 修复文档为空附件不能下载 2. 修复文档设置为非markdown编辑附件不能下载 3. 兼容现存问题文档 4. 非markdown编辑文档,阅读时增加文档修改信息
This commit is contained in:
parent
a2202f8878
commit
c8f7a2a544
@ -267,12 +267,18 @@ func (item *Document) ReleaseContent() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理文档的外链,附件,底部编辑信息等.
|
// Processor 调用位置两处:
|
||||||
|
// 1. 项目发布和文档发布: 处理文档的外链,附件,底部编辑信息等;
|
||||||
|
// 2. 文档阅读:可以修复存在问题的文档,使其能正常显示附件下载和文档作者信息等。
|
||||||
func (item *Document) Processor() *Document {
|
func (item *Document) Processor() *Document {
|
||||||
if item.Release != "" {
|
if item.Release != "" {
|
||||||
item.Release = utils.SafetyProcessor(item.Release)
|
item.Release = utils.SafetyProcessor(item.Release)
|
||||||
|
} else {
|
||||||
|
// Release内容为空,直接赋值文档标签,保证附件下载正常
|
||||||
|
item.Release = "<div class=\"whole-article-wrap\"></div>"
|
||||||
|
}
|
||||||
|
|
||||||
//安全过滤,移除危险标签和属性
|
// Next: 生成文档的一些附加信息
|
||||||
if docQuery, err := goquery.NewDocumentFromReader(bytes.NewBufferString(item.Release)); err == nil {
|
if docQuery, err := goquery.NewDocumentFromReader(bytes.NewBufferString(item.Release)); err == nil {
|
||||||
|
|
||||||
//处理附件
|
//处理附件
|
||||||
@ -294,11 +300,11 @@ func (item *Document) Processor() *Document {
|
|||||||
docQuery, err = goquery.NewDocumentFromReader(content)
|
docQuery, err = goquery.NewDocumentFromReader(content)
|
||||||
} else {
|
} else {
|
||||||
if selector := docQuery.Find("div.wiki-bottom").First(); selector.Size() > 0 {
|
if selector := docQuery.Find("div.wiki-bottom").First(); selector.Size() > 0 {
|
||||||
selector.BeforeHtml(content.String())
|
selector.BeforeHtml(content.String()) //This branch should be a compatible branch.
|
||||||
} else if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {
|
} else if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {
|
||||||
selector.AppendHtml(content.String())
|
selector.AppendHtml(content.String()) //The document produced by the editor of Markdown will have this tag.class.
|
||||||
} else if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() > 0 {
|
} else if selector := docQuery.Find("div.whole-article-wrap").First(); selector.Size() > 0 {
|
||||||
selector.AppendHtml(content.String())
|
selector.AppendHtml(content.String()) //All documents should have this tag.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,8 +341,8 @@ func (item *Document) Processor() *Document {
|
|||||||
|
|
||||||
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {
|
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() > 0 {
|
||||||
selector.AppendHtml(release)
|
selector.AppendHtml(release)
|
||||||
} else if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() > 0 {
|
} else if selector := docQuery.Find("div.whole-article-wrap").First(); selector.Size() > 0 {
|
||||||
selector.First().AppendHtml(release)
|
selector.AppendHtml(release)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cdnimg, _ := web.AppConfig.String("cdnimg")
|
cdnimg, _ := web.AppConfig.String("cdnimg")
|
||||||
@ -387,7 +393,7 @@ func (item *Document) Processor() *Document {
|
|||||||
item.Release = strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(html), "<html><head></head><body>"), "</body></html>")
|
item.Release = strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(html), "<html><head></head><body>"), "</body></html>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ func SafetyProcessor(html string) string {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
//添加文档标签包裹
|
//添加文档标签包裹
|
||||||
if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() <= 0 {
|
if selector := docQuery.Find("div.whole-article-wrap").First(); selector.Size() <= 0 {
|
||||||
docQuery.Children().WrapAllHtml("<article class=\"markdown-article-inner\"></article>")
|
docQuery.Find("body").Children().WrapAllHtml("<div class=\"whole-article-wrap\"></div>")
|
||||||
}
|
}
|
||||||
//解决文档内容缺少包裹标签的问题
|
//解决文档内容缺少包裹标签的问题
|
||||||
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() <= 0 {
|
if selector := docQuery.Find("div.markdown-article").First(); selector.Size() <= 0 {
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
<div class="article-body markdown-body editormd-preview-container content">
|
<div class="article-body markdown-body editormd-preview-container content">
|
||||||
{{.Content}}
|
{{.Content}}
|
||||||
{{if .Model.AttachList}}
|
{{if .Model.AttachList}}
|
||||||
<div class="attach-list"><strong>{{i18n .Lang "blog.attachment"}}</strong><ul>
|
<div class="attach-list"><strong>{{i18n .Lang "doc.attachment"}}</strong><ul>
|
||||||
{{range $index,$item := .Model.AttachList}}
|
{{range $index,$item := .Model.AttachList}}
|
||||||
<li><a href="{{$item.HttpPath}}" title="{{$item.FileName}}">{{$item.FileName}}</a> </li>
|
<li><a href="{{$item.HttpPath}}" title="{{$item.FileName}}">{{$item.FileName}}</a> </li>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user