htmlbag is the HTML/CSS renderer within the Boxes and Glue stack. It turns HTML fragments plus CSS into internal text and node structures (frontend.Text, node.VList, etc.) that are later shipped to PDF.
CSSBuilder(cssbuilder.go): owns afrontend.Documentandcsshtml.CSS, parses HTML (ParseHTMLFromNode/HTMLToText), applies CSS, and builds vlists.- Styles:
inheritablestyles.gomodels CSS inheritance; list markers, indents, and table handling live here and inhtmltable.go. - Rendering:
vlistbuilder.gobuilds vertical lists fromfrontend.Text;output.goships pages via the frontend/pdfdraw backend. - Fonts:
fonts.goloads embedded webfonts; assets live underfonts/.
css := csshtml.New()
_ = css.ParseString(`@page { size: A4; } body { font-family: serif; }`)
doc := frontend.NewDocument()
cb, _ := htmlbag.New(doc, css)
te, _ := cb.HTMLToText(`<p><b>Hello</b> world</p>`)
vl, _ := cb.CreateVlist(te, bag.MustSP("15cm"))
doc.Doc.OutputAt(0, 0, vl) // example: output directly- Go 1.22+. Import path:
github.com/boxesandglue/htmlbag. - Tests/lint: no test at the moment.
- Changes in the CSS/HTML pipeline should be validated against PDF references (downstream projects rely on stable output).