Callbacks
htmlbag exposes two callback hooks for embedders that want to observe or react to the layout pipeline.
ElementCallback
type ElementEvent struct {
TagName string
TextContent string
VList *node.VList
}
type ElementCallbackFunc func(event ElementEvent)Set CSSBuilder.ElementCallback to a function that runs after each
block-level element’s VList is built. Used for collecting headings,
detecting figure captions, building a table of contents, or
debugging. Fires before page-output, so the Page field of any
heading reference will not yet be valid here.
PageInitCallback
type PageInitCallbackFunc func()Set CSSBuilder.PageInitCallback to a function that runs once per
new page, just after the page is initialised but before any content
is placed. Use it to draw page-level chrome (running headers,
footers, page numbers, watermarks). Read the active page geometry
from cb.frontend.Doc.CurrentPage.Userdata[PageDimensionsKey].
Headings
Independent of the callback, CSSBuilder.Headings accumulates a
[]HeadingEntry for every <h1>–<h6> encountered. The Page
field is filled at output time, so wait until OutputPages* returns
before reading the slice for TOC generation.