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:
Gabe Kangas
2020-10-13 16:45:52 -07:00
committed by GitHub
parent 9eab6d7553
commit d7c3991b59
23 changed files with 408 additions and 5441 deletions

View File

@@ -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()
}