render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const KittyChunk = 4096

KittyChunk is the payload size per escape.

Kitty's protocol requires the base64 be split, and 4096 is the documented chunk size. Larger works on kitty itself and breaks through tmux, which has its own buffer limits.

Variables

This section is empty.

Functions

func ITermImage

func ITermImage(png []byte, cols, rows int) string

ITermImage encodes a PNG for iTerm2's protocol.

One sequence, no chunking. `inline=1` draws it rather than offering a download, and preserveAspectRatio keeps a tree diagram from being squashed into its box.

func KittyImage

func KittyImage(png []byte, cols, rows int) string

KittyImage encodes a PNG for kitty's graphics protocol.

cols and rows bound the drawing to a cell box, so a diagram cannot push the statement off the screen — the terminal scales to fit.

func Markdown

func Markdown(md string, width int) (string, error)

Markdown renders markdown to styled terminal output at the given width.

func Passthrough

func Passthrough(seq string) string

Passthrough wraps an escape so it survives tmux.

tmux eats sequences it does not recognise unless `allow-passthrough` is on, and even then the payload must be wrapped in its own DCS and every ESC inside it doubled — otherwise tmux terminates the wrapper at the first one and prints the rest as text.

`leetui doctor` reports when passthrough is off, because the failure is otherwise completely silent: no error anywhere, just a figure that never appears.

func ToPNG

func ToPNG(data []byte) ([]byte, error)

ToPNG re-encodes an image so kitty can draw it.

Kitty's f=100 means PNG. LeetCode serves plenty of JPEGs, and handing one over with f=100 produces no picture and no error — the terminal simply fails to decode and nothing appears, which is the silent failure this whole path is trying to avoid.

A PNG passes through untouched: re-encoding one would cost time and lose nothing.

Types

type Document

type Document struct {
	// Markdown is ready for Glamour.
	Markdown string

	// Images are the URLs behind each bracket marker, in the order they appear.
	// Marker "[▸ img 2 …]" is Images[1].
	Images []Image
}

Document is converted content plus the assets referenced from it.

func EditorialToMarkdown

func EditorialToMarkdown(md string) Document

EditorialToMarkdown reduces an editorial's embedded HTML to markers.

Split out from Editorial so it can be tested without a terminal renderer, and so a caller that wants the markdown (a future "save the editorial next to the solution") does not have to render it first.

func HTMLToMarkdown

func HTMLToMarkdown(input string) (Document, error)

HTMLToMarkdown converts a LeetCode problem statement or editorial.

type Image

type Image struct {
	URL string
	Alt string
}

Image is a referenced image.

func Editorial

func Editorial(md string, width int) (string, []Image, error)

Editorial converts an official solution's markdown and renders it at the given width, returning the assets behind each bracket marker in the order they appear.

func HTML

func HTML(input string, width int) (string, []Image, error)

HTML converts LeetCode HTML and renders it in one step, returning the referenced images so the caller can wire up "open image" on the bracket markers.

Jump to

Keyboard shortcuts

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