Skip to content
boxesandgluePublic

About

HTML stuff for boxes and glue

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

283 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmlbag

Explore in Constellation

htmlbag is the HTML/CSS renderer within the boxes and glue stack. It parses CSS stylesheets, matches them against an HTML document, and turns the styled DOM into internal text and node structures (frontend.Text, node.VList, etc.) that are later shipped to PDF. bagme and the HTML mode of glu are built on it.

Multi-column page with a spanning title, rendered by htmlbag from HTML and CSS

The CSS parser and selector engine used to be the separate package github.com/boxesandglue/csshtml, now archived. Its identifiers kept their names, so csshtml.NewCSSParserWithDefaults became htmlbag.NewCSSParserWithDefaults.

Installation

go get github.com/boxesandglue/htmlbag

Documentation

The htmlbag manual describes the supported HTML elements and CSS properties, tables, floats, footnotes, cross references and the Go API.

Core pieces

  • CSS: css.go parses stylesheets (including @import, @font-face and @page), tree.go matches the rules against the DOM via cascadia and writes the computed styles onto the nodes, processhtml.go loads HTML files or chunks together with their linked stylesheets, nesting.go flattens CSS nesting.
  • CSSBuilder (cssbuilder.go): owns a frontend.Document and a CSS, parses HTML (ParseHTMLFromNode/HTMLToText), applies CSS, and builds vlists.
  • Styles: inheritablestyles.go models CSS inheritance; list markers, indents, and table handling live here and in htmltable.go.
  • Rendering: vlistbuilder.go builds vertical lists from frontend.Text; output.go ships pages via the frontend/pdfdraw backend.
  • Fonts: fonts.go loads embedded webfonts; assets live under fonts/.

Quick start

css := htmlbag.NewCSSParserWithDefaults()
_ = css.AddCSSText(`@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

Development

  • Go 1.25+. Import path: github.com/boxesandglue/htmlbag.
  • Tests: go test ./....
  • Changes in the CSS/HTML pipeline should be validated against PDF references (downstream projects rely on stable output).

Ecosystem

htmlbag is part of a broader ecosystem of PDF, typesetting and publishing technologies.

Explore the constellation →

About

HTML stuff for boxes and glue

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages