Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Emojify ¶ added in v0.6.0
Emojify replaces shortcodes in `inputText` with the emoji in `emojis`.
Callers should ensure that inputText and resulting text are escaped appropriately depending on what they're used for.
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 unicode letters and numbers. If 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, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, text string) *FormatResult
type FormatResult ¶ added in v0.7.0
type Formatter ¶
type Formatter interface { // FromPlain parses an HTML text from a plaintext. FromPlain(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult // FromPlainNoParagraph parses an HTML text from a plaintext, without wrapping the resulting text in <p> tags. FromPlainNoParagraph(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult // FromMarkdown parses an HTML text from a markdown-formatted text. FromMarkdown(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, md string) *FormatResult // FromPlainEmojiOnly parses an HTML text from a plaintext, only parsing emojis and not mentions etc. FromPlainEmojiOnly(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult }
Formatter wraps some logic and functions for parsing statuses and other text input into nice html. Each of the member functions returns a struct containing the formatted HTML and any tags, mentions, and emoji that were found in the text.
func NewFormatter ¶
NewFormatter returns a new Formatter interface for parsing statuses and other text input into nice html.