text

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxIter = 100

Functions

func WrapFunc

func WrapFunc(fn func(string) string) func(string) (string, error)

WrapFunc wraps a simple string -> string function into a function matching the Processor signature.

Types

type Cutter added in v0.1.81

type Cutter struct {
	Sep string
}

Cutter splits the input by the given separator and keeps only the part before it.

func (Cutter) Describe added in v0.1.81

func (p Cutter) Describe() string

Describe returns a string representation of the Cutter.

func (Cutter) Once added in v0.1.81

func (Cutter) Once() bool

Once always returns true, meaning this processor should be run only once.

func (Cutter) Process added in v0.1.81

func (p Cutter) Process(s string) (string, error)

Process cuts the string at the first occurrence of the separator and returns the left part.

type LineToParagraph added in v0.1.83

type LineToParagraph struct {
	// TrimSpace controls whether leading and trailing spaces are removed from each line.
	// true  → trim spaces
	// false → preserve spaces (default, matches previous behaviour)
	TrimSpace bool
	// SkipEmpty controls whether completely empty lines produce <p></p> or are ignored.
	// true  → skip empty lines (default, matches previous behaviour)
	// false → emit <p></p> for empty lines
	SkipEmpty bool
}

LineToParagraph converts each line of text into a separate HTML <p>...</p> paragraph. TrimSpace controls whether leading and trailing spaces are removed from each line before wrapping it in <p> tags. Empty lines can be either skipped or rendered as empty <p></p> according to the SkipEmpty flag.

func (LineToParagraph) Describe added in v0.1.83

func (p LineToParagraph) Describe() string

Describe returns a human-readable description of the processor.

func (LineToParagraph) Once added in v0.1.83

func (LineToParagraph) Once() bool

Once returns true – the transformation is idempotent and should run only once.

func (LineToParagraph) Process added in v0.1.83

func (p LineToParagraph) Process(s string) (string, error)

Process transforms the input text line-by-line into HTML paragraphs.

type Processor

type Processor interface {
	// Describe returns a short description of this processor.
	Describe() string
	// Once reports whether this processor should run only once.
	Once() bool
	// Process performs the actual text transformation.
	Process(string) (string, error)
}

Processor defines a generic interface for text processors. Each processor can optionally be executed only once (Once == true) and provides a human-readable description for debugging or logging.

func CutSpace added in v0.1.81

func CutSpace() Processor

CutSpace returns a processor that extracts the first word in the input string.

func NewMultiProcessor added in v0.1.81

func NewMultiProcessor(desc string, once bool, procs ...Processor) Processor

NewMultiProcessor creates a new MultiProcessor.

desc  - human-readable name
once  - whether this processor should execute only once
procs - list of sub-processors

func NewProcessor

func NewProcessor(desc string, once bool, fn func(string) (string, error)) Processor

NewProcessor creates a new Processor from a function.

desc - short description for debugging
once - whether this processor should be executed only once
fn   - transformation function taking a string and returning a string/error

func RemoveParentheses added in v0.1.81

func RemoveParentheses() Processor

RemoveParentheses returns a processor that remove both western and full-width parentheses.

func ToParagraphs added in v0.1.83

func ToParagraphs(skipEmpty bool) Processor

ToParagraphs returns a processor that converts each line into a <p> paragraph. If skipEmpty is true, empty lines are ignored; otherwise, they produce empty <p></p>.

func TrimSpace added in v0.1.81

func TrimSpace() Processor

TrimSpace returns a processor that removes leading and trailing spaces.

type RegexpRemover added in v0.1.81

type RegexpRemover struct {
	Re *regexp.Regexp
}

RegexpRemover removes substrings that match the given regular expression.

func (RegexpRemover) Describe added in v0.1.81

func (p RegexpRemover) Describe() string

Describe returns a string representation of the RegexpRemover.

func (RegexpRemover) Once added in v0.1.81

func (RegexpRemover) Once() bool

Once always returns false, meaning this processor can be applied repeatedly.

func (RegexpRemover) Process added in v0.1.81

func (p RegexpRemover) Process(s string) (string, error)

Process removes all matches of the regular expression from the input string.

type Tasks

type Tasks struct {
	// contains filtered or unexported fields
}

Tasks represents an ordered list of text processors. Each processor in the list will be executed sequentially, and repeated until the text no longer changes.

func NewTasks

func NewTasks(tasks ...Processor) *Tasks

NewTasks creates a new Tasks instance with the provided processors.

func (*Tasks) Append

func (t *Tasks) Append(tasks ...Processor) *Tasks

Append adds one or more processors to the task list and returns the updated instance.

func (*Tasks) Process

func (t *Tasks) Process(s string) (output string, err error)

Process executes all configured processors on a single string.

func (*Tasks) ProcessAll

func (t *Tasks) ProcessAll(inputs []string) ([]string, error)

ProcessAll applies all processors to a slice of strings, returning the processed results. If any processor returns an error, processing stops and the error is returned.

type Trimmer added in v0.1.81

type Trimmer struct {
	Cutset string
}

Trimmer removes all leading and trailing characters from the given cutset.

func (Trimmer) Describe added in v0.1.81

func (p Trimmer) Describe() string

Describe returns a string representation of the Trimmer.

func (Trimmer) Once added in v0.1.81

func (Trimmer) Once() bool

Once always returns false, meaning this processor can be applied repeatedly.

func (Trimmer) Process added in v0.1.81

func (p Trimmer) Process(s string) (string, error)

Process trims all leading and trailing characters in Cutset from the input string.

Jump to

Keyboard shortcuts

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