From 596861a594a962e9c9c244f26a6e8e4787ef1391 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Mon, 9 Jan 2023 01:13:31 +0100 Subject: [PATCH] don't remove the twitter-tweet class from blockquote This is needed to format the Twitter blockquotes as tweets. --- backend/app/store/comment.go | 2 ++ backend/app/store/comment_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/backend/app/store/comment.go b/backend/app/store/comment.go index d4726b64..6c94065e 100644 --- a/backend/app/store/comment.go +++ b/backend/app/store/comment.go @@ -118,6 +118,8 @@ func (c *Comment) SetDeleted(mode DeleteMode) { func (c *Comment) Sanitize() { p := bluemonday.UGCPolicy() p.AllowAttrs("class").Matching(regexp.MustCompile("^chroma$")).OnElements("pre") + // special case for embedding the quotes from Twitter + p.AllowAttrs("class").Matching(regexp.MustCompile("^twitter-tweet$")).OnElements("blockquote") // this is list of tag classes which could be produced by chroma code renderer // source: https://github.com/alecthomas/chroma/blob/cc2dd5b/types.go#L211-L307 const codeSpanClassRegex = "^(bg|chroma|line|ln|lnt|hl|lntable|lntd|cl|w|err|x|k|kc" + diff --git a/backend/app/store/comment_test.go b/backend/app/store/comment_test.go index 03a77899..74b91eeb 100644 --- a/backend/app/store/comment_test.go +++ b/backend/app/store/comment_test.go @@ -88,6 +88,10 @@ func TestComment_Sanitize(t *testing.T) { inp: Comment{Text: "blah blah", PostTitle: "something"}, out: Comment{Text: "blah blah", PostTitle: "something"}, }, + { + inp: Comment{Text: ` `, PostTitle: "Twitter quote"}, + out: Comment{Text: ` `, PostTitle: "Twitter quote"}, + }, } for n, tt := range tbl {