text

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindLinks(in string) []*url.URL

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

func SanitizeHTML(in string) string

SanitizeHTML sanitizes risky html elements from the given string, allowing only safe ones through.

func SanitizePlaintext added in v0.3.4

func SanitizePlaintext(in string) string

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 {
	// FromPlain parses an HTML text from a plaintext.
	FromPlain(ctx context.Context, plain string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string
	// FromMarkdown parses an HTML text from a markdown-formatted text.
	FromMarkdown(ctx context.Context, md string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag, emojis []*gtsmodel.Emoji) 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

func NewFormatter(db db.DB) Formatter

NewFormatter returns a new Formatter interface for parsing statuses and other text input into nice html.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL