Documentation
¶
Overview ¶
Code generated by scripts/build-go-engine.sh; DO NOT EDIT.
Package bionicreader transforms text and Markdown with bionic reading emphasis. It embeds the shared Rust engine and runs locally without CGO, Rust, a CLI, or a network service. Reuse a Reader and close it when finished.
Index ¶
- Constants
- Variables
- func Pointer[T any](value T) *T
- type Error
- type Format
- type LengthRule
- type Options
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) ParseConfig(ctx context.Context, contents string) (Options, error)
- func (r *Reader) Render(ctx context.Context, text string, format Format, options Options) (string, error)
- func (r *Reader) Segments(ctx context.Context, text string, options Options) ([]TextSegment, error)
- type TextSegment
Examples ¶
Constants ¶
const Version = "0.3.0"
Version is the Cargo-owned package and embedded-engine version.
Variables ¶
var ErrClosed = &Error{Code: "closed_reader", Message: "bionic reader is closed or uninitialized"}
ErrClosed is returned when using a closed or uninitialized Reader.
Functions ¶
Types ¶
type Error ¶
Error is a transformation or engine failure with a stable machine-readable code. Codes are invalid_input, initialization_failed, engine_failed, and closed_reader. Context cancellation and deadline errors are returned directly.
type LengthRule ¶
LengthRule sets an emphasis fraction through an inclusive word-length limit.
type Options ¶
type Options struct {
Enabled *bool `json:"enabled,omitempty"`
Profile string `json:"profile,omitempty"`
Fraction *float64 `json:"fraction,omitempty"`
Every *uint32 `json:"every,omitempty"`
MinWordLength *uint32 `json:"min_word_length,omitempty"`
LengthRules []LengthRule `json:"length_rules,omitempty"`
Emphasis string `json:"emphasis,omitempty"`
InputFormat string `json:"input_format,omitempty"`
Controls string `json:"controls,omitempty"`
SkipCode *bool `json:"skip_code,omitempty"`
}
Options overrides balanced defaults. Nil pointers leave defaults unchanged; Pointer(false) and Pointer(0.0) explicitly disable emphasis or prefix selection. Word counts must be positive and rules must have increasing thresholds.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader owns a reusable compiled engine. Calls are safe concurrently and use isolated instances without filesystem or network access. It must not be copied. Close waits for active calls; cancel their contexts to interrupt them.
func NewReader ¶
NewReader loads and validates the embedded engine. No files are discovered or downloaded. The context bounds initialization, not the lifetime of the reader.
func (*Reader) Close ¶
Close releases engine resources and is idempotent. It waits for active calls.
func (*Reader) ParseConfig ¶
ParseConfig parses explicitly supplied TOML contents, performing no file I/O. A style of never disables emphasis; auto is deterministically enabled. The caller still chooses Render's format explicitly. Session-only fields are ignored.
func (*Reader) Render ¶
func (r *Reader) Render(ctx context.Context, text string, format Format, options Options) (string, error)
Render transforms a whole Unicode string in the explicitly selected format. Markdown input is limited to 8 MiB of UTF-8. Other inputs are bounded by available memory and the WebAssembly linear-memory limit. No configuration files, terminal state, NO_COLOR, or TERM are inspected.
Example ¶
package main
import (
"context"
"fmt"
bionicreader "github.com/arturoaviles/bionic-reader"
)
func main() {
ctx := context.Background()
reader, err := bionicreader.NewReader(ctx)
if err != nil {
panic(err)
}
defer reader.Close()
html, err := reader.Render(ctx, "Hello world", bionicreader.HTML, bionicreader.Options{})
if err != nil {
panic(err)
}
fmt.Println(html)
}
Output: <strong>Hel</strong>lo <strong>wor</strong>ld
type TextSegment ¶
TextSegment is literal visible text with its bionic reading emphasis state.