From eb8bac4eecb35999e2cfefa046d2a0558f04d1d7 Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Fri, 14 Sep 2018 10:24:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=85=BC=E5=AE=B9=E8=80=81=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E7=9A=84TOC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/DocumentModel.go | 4 ---- utils/html.go | 11 ++++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/models/DocumentModel.go b/models/DocumentModel.go index 6d4015cb..58806ce7 100644 --- a/models/DocumentModel.go +++ b/models/DocumentModel.go @@ -291,8 +291,6 @@ func (item *Document) Processor() *Document { selector.AppendHtml(content.String()) } else if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() > 0 { selector.AppendHtml(content.String()) - } else { - docQuery.Children().WrapHtml("
").AppendHtml(content.String()) } } } @@ -316,8 +314,6 @@ func (item *Document) Processor() *Document { selector.AppendHtml(release) } else if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() > 0 { selector.First().AppendHtml(release) - } else { - docQuery.Children().WrapHtml("
").AppendHtml(release); } } diff --git a/utils/html.go b/utils/html.go index c3075899..7ab91c6d 100644 --- a/utils/html.go +++ b/utils/html.go @@ -105,7 +105,16 @@ func SafetyProcessor(html string) string { } } }) - + //添加文档标签包裹 + if selector := docQuery.Find("article.markdown-article-inner").First(); selector.Size() <= 0 { + docQuery.Children().WrapAllHtml("
") + } + //解决文档内容缺少包裹标签的问题 + if selector := docQuery.Find("div.markdown-article").First(); selector.Size() <= 0 { + if selector := docQuery.Find("div.markdown-toc").First(); selector.Size() > 0 { + docQuery.Find("div.markdown-toc").NextAll().WrapAllHtml("
") + } + } if html, err := docQuery.Html(); err == nil {