markdown

package
v1.0.31-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 38 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchImage

func FetchImage(src string) (image.Image, error)

FetchImage loads the image src names, for Options.LoadImage: an http or https URL, a data: URI (base64), or a local file (a path or a file: URL). It reads PNG, JPEG, GIF (the first frame) and WebP. Downloads time out after 20 seconds and stop at 20 MB.

Loading the images of Markdown the app doesn't control - a model's reply, a message from someone else - tells their servers that the document was opened, and from where: wrap FetchImage to allow only trusted hosts in such a case.

func New

func New(src string, opts ...Options) elements.Element

New renders src. Like Text it's stateless: build it in the view function every frame; parsing is cached per source, so a reply that streams in is re-parsed only when it changes.

giode.Markdown(reply, giode.MarkdownOptions{OnLink: openURL, Selectable: msg.ID})

Types

type Options

type Options struct {
	// Styles is the body text: Color (default theme.text), FontSize
	// (default 14), LineHeight, FontFamily.
	Styles styles.Styles
	// CodeFont is the typeface of code spans and blocks, default
	// "Go Mono" (register it, or your own monospace face, with
	// RegisterFonts).
	CodeFont properties.FontFamily
	// CodeBackground fills code spans and blocks, default a faint tint
	// of the text color.
	CodeBackground properties.Color
	// LinkColor colors links, default theme.primary.
	LinkColor properties.Color
	// OnLink handles taps on links; by default they open in the
	// browser.
	OnLink func(url string)
	// Selectable, when set, makes the document selectable as a whole -
	// drag across paragraphs, headings, lists, tables and code, then
	// copy - by putting it in a SelectionArea; its value identifies the
	// document, as a message ID would. A document already inside a
	// SelectionArea is part of that area's selection, with or without
	// it.
	Selectable any
	// Gap is the space between blocks in dp, default 10.
	Gap int
	// LoadImage, when set, loads the pictures of ![alt](src), in
	// paragraphs, headings and table cells, given src: FetchImage
	// reads URLs, data: URIs and files, or wrap it to resolve relative
	// paths or allow only some hosts. It's called once per src, off the
	// UI goroutine, and the image is kept for the next documents that
	// show it. An image shows at its pixel size in dp, narrowed to the
	// width there is, on a line of its own (side by side with images
	// next to it); its alt text shows while it loads and if it fails.
	// Without LoadImage, images show as their alt text.
	LoadImage func(src string) (image.Image, error)
	// Math sets formulas, with package formula imported (which adds its
	// math font): $$...$$ and \[...\] starting a line as display
	// formulas, centered; $...$ and \(...\) in a paragraph inline, on
	// the text's baseline and wrapping with the words. A $ opens a
	// formula when no space follows it and closes one when no space
	// comes before it and no digit after it, as on GitHub, so "$5 and
	// $10" stays text; \$ is a dollar sign. A selection copies a
	// formula as its source. One that doesn't read (formula.Check), or
	// without package formula, shows its source as code.
	Math bool
}

Options configures how Markdown renders. The zero value works.

Jump to

Keyboard shortcuts

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