strip html tags by default

This commit is contained in:
gutmet 2022-11-23 23:40:58 +01:00
parent 4b6352a1d9
commit 93048cd5a3
3 changed files with 13 additions and 0 deletions

1
go.mod
View File

@ -5,4 +5,5 @@ go 1.16
require (
git.gutmet.org/go-mastodon.git v0.0.0-20221123195156-1cc330baf3e9
git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9
github.com/grokify/html-strip-tags-go v0.0.1
)

2
go.sum
View File

@ -4,3 +4,5 @@ git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9 h1:XVD037Slgdl/CxcC
git.gutmet.org/goutil.git v0.0.0-20201108182825-c19893df11f9/go.mod h1:iMgpxo9FxmbnUiQu5ugpjdtVZmh2rA9nySCr/GHkA64=
git.gutmet.org/linkheader.git v0.0.0-20221120205136-a51e89fd8486 h1:7F1dwJvIgvHNvglosyIE7SA49BwG6b8DFkvD8NtHMD8=
git.gutmet.org/linkheader.git v0.0.0-20221120205136-a51e89fd8486/go.mod h1:xArmd5A1lL5BEfB56+FUwqeG4XDfAvFGe35pqAgifCc=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=

View File

@ -13,6 +13,7 @@ import (
"git.gutmet.org/go-mastodon.git"
goutil "git.gutmet.org/goutil.git/misc"
strip "github.com/grokify/html-strip-tags-go"
)
const (
@ -21,6 +22,7 @@ const (
)
var formatTemplate *template.Template
var stripHTML bool
type mediaKind int
@ -249,6 +251,11 @@ func updateStatus(f statusFlags, args []string) []*mastodon.Status {
}
func PrintStatuses(statuses []*mastodon.Status) {
if stripHTML {
for _, status := range statuses {
status.Content = strip.StripTags(status.Content)
}
}
if formatTemplate != nil {
optLogFatal("printStatuses", formatTemplate.Execute(os.Stdout, statuses))
} else {
@ -304,6 +311,7 @@ func userTimelineCommand() (goutil.CommandFlagsInit, goutil.CommandFunc) {
type generalFlags struct {
templateFile string
stripHTML bool
}
func wrapCommand(cmd goutil.CommandFunc) func() (goutil.CommandFlagsInit, goutil.CommandFunc) {
@ -314,6 +322,7 @@ func wrapCommandFl(cmd func() (goutil.CommandFlagsInit, goutil.CommandFunc)) fun
f := generalFlags{}
flagsInit := func(s *flag.FlagSet) {
s.StringVar(&f.templateFile, "template", "", "use a template file to format tweets")
s.BoolVar(&f.stripHTML, "strip-html", true, "strip HTML tags from statuses")
}
return func() (goutil.CommandFlagsInit, goutil.CommandFunc) {
formerInit, commandFunc := cmd()
@ -326,6 +335,7 @@ func wrapCommandFl(cmd func() (goutil.CommandFlagsInit, goutil.CommandFunc)) fun
if f.templateFile != "" {
formatTemplate = template.Must(template.New(filepath.Base(f.templateFile)).Funcs(template.FuncMap{"replaceAll": strings.ReplaceAll}).ParseFiles(f.templateFile))
}
stripHTML = f.stripHTML
return commandFunc(args)
}
}