text

package
v0.13.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: AGPL-3.0 Imports: 30 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 MinifyHTML

func MinifyHTML(in string) string

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

func NormalizeHashtag(text string) (string, bool)

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 letters, numbers, and underscores (and not *JUST* underscores).

If all this passes, returned bool will be true.

func SanitizeToHTML added in v0.11.0

func SanitizeToHTML(in string) string

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

func SanitizeToPlaintext added in v0.11.0

func SanitizeToPlaintext(in string) string

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,
	parseMention gtsmodel.ParseMentionFunc,
	authorID string,
	statusID string,
	text string,
) *FormatResult

FormatFunc is fulfilled by FromPlain, FromPlainNoParagraph, and FromMarkdown.

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 struct {
	// contains filtered or unexported fields
}

Formatter wraps 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.

func (*Formatter) FromMarkdown

func (f *Formatter) FromMarkdown(
	ctx context.Context,
	parseMention gtsmodel.ParseMentionFunc,
	authorID string,
	statusID string,
	input string,
) *FormatResult

FromMarkdown fulfils FormatFunc by parsing the given markdown input into a FormatResult.

func (*Formatter) FromPlain

func (f *Formatter) FromPlain(
	ctx context.Context,
	parseMention gtsmodel.ParseMentionFunc,
	authorID string,
	statusID string,
	input string,
) *FormatResult

FromPlain fulfils FormatFunc by parsing the given plaintext input into a FormatResult.

func (*Formatter) FromPlainEmojiOnly added in v0.7.0

func (f *Formatter) FromPlainEmojiOnly(
	ctx context.Context,
	parseMention gtsmodel.ParseMentionFunc,
	authorID string,
	statusID string,
	input string,
) *FormatResult

FromPlainEmojiOnly fulfils FormatFunc by parsing the given plaintext input into a FormatResult.

Unlike FromPlain, it will only parse emojis with the custom renderer, leaving aside mentions and tags.

func (*Formatter) FromPlainNoParagraph added in v0.9.0

func (f *Formatter) FromPlainNoParagraph(
	ctx context.Context,
	parseMention gtsmodel.ParseMentionFunc,
	authorID string,
	statusID string,
	input string,
) *FormatResult

FromPlainNoParagraph fulfils FormatFunc by parsing the given plaintext input into a FormatResult.

Unlike FromPlain, it will not wrap the resulting HTML in <p> tags, making it useful for parsing short fragments of text that oughtn't be formally wrapped as a paragraph.

Jump to

Keyboard shortcuts

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