From 59a0bc38d1cfe0e3da9c43f90138593a89fc16b6 Mon Sep 17 00:00:00 2001 From: Edd Salkield Date: Thu, 24 Sep 2020 12:37:41 +0000 Subject: [PATCH] Prune redundant posts/render.go --- go.mod | 2 -- go.sum | 4 ---- posts/render.go | 63 ------------------------------------------------- 3 files changed, 69 deletions(-) delete mode 100644 posts/render.go diff --git a/go.mod b/go.mod index 316a321..aaede3f 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,11 @@ go 1.10 require ( github.com/kr/pretty v0.1.0 // indirect github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec - github.com/microcosm-cc/bluemonday v1.0.2 github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/writeas/impart v1.1.0 github.com/writeas/nerds v1.0.0 github.com/writeas/openssl-go v1.0.0 - github.com/writeas/saturday v1.6.0 golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect diff --git a/go.sum b/go.sum index c0585e9..af7f5d1 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,6 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspqypleMuJy4bzYEqlMhJnGAYpLrWe5p7W3CdvI= github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g= -github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s= -github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -17,8 +15,6 @@ github.com/writeas/nerds v1.0.0 h1:ZzRcCN+Sr3MWID7o/x1cr1ZbLvdpej9Y1/Ho+JKlqxo= github.com/writeas/nerds v1.0.0/go.mod h1:Gn2bHy1EwRcpXeB7ZhVmuUwiweK0e+JllNf66gvNLdU= github.com/writeas/openssl-go v1.0.0 h1:YXM1tDXeYOlTyJjoMlYLQH1xOloUimSR1WMF8kjFc5o= github.com/writeas/openssl-go v1.0.0/go.mod h1:WsKeK5jYl0B5y8ggOmtVjbmb+3rEGqSD25TppjJnETA= -github.com/writeas/saturday v1.6.0 h1:HNUtX8TVJJnSdxE8vaAgtHiAJVt+Of5AJYlm62pmVlI= -github.com/writeas/saturday v1.6.0/go.mod h1:ETE1EK6ogxptJpAgUbcJD0prAtX48bSloie80+tvnzQ= golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613 h1:MQ/ZZiDsUapFFiMS+vzwXkCTeEKaum+Do5rINYJDmxc= golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= diff --git a/posts/render.go b/posts/render.go deleted file mode 100644 index 157bed2..0000000 --- a/posts/render.go +++ /dev/null @@ -1,63 +0,0 @@ -package posts - -import ( - "github.com/microcosm-cc/bluemonday" - "github.com/writeas/saturday" - "regexp" - "strings" - "unicode" -) - -var ( - blockReg = regexp.MustCompile("<(ul|ol|blockquote)>\n") - endBlockReg = regexp.MustCompile("\n") - - markeddownReg = regexp.MustCompile("

(.+)

") -) - -func ApplyMarkdown(data []byte) string { - mdExtensions := 0 | - blackfriday.EXTENSION_TABLES | - blackfriday.EXTENSION_FENCED_CODE | - blackfriday.EXTENSION_AUTOLINK | - blackfriday.EXTENSION_STRIKETHROUGH | - blackfriday.EXTENSION_SPACE_HEADERS | - blackfriday.EXTENSION_HEADER_IDS - htmlFlags := 0 | - blackfriday.HTML_USE_SMARTYPANTS | - blackfriday.HTML_SMARTYPANTS_DASHES - - // Generate Markdown - md := blackfriday.Markdown([]byte(data), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions) - // Strip out bad HTML - policy := bluemonday.UGCPolicy() - policy.AllowAttrs("class", "id").Globally() - outHTML := string(policy.SanitizeBytes(md)) - // Strip newlines on certain block elements that render with them - outHTML = blockReg.ReplaceAllString(outHTML, "<$1>") - outHTML = endBlockReg.ReplaceAllString(outHTML, "") - - return outHTML -} - -func ApplyBasicMarkdown(data []byte) string { - mdExtensions := 0 | - blackfriday.EXTENSION_STRIKETHROUGH | - blackfriday.EXTENSION_SPACE_HEADERS | - blackfriday.EXTENSION_HEADER_IDS - htmlFlags := 0 | - blackfriday.HTML_SKIP_HTML | - blackfriday.HTML_USE_SMARTYPANTS | - blackfriday.HTML_SMARTYPANTS_DASHES - - // Generate Markdown - md := blackfriday.Markdown([]byte(data), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions) - // Strip out bad HTML - policy := bluemonday.UGCPolicy() - policy.AllowAttrs("class", "id").Globally() - outHTML := string(policy.SanitizeBytes(md)) - outHTML = markeddownReg.ReplaceAllString(outHTML, "$1") - outHTML = strings.TrimRightFunc(outHTML, unicode.IsSpace) - - return outHTML -}