text

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package text opens text files and TXTZ files.

A TXTZ file is a zip archive that calibre writes: index.txt, its images, metadata.opf and a cover image. The cover image is the preview, and metadata.opf gives the metadata. A text file has no preview and no metadata. A TXTZ file whose entries ZipCrypto or the AES of WinZip encrypts opens with the password of ivy.Config, or with its function PasswordFunc (D12).

The package converts the text into a document of HTML. A blank line ends a paragraph. A text file joins the lines of a paragraph, which the layout wraps to the page, as calibre does with a book that a program wrapped, such as a book of Project Gutenberg (D34). A line that starts with white space, such as a space, a tab or an ideographic space, starts a new line, so that a table, code, a poem with an indent and a paragraph with an indent keep their lines. A text file in Chinese or Japanese, and a TXTZ file, keep each break of a line, as calibre does (D68). The style sheet keeps each run of spaces.

The text is UTF-8 or UTF-16 with a byte order mark, or UTF-8 without one. Text that is not valid UTF-8 is read as windows-1252. Markdown is the package markdown.

The document takes the language of the text: the language of the header of a Project Gutenberg file, or else the East Asian language that the letters show. The layout takes the fonts of that language for the CJK characters.

The layout of phase 4 puts the document on pages (D10, D15): a page of US Letter in a monospace font for a text file, and the page of an ebook for a TXTZ file. Page lays out the document only as far as the page that a program asks for.

Index

Constants

This section is empty.

Variables

View Source
var Format = ivy.Format{
	Name:  "text",
	Mimes: []string{"text/plain", "application/txtz+zip"},
	Exts:  []string{"txt", "text", "txtz"},
	Open: func(ctx context.Context, src ivy.Source, cfg ivy.Config) (ivy.Document, error) {
		return Open(ctx, src, WithConfig(cfg))
	},
}

Format describes the package for the registry of a program.

Functions

This section is empty.

Types

type Document

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

Document is an open text or TXTZ file.

func Open

func Open(ctx context.Context, src ivy.Source, opts ...Option) (d *Document, err error)

Open opens a text file or a TXTZ file, and converts the text into a document of HTML. A source that starts as a zip archive is a TXTZ file, and any other source is a text file. It returns an error that wraps ivy.ErrFormat if a TXTZ file holds no text, one that wraps ivy.ErrPassword if no password opens an encrypted TXTZ file, and one that wraps ivy.ErrLimit if the text or its document of HTML is larger than Limits.MaxMemory.

func (*Document) Close

func (d *Document) Close() error

Close satisfies the ivy.Document interface.

func (*Document) Describe

func (d *Document) Describe(ctx context.Context) (ivy.Info, error)

Describe satisfies the ivy.Describer interface. For a TXTZ file, it reads metadata.opf. A text file says nothing about itself.

func (*Document) Page

func (d *Document) Page(ctx context.Context, n int) (ivy.Page, error)

Page satisfies the ivy.Pager interface. It lays out the document only as far as page n.

func (*Document) PageCount

func (d *Document) PageCount(ctx context.Context) (int, error)

PageCount satisfies the ivy.Pager interface. It lays out the whole document on its first call.

func (*Document) Previews

func (d *Document) Previews(ctx context.Context) iter.Seq2[ivy.Preview, error]

Previews satisfies the ivy.Previewer interface. It lists the cover image of a TXTZ file: the cover that metadata.opf names, or a file named cover.jpg or cover.png in the root. A text file has no preview.

type Option

type Option func(*options)

Option is an option of Open.

func WithConfig

func WithConfig(cfg ivy.Config) Option

WithConfig sets the configuration that every format shares.

Jump to

Keyboard shortcuts

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