article

package
v0.0.0-...-58747ad Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(title, domain string) error

func ValidateURL

func ValidateURL(rawURL string) error

ValidateURL is Validate for a bare link followed from inside an article: there is no story title to carry [pdf]-style tags, so the scheme, the domain blocklist, and the path's file type stand in for it. The reader's link selector shows failing links muted and inert.

Types

type CodeBlock

type CodeBlock struct {
	// Declared is the language the page itself named, empty when unlabeled.
	Declared string

	// Guessed is what GuessLang makes of the same text, filled in whether or
	// not the page declared anything — a page that declares its language is
	// free ground truth to score the guesser against.
	Guessed string

	Text string
}

CodeBlock reports how one code block's language resolved.

type ImageOptions

type ImageOptions struct {
	// Show renders image blocks as pixels instead of a text label.
	Show bool
	// Kitty reports that the terminal speaks the Kitty graphics protocol.
	// Without it there is no way to draw an image, so every image block
	// renders as its label regardless of Show.
	Kitty bool
	// CellWidth and CellHeight are one terminal cell's pixel dimensions,
	// which keep an image's aspect ratio honest in cells. Zero assumes cells
	// twice as tall as wide.
	CellWidth, CellHeight int
}

ImageOptions controls how image blocks render.

type KittyWork

type KittyWork struct {
	ID         int
	PNG        []byte
	Cols, Rows int
}

KittyWork is one image whose terminal state is stale: PNG data still to transmit, or — with PNG nil — an already-transmitted image whose placement geometry changed with the layout.

type Parsed

type Parsed struct {

	// Title is the page's own title as readability extracted it; empty for
	// plain-text pages. Articles opened from a story use the story title
	// instead — this one names pages reached by following links.
	Title string
	// contains filtered or unexported fields
}

Parsed holds the block representation of a fetched article, allowing re-rendering at different widths without re-fetching.

func NewParsedFromHTML

func NewParsedFromHTML(src string) *Parsed

NewParsedFromHTML skips fetching and readability extraction; for tests.

func Parse

func Parse(ctx context.Context, url string, images bool) (*Parsed, error)

Parse fetches the article at url and turns it into renderable blocks. The page's images are downloaded and decoded only when images is true: nothing below a Kitty-graphics terminal can draw them, and there the whole fetch-decode-rasterize-encode pass would be discarded for a text label. Whether a drawable image is actually shown is still decided later, at render time, by the h/l toggle.

Callers inside a started program pass graphics.Enabled(). The standalone commands cannot: they parse before the program exists, and a terminal without graphics support answers the probe with silence rather than a no — so "not supported" and "has not answered yet" are the same reading. They pass true and keep fetching unconditionally.

func (*Parsed) CodeBlocks

func (p *Parsed) CodeBlocks() []CodeBlock

CodeBlocks reports every code block in the article, for the guess-report tool.

func (*Parsed) HasImages

func (p *Parsed) HasImages(kitty bool) bool

HasImages reports whether any block holds pixels the h/l toggle can reveal. Only a terminal speaking the Kitty graphics protocol can draw them, so without it there is nothing to toggle and every image stays a label.

func (*Parsed) PendingKittyWork

func (p *Parsed) PendingKittyWork() []KittyWork

PendingKittyWork returns the images whose terminal state no longer matches the geometry the last render recorded, and marks them clean — the caller owes the terminal exactly these sequences. Hidden images record geometry too: their pixels travel while they are hidden, so the first show composites instantly. Images the Kitty path never sized (terminal without graphics) want nothing and never appear.

func (*Parsed) RenderWithHeader

func (p *Parsed) RenderWithHeader(contentWidth, screenWidth int, header string, images ImageOptions) Rendered

RenderWithHeader wraps prose at contentWidth; code boxes span at least contentWidth and grow toward screenWidth, which verbatim text and tables extend to directly. A screenWidth of 0 keeps everything at contentWidth. The right edge reserves the scrollbar column so a full-width line is not clipped by the bar. images controls whether decoded images render as art or fall back to a text label.

type Rendered

type Rendered struct {
	Body string

	// BlockStarts holds the line index each block starts on, so a scroll
	// position can be re-anchored to the same block after a re-render
	// changes block heights (image toggling, resizing).
	BlockStarts []int

	// HeadingStarts holds the line index of each section heading, for
	// jumping between sections.
	HeadingStarts []int
}

Rendered is one rendering of a Parsed article at a particular width.

type UnsupportedDomainError

type UnsupportedDomainError struct {
	Domain string
}

UnsupportedDomainError is typed so the status bar can highlight the domain.

func (*UnsupportedDomainError) Error

func (e *UnsupportedDomainError) Error() string

Jump to

Keyboard shortcuts

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