Render and sanitize chat messages server-side. (#237)
* Render and sanitize chat messages server-side. Closes #235 * Render content.md server-side and return it in the client config * Remove showdown from web project * Update api spec * Move example user content file
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mssola/user_agent"
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
"mvdan.cc/xurls"
|
||||
)
|
||||
|
||||
//GetTemporaryPipePath gets the temporary path for the streampipe.flv file
|
||||
@@ -65,3 +70,30 @@ func IsUserAgentABot(userAgent string) bool {
|
||||
ua := user_agent.New(userAgent)
|
||||
return ua.Bot()
|
||||
}
|
||||
|
||||
func RenderSimpleMarkdown(raw string) string {
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithRendererOptions(
|
||||
html.WithUnsafe(),
|
||||
),
|
||||
goldmark.WithExtensions(
|
||||
extension.NewLinkify(
|
||||
extension.WithLinkifyAllowedProtocols([][]byte{
|
||||
[]byte("http:"),
|
||||
[]byte("https:"),
|
||||
}),
|
||||
extension.WithLinkifyURLRegexp(
|
||||
xurls.Strict,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
trimmed := strings.TrimSpace(raw)
|
||||
var buf bytes.Buffer
|
||||
if err := markdown.Convert([]byte(trimmed), &buf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user