Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindLinks ¶
FindLinks parses the given string looking for recognizable URLs (including scheme). It returns a list of those URLs, without changing the string, or an error if something goes wrong. If no URLs are found within the given string, an empty slice and nil will be returned.
func SanitizeHTML ¶
SanitizeHTML sanitizes risky html elements from the given string, allowing only safe ones through.
func SanitizePlaintext ¶ added in v0.3.4
SanitizePlaintext runs text through basic sanitization. This removes any html elements that were in the string, and returns clean plaintext.
Types ¶
type Formatter ¶
type Formatter interface { // FromMarkdown parses an HTML text from a markdown-formatted text. FromMarkdown(ctx context.Context, md string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string // FromPlain parses an HTML text from a plaintext. FromPlain(ctx context.Context, plain string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string // ReplaceTags takes a piece of text and a slice of tags, and returns the same text with the tags nicely formatted as hrefs. ReplaceTags(ctx context.Context, in string, tags []*gtsmodel.Tag) string // ReplaceMentions takes a piece of text and a slice of mentions, and returns the same text with the mentions nicely formatted as hrefs. ReplaceMentions(ctx context.Context, in string, mentions []*gtsmodel.Mention) string // ReplaceLinks takes a piece of text, finds all recognizable links in that text, and replaces them with hrefs. ReplaceLinks(ctx context.Context, in string) string }
Formatter wraps some logic and functions for parsing statuses and other text input into nice html.
func NewFormatter ¶
NewFormatter returns a new Formatter interface for parsing statuses and other text input into nice html.