Documentation ¶
Index ¶
- func Demojify(text string) string
- func EmojifyRSS(emojis []apimodel.Emoji, text string) string
- func EmojifyWeb(emojis []apimodel.Emoji, html template.HTML) template.HTML
- func MinifyHTML(in string) string
- func NormalizeHashtag(text string) (string, bool)
- func SanitizeToHTML(in string) string
- func SanitizeToPlaintext(in string) string
- type FormatFunc
- type FormatResult
- type Formatter
- func (f *Formatter) FromMarkdown(ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, ...) *FormatResult
- func (f *Formatter) FromPlain(ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, ...) *FormatResult
- func (f *Formatter) FromPlainEmojiOnly(ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, ...) *FormatResult
- func (f *Formatter) FromPlainNoParagraph(ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, ...) *FormatResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Demojify ¶ added in v0.14.0
Demojify replaces emoji shortcodes like `:example:` in the given text fragment with empty strings, essentially stripping them from the text. This is useful for text used in OG Meta headers.
func EmojifyRSS ¶ added in v0.14.0
EmojifyRSS replaces emoji shortcodes like `:example:` in the given text fragment with `<img>` tags suitable for rendering as RSS content.
func EmojifyWeb ¶ added in v0.14.0
EmojifyWeb replaces emoji shortcodes like `:example:` in the given HTML fragment with `<img>` tags suitable for rendering on the web frontend.
func MinifyHTML ¶
MinifyHTML minifies the given string under the assumption that it's HTML.
If input is not HTML encoded, this function will try to do minimization anyway, but this may produce unexpected results.
If an error occurs during minimization, it will be logged and the original string returned unmodified.
func NormalizeHashtag ¶ added in v0.11.0
NormalizeHashtag normalizes the given hashtag text by removing the initial '#' symbol, and then decomposing and canonically recomposing chars + combining diacritics in the text to single unicode characters, following Normalization Form C (https://unicode.org/reports/tr15/).
Finally, it will do a check on the normalized string to ensure that it's below maximumHashtagLength chars, and contains only letters, numbers, and underscores (and not *JUST* underscores).
If all this passes, returned bool will be true.
func SanitizeToHTML ¶ added in v0.11.0
SanitizeToHTML sanitizes only risky html elements from the given string, allowing safe ones through.
func SanitizeToPlaintext ¶ added in v0.11.0
SanitizeToPlaintext runs text through basic sanitization. This removes any html elements that were in the string, and returns clean plaintext.
Types ¶
type FormatFunc ¶ added in v0.7.0
type FormatFunc func( ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, statusID string, text string, ) *FormatResult
FormatFunc is fulfilled by FromPlain, FromPlainNoParagraph, and FromMarkdown.
type FormatResult ¶ added in v0.7.0
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter wraps logic and functions for parsing statuses and other text input into nice html.
func (*Formatter) FromMarkdown ¶
func (f *Formatter) FromMarkdown( ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, statusID string, input string, ) *FormatResult
FromMarkdown fulfils FormatFunc by parsing the given markdown input into a FormatResult.
func (*Formatter) FromPlain ¶
func (f *Formatter) FromPlain( ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, statusID string, input string, ) *FormatResult
FromPlain fulfils FormatFunc by parsing the given plaintext input into a FormatResult.
func (*Formatter) FromPlainEmojiOnly ¶ added in v0.7.0
func (f *Formatter) FromPlainEmojiOnly( ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, statusID string, input string, ) *FormatResult
FromPlainEmojiOnly fulfils FormatFunc by parsing the given plaintext input into a FormatResult.
Unlike FromPlain, it will only parse emojis with the custom renderer, leaving aside mentions and tags.
func (*Formatter) FromPlainNoParagraph ¶ added in v0.9.0
func (f *Formatter) FromPlainNoParagraph( ctx context.Context, parseMention gtsmodel.ParseMentionFunc, authorID string, statusID string, input string, ) *FormatResult
FromPlainNoParagraph fulfils FormatFunc by parsing the given plaintext input into a FormatResult.
Unlike FromPlain, it will not wrap the resulting HTML in <p> tags, making it useful for parsing short fragments of text that oughtn't be formally wrapped as a paragraph.