Documentation
¶
Overview ¶
Package richtext is Godwit's rich text model: mail bodies, compose content and Markdown become a flat list of blocks that the native UI draws (spec 5.5), and compose content goes back to HTML.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = Limits{20, 5000, 2000, 20000}
DefaultLimits are the budget for one mail (global constraints).
Functions ¶
func Autospace ¶
Autospace splits s into spans so that the character before each place where CJK text meets a Latin letter or digit is a span of its own with a quarter em (size/4) of LetterSpacing (CSS text-autospace: normal). No characters are added: the text of the spans is s.
Types ¶
type Block ¶
type Block struct {
Kind BlockKind
Level int
Ordered bool
Inlines []Inline
Rows [][]Cell
Header bool
Image *Image
}
Block is one block. Which fields count depends on Kind.
type Doc ¶
type Doc struct{ Blocks []Block }
Doc is a document: blocks from top to bottom.
func FromComposeHTML ¶
FromComposeHTML converts compose content (mail.SanitizeCompose output or a draft's editable part): links come from href, and only paragraphs, bold, italic, links, lists, quotes and data: images (a draft's signature images, for showing) stay; everything else becomes paragraph text.
func FromMailHTML ¶
FromMailHTML converts a received mail's sanitized HTML (Message.HTML after mail.Sanitize): links come from data-href, images from data: or http(s) src. truncated reports that lim cut something off.
func FromMarkdown ¶
FromMarkdown converts Markdown (a model's answer, say) through the same sanitizer as received mail, so it gets no more than mail does. Remote images are dropped: loading one would tell its server what was written.
type Image ¶
Image is an image block. Src is a data: URL (PNG, JPEG, GIF, WebP) or an http(s) URL; Width and Height are the HTML attributes, 0 when unknown.
type Inline ¶
type Inline struct {
Text string
Bold, Italic, Code, Strike, Underline bool
Link string
Color string // a CSS color, from the sanitized inline style
}
Inline is a run of text in one style. "\n" in Text is a line break.
type Limits ¶
type Limits struct{ MaxDepth, MaxBlocks, MaxCells, MaxInlines int }
Limits bound what a conversion produces: element nesting (deeper subtrees become plain text), blocks, cells of one table and inlines of one block.
type Pos ¶
type Pos struct{ Block, Rune int }
Pos is a place in a document: a rune of a block's text (its inlines' text together).
type RenderOptions ¶
type RenderOptions struct {
FontSize float32
Background ui.Color
Images func(src string) *ui.Bitmap
OnLink func(url string)
}
RenderOptions are how Render draws a document. FontSize defaults to the body font size, Background (what the document is drawn on, for the contrast check) to the theme's. Images returns a loaded image or nil for a placeholder. OnLink gets the target of an activated link; the host shows it before opening it.