MCPcopy Index your code
hub / github.com/TruthHun/BookStack / RenderMarkdown

Method RenderMarkdown

controllers/LocalhostController.go:33–66  ·  view source on GitHub ↗

渲染markdown. 根据文档id来。

()

Source from the content-addressed store, hash-verified

31//渲染markdown.
32//根据文档id来。
33func (this *LocalhostController) RenderMarkdown() {
34 id, _ := this.GetInt("id")
35 if id > 0 {
36 var doc models.Document
37 ModelStore := new(models.DocumentStore)
38 o := orm.NewOrm()
39 qs := o.QueryTable("md_documents").Filter("document_id", id)
40 if this.Ctx.Input.IsPost() {
41 qs.One(&doc, "identify", "book_id")
42 var book models.Book
43 o.QueryTable("md_books").Filter("book_id", doc.BookId).One(&book, "identify")
44 content := this.GetString("content")
45 //doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
46 //if err == nil {
47 // doc.Find("br").Each(func(i int, selection *goquery.Selection) {
48 // selection.Remove()
49 // })
50 // content, _ = doc.Find("body").Html()
51 //}
52 content = this.replaceLinks(book.Identify, content)
53 qs.Update(orm.Params{
54 "release": content,
55 "modify_time": time.Now(),
56 })
57 //这里要指定更新字段,否则markdown内容会被置空
58 ModelStore.InsertOrUpdate(models.DocumentStore{DocumentId: id, Content: content}, "content")
59 this.JsonResult(0, "成功")
60 }
61
62 this.Data["Markdown"] = ModelStore.GetFiledById(id, "markdown")
63 this.TplName = "widgets/render.html"
64 return
65 }
66}
67
68// 渲染生成封面截图
69func (this *LocalhostController) RenderCover() {

Callers

nothing calls this directly

Calls 5

replaceLinksMethod · 0.80
JsonResultMethod · 0.80
GetFiledByIdMethod · 0.80
UpdateMethod · 0.45
InsertOrUpdateMethod · 0.45

Tested by

no test coverage detected