MCPcopy Index your code
hub / github.com/benoitkugler/webrender

github.com/benoitkugler/webrender @v0.0.14

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.14 ↗ · + Follow
5,149 symbols 16,299 edges 166 files 1,209 documented · 23% updated 3mo ago★ 444 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Web render

This module implements a static renderer for the HTML, CSS and SVG formats.

It consists for the main part of a Golang port of the awesome Weasyprint python Html to Pdf library.

The project is usable, but you should use it carefully in production; breaking changes may also be committed on the fly.

Scope

The main goal of this module is to process HTML or SVG inputs into laid out documents, ready to be paint, and to be compatible with various output formats (like raster images or PDF files). To do so, this module uses an abstraction of the output, whose implementation must be provided by an higher level package.

Outline of the module

From the lower level to the higher level, this module has the following structure :

  • the css package provides a CSS parser, with property validation and a CSS selector engine (css/selector).

  • the svg package implements a SVG parser and renderer, supporting CSS styling.

  • the html package implements an HTML renderer

  • the backend package defines the interfaces which must be implemented by output targets.

The main entry points are the html/document package for HTML rendering and the svg package if you only need SVG support.

HTML to PDF: an overview

The html package implements a static HTML renderer, which works by :

  • parsing the HTML input and fetching CSS files, and cascading the styles. This is implemented in the html/tree package

  • building a tree of boxes from the HTML structure (package html/boxes)

  • laying out this tree, that is attributing position and dimensions to the boxes, and performing line, paragraph and page breaks (package html/layout)

  • drawing the laid out tree to an output. Contrary to the Python library, this step is here performed on an abstract output, which must implement the backend.Document interface. This means than the core layout logic could easily be reused for other purposes, such as visualizing html document on a GUI application, or targetting other output file formats.

Extension points exported contracts — how you extend this code

BlockContainerBoxITF (Interface)
A box that contains only block-level boxes or only line boxes. A box that either contains only block-level boxes or esta [6 …
html/boxes/stubs.go
InnerContent (Interface)
guard for possible content properties [6 implementers]
css/properties/types.go
Token (Interface)
Token is a CSS component value, used to build declarations [14 implementers]
css/parser/tokenizer.go
Matcher (Interface)
Matcher is the interface for basic selector functionality. Match returns whether a selector matches n. [20 implementers]
css/selector/selector.go
Image (Interface)
Image groups all possible image format, like raster image, svg, or gradients. [2 implementers]
backend/graphics.go
Image (Interface)
Image is the common interface for supported image formats, such as gradients, SVG, or JPEG, PNG, etc... [2 implementers]
images/images.go
TextLayoutContext (Interface)
(no doc) [4 implementers]
text/text.go
FontConfiguration (Interface)
FontConfiguration holds information about the available fonts on the system. It is used for text layout at various steps [2 …
text/fonts.go

Core symbols most depended-on inside this repo

Box
called by 3701
html/boxes/boxes.go
V
called by 755
css/properties/float.go
AssertNoLogs
called by 576
utils/testutils/logs.go
Key
called by 385
css/properties/main.go
ToValue
called by 180
css/properties/utils.go
Get
called by 177
html/tree/style.go
Get
called by 177
html/tree/style.go
String
called by 173
css/selector/selector.go

Shape

Method 2,715
Function 1,909
Struct 315
TypeAlias 99
Interface 76
Class 32
FuncType 3

Languages

Go98%
Python2%

Modules by API surface

css/properties/props_gen.go709 symbols
html/tree/accessors.go708 symbols
css/properties/types.go223 symbols
html/boxes/stubs.go220 symbols
css/validation/validation.go171 symbols
css/parser/tokenizer.go121 symbols
macros/source_box.py94 symbols
html/layout/tables_test.go86 symbols
html/boxes/boxes_tree.go80 symbols
html/boxes/boxes.go73 symbols
css/properties/utils.go66 symbols
css/selector/selector.go63 symbols

For agents

$ claude mcp add webrender \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact