fix: render description as HTML when rendering message (close #42)

This commit is contained in:
JustSong
2023-01-06 14:23:07 +08:00
parent ccf131037b
commit 89e7a10d20
4 changed files with 22 additions and 13 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
<span class="line">发布于:<span class="tag is-light">{{.time}}</span></span>
</div>
<blockquote>
<p>{{.description}}</p>
{{.description | unescape}}
</blockquote>
{{.content | unescape}}
</article>
+12
View File
@@ -1,8 +1,10 @@
package common
import (
"bytes"
"fmt"
"github.com/google/uuid"
"github.com/yuin/goldmark"
"html/template"
"log"
"net"
@@ -139,3 +141,13 @@ func Max(a int, b int) int {
return b
}
}
func Markdown2HTML(markdown string) (HTML string, err error) {
var buf bytes.Buffer
err = goldmark.Convert([]byte(markdown), &buf)
if err != nil {
return fmt.Sprintf("Markdown 渲染出错:%s", err.Error()), err
}
HTML = buf.String()
return
}