text

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emojify added in v0.6.0

func Emojify(emojis []apimodel.Emoji, inputText string) string

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 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 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 FormatResult struct {
	HTML     string
	Mentions []*gtsmodel.Mention
	Tags     []*gtsmodel.Tag
	Emojis   []*gtsmodel.Emoji
}

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

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