Documentation
¶
Overview ¶
Package render owns htmlterm's HTML/CSS layout engine and render-state production. It is internal so the public root package can stay a small generic renderer facade.
Index ¶
Constants ¶
const DefaultStylesheet = `` /* 5832-byte string literal not displayed */
DefaultStylesheet is the built-in default stylesheet, of lowest priority, with Options.CSS and Options.Stylesheets layered above it. Re-exported by the root package as htmlterm.DefaultStylesheet, so callers can inspect it or diff their own overrides against it. Parsed once per Engine by New.
This is the user-agent sheet, the terminal analogue of a browser's own default styles. It carries only what a rule can express: display types, font weight and style, margins and padding, borders, generated content. Anything needing engine behavior instead of a declaration is not here and cannot be moved here by adding a rule.
Two categories in particular are handled in Go, not CSS:
- Head-level elements never reach the CSS cascade at all. render.go's isSkippedContentElement drops <style>, <script>, <meta>, <link>, and <template> wherever they appear, and its root dispatch skips <head> outright, which covers <title>. A `display: none` rule for any of them would be dead weight, so there isn't one.
- Form controls and widgets get their structure from their renderers (formcontrol.go, select_popup.go, table*.go). The rules below set only the parts a stylesheet owns, such as a control's outer display type or a button's bracket affixes.
const ScrollbarGutterHeight = 1
ScrollbarGutterHeight is ScrollbarGutterWidth's horizontal-scrollbar counterpart: the default row count reserved for a horizontal scrollbar gutter when overflow-x:scroll is set, and no ::scrollbar-x height declaration overrides it, on an element with an explicit width and no height of its own. See the "scroll"/"auto" case in renderBlockContentBox's overflow-x handling, and docs/SCROLLING.md.
const ScrollbarGutterWidth = 1
ScrollbarGutterWidth is the default column width reserved for the scrollbar gutter when overflow-y:scroll is set and no ::scrollbar width declaration overrides it. See docs/SCROLLING.md's "Scrollbar gutter and indicator" and docs/SCROLLBARS.md. It is exported, via htmlterm.ScrollbarGutterWidth, so callers who pre-render content outside a scrollable Document or Renderer pass — to cache an expensive layout, say, then splice it into a live scrollable pane via Document.SetPreRendered — can reserve the same column up front. Otherwise the pre-rendered content is wrapped 1 column wider than the live pane's actual content width once the gutter is reserved there, desyncing the two and producing exactly the scrollbar-off-by-one symptom this constant exists to prevent. A caller that also sets a custom ::scrollbar { width } on the live pane must account for that override itself; this constant only reflects the built-in default.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine renders already-parsed HTML trees or HTML strings to terminal output.
func New ¶
New parses opts.CSS/opts.Stylesheets and returns a reusable render engine.
Cascade order, lowest priority first: the built-in default stylesheet (DefaultStylesheet), opts.CSS, then each of opts.Stylesheets in order, mirroring how a page's own stylesheet is followed by however many <link> sheets it loads. Document <style> elements and inline style= attributes are layered on top of all of these at render time (see DocumentRules and cssengine.Cascade). DefaultStylesheet's own parsed rules are also kept separately, as uaRules, purely to give the "revert" cascade-wide keyword a user-agent-only rule set to fall back to (see cssengine.Cascade.UARules).
func (*Engine) DocumentRules ¶
DocumentRules returns the final rule set for doc: engine rules plus any active <style> rules, unless document CSS is ignored.
func (*Engine) RenderHTML ¶
RenderHTML parses htmlStr and renders it. It returns layout metadata for callers that need it; the public root facade discards everything except Output.
type Options ¶
type Options struct {
CSS string
Stylesheets []string
Width int
Height int
IgnoreDocumentCSS bool
Profile colorprofile.Profile
NoOSC8Links bool
MaxBlankLines int
StripHiddenInline bool
FocusAttr string
SelectOpenAttr string
SelectHighlightAttr string
SelectionStartAttr string
SelectionEndAttr string
DialogModalAttr string
DatalistOpenAttr string
DatalistMatchAttr string
}
Options configures the internal render engine. The public htmlterm.Options type is converted to this type by the root package facade.
type Rect ¶
Rect is a box's position and size relative to whatever coordinate space it was recorded in. See docs/RENDERING.md's "Position tracking" section. It approximates the CSS border box (content+padding+border): horizontal margin, when an element sets margin-left/right explicitly, is baked into its box the same way padding is (see renderBlockContentBox) and is not currently subtracted back out, so Rect may include a few extra columns of margin overlap for such elements. Vertical margin is unaffected, since it is injected as separate blank lines around a box, never baked into it. This is an accepted simplification: the primary motivating use is hit-testing form controls (see docs/INTERACTIVE.md), and those essentially never set margin on input/button/textarea.
type Request ¶
type Request struct {
Width int
Height int
Rules []cssengine.Rule
ScrollOffsets map[*html.Node]int
ScrollOffsetsX map[*html.Node]int
}
Request supplies per-frame state for RenderNode.
type Result ¶
type Result struct {
Output string
Positions map[*html.Node]Rect
ScrollOffsets map[*html.Node]int
ScrollViewport map[*html.Node]Viewport
ScrollOffsetsX map[*html.Node]int
ScrollViewportX map[*html.Node]ViewportX
ContentOffsets map[*html.Node]int
ContentOffsetsX map[*html.Node]int
}
Result is the rendered output plus layout metadata needed by interactive document hosts.
type Viewport ¶
type Viewport struct {
Height int
TopOffset int
GutterCol int
GutterWidth int
CapStart bool
CapEnd bool
}
Viewport records a scroll container's visible content-area geometry. GutterCol, GutterWidth, CapStart, and CapEnd are only meaningful when GutterWidth > 0, meaning an overflow-y:scroll gutter really was reserved this frame (see block.go's hasScrollbarGutter). document.go's tryScrollCapClick uses them, combined with the element's own Rect, whose Col and Row this Viewport's offsets are relative to, same as TopOffset already is, to hit-test a click against the cap buttons' cells.
CapStart and CapEnd reflect whether that cap was drawn this frame, not just whether a ::scrollbar-cap-start or ::scrollbar-cap-end rule set content: a cap dropped for lack of room (see appendScrollbarColumn) must not be clickable.
type ViewportX ¶
type ViewportX struct {
Width int
LeftOffset int
GutterRow int
GutterHeight int
CapStart bool
CapEnd bool
}
ViewportX is Viewport's horizontal counterpart, recorded for an overflow-x:scroll|auto element with an explicit width. See block.go's hasScrollbarGutterX and docs/SCROLLING.md's horizontal-scrolling addendum.
Width and LeftOffset are the transpose of Height and TopOffset: LeftOffset is the column shift from the element's own Rect.Col to where its content starts, the same relationship colShift already has to Rect.Col elsewhere. GutterRow, GutterHeight, CapStart, and CapEnd are the transpose of GutterCol, GutterWidth, CapStart, and CapEnd. GutterRow is the row shift from Rect.Row to the gutter row, only meaningful when GutterHeight > 0, meaning a visible ::scrollbar-track-x or ::scrollbar-thumb-x row was drawn this frame. CapStart and CapEnd here mean the *left* and *right* cap, ::scrollbar-cap-start-x and ::scrollbar-cap-end-x, not top and bottom.
Source Files
¶
- attrs.go
- blankcap.go
- block.go
- box.go
- cascade.go
- color.go
- counter.go
- csstext.go
- datalist_popup.go
- defaultstylesheet.go
- doc.go
- engine.go
- flex.go
- formcontrol.go
- inline.go
- length.go
- list.go
- number.go
- outofflow.go
- overlay_box.go
- position.go
- render.go
- select_popup.go
- strip.go
- style.go
- symbols.go
- table.go
- table_collapse.go
- table_render.go
- table_separate.go
- wraptoken.go