text

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

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 MinifyHTML

func MinifyHTML(in string) (string, error)

MinifyHTML runs html through a minifier, reducing it in size.

func RemoveHTML

func RemoveHTML(in string) string

RemoveHTML removes all HTML from the given string.

func SanitizeCaption added in v0.1.1

func SanitizeCaption(in string) string

SanitizeCaption runs image captions (or indeed any plain text) through basic sanitization. It returns plain text rather than HTML, in contrast to other functions in this package.

func SanitizeHTML

func SanitizeHTML(in string) string

SanitizeHTML cleans up HTML in the given string, allowing through only safe HTML elements.

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

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