How kozea/weasyprint works
WeasyPrint is a Python HTML/CSS rendering engine that produces paginated PDF documents. The principal workflow is to accept HTML and stylesheets, build styled formatting boxes, lay them out across pages, draw their content, and export a PDF. Supporting branches handle external resources, images and SVG, text and fonts, and PDF metadata and accessibility features. The source index confirms several module dependencies; some orchestration details and unsampled PDF stages are shown only as documented or unverified relationships.
Main entry points: block.py Block and page flow · html.py HTML handling · css/__init__.py Stylesheet cascade · draw/__init__.py Page drawing
Components 22
Input and resources
- HTML handling
weasyprint/html.py - URL fetching
weasyprint/urls.py
CSS processing
- Stylesheet cascade
weasyprint/css/__init__.py - CSS tokens
weasyprint/css/tokens.py - Property validation
weasyprint/css/validation/properties.py - Computed values
weasyprint/css/computed_values.py
Formatting and layout
- Formatting boxes
weasyprint/formatting_structure/boxes.py - Box construction
weasyprint/formatting_structure/build.py - Block and page flow
weasyprint/layout/block.py - Grid layout
weasyprint/layout/grid.py - Table layout
weasyprint/layout/table.py - Positioned layout
weasyprint/layout/absolute.py - Page layout
weasyprint/layout/page.py
Drawing and assets
- Page drawing
weasyprint/draw/__init__.py - Image decoding
weasyprint/images.py - SVG rendering
weasyprint/svg/__init__.py - Font handling
weasyprint/text/fonts.py
PDF output
- Document rendering
weasyprint/document.py - PDF writing
weasyprint/pdf/__init__.py - PDF metadata
weasyprint/pdf/metadata.py - PDF accessibility
weasyprint/pdf/pdfua.py
Other components
- Web developer
Connections 24
- Web developer → HTML handling: provides HTML
- HTML handling → URL fetching: resolves resources
weasyprint/html.py - HTML handling → Stylesheet cascade: finds stylesheets
weasyprint/css/__init__.py - Stylesheet cascade → CSS tokens: tokenizes CSS
weasyprint/css/__init__.py - Stylesheet cascade → Property validation: validates declarations
weasyprint/css/__init__.py - Stylesheet cascade → Computed values: computes styles
weasyprint/css/__init__.py - HTML handling → Formatting boxes: handles elements
weasyprint/html.py - Box construction → HTML handling: reads elements
weasyprint/formatting_structure/build.py - Box construction → Formatting boxes: builds boxes
weasyprint/formatting_structure/build.py - Block and page flow → Formatting boxes: lays out boxes
weasyprint/layout/block.py - Block and page flow → Grid layout: dispatches grid
weasyprint/layout/block.py - Block and page flow → Table layout: dispatches tables
weasyprint/layout/block.py - Block and page flow → Positioned layout: lays out positioned boxes
weasyprint/layout/block.py - Grid layout → Block and page flow: lays out children
weasyprint/layout/grid.py - Grid layout → Table layout: uses table layout
weasyprint/layout/grid.py - Page layout → Block and page flow: paginates content
- Page drawing → Formatting boxes: draws boxes
weasyprint/draw/__init__.py - Page drawing → Image decoding: draws images
weasyprint/draw/__init__.py - Image decoding → SVG rendering: renders SVG
weasyprint/images.py - Page drawing → Font handling: draws text
- Document rendering → Page drawing: renders pages
- Document rendering → PDF writing: exports PDF
- PDF writing → PDF metadata: writes metadata
- PDF writing → PDF accessibility: supports accessibility