HTML mode
glu can convert HTML files directly to PDF. Unlike Markdown mode, no default stylesheet is applied — all styling comes from <style> tags, <link> stylesheets, inline styles, or the --css flag.
glu page.html # → page.pdfglu detects the mode by the file extension: .html or .htm for HTML mode.
Features
HTML mode supports:
- Full HTML document structure (
<!DOCTYPE html>,<html>,<head>,<body>) <style>tags in<head>(including@pagerules)<link rel="stylesheet">for external CSS files- CSS class and element selectors
- Borders, padding, background colors, border-radius
- Tables, lists, headings, paragraphs
- Inline styles
Example
<!DOCTYPE html>
<html>
<head>
<style>
@page { size: a5; margin: 2cm; }
body { font-family: serif; font-size: 10pt; }
h1 { color: #336699; font-size: 20pt; }
.highlight {
border: 1pt solid #336699;
padding: 6pt;
border-radius: 3pt;
}
</style>
</head>
<body>
<h1>Report</h1>
<p>This PDF was generated from an HTML file.</p>
<div class="highlight">
<p>This section has a <strong>blue border</strong>.</p>
</div>
</body>
</html>Run with:
glu report.html # → report.pdfCompanion Lua file
Like Markdown mode, a companion Lua file is loaded automatically if it exists:
page.html ← your document
page.lua ← loaded automatically (if present)The companion file can register callbacks for page backgrounds, overlays, or element processing.
local frontend = require("glu.frontend")
frontend.add_callback("page_init", "bg", function(doc, page, pagenum, pageinfo)
-- draw page background
end)Custom CSS via command line
Additional CSS can be loaded with the --css flag:
glu --css extra.css page.htmlCSS from the command line is applied after stylesheets from <link> and <style> tags.
Page counters and auxiliary files
HTML mode supports the same page counters and auxiliary file mechanism as Markdown mode. Use counter(page) and counter(pages) in @page margin boxes:
<style>
@page {
@bottom-center {
content: counter(page) " / " counter(pages);
font-size: 9pt;
}
}
</style>See Markdown mode — Page margin boxes and counters for the full documentation.
Leaders (CSS)
Leaders create repeating dot patterns that fill available space — commonly used in table-of-contents entries. Use the CSS content: leader('.') property (from the CSS Generated Content for Paged Media specification) on an empty inline element:
<style>
.toc-entry { margin-top: 2pt; margin-bottom: 2pt; }
</style>
<p class="toc-entry">
Chapter 1<span style="content: leader('.')"></span>5
</p>
<p class="toc-entry">
Chapter 2<span style="content: leader('.')"></span>12
</p>This produces:
Chapter 1 . . . . . . . . . . . . 5
Chapter 2 . . . . . . . . . . . . 12The dots are vertically aligned across lines (global grid alignment). The leader pattern can be any string — leader('.') for dots, leader('_') for underscores, etc.
The <span> must be empty (no child content). The content property is parsed from the inline style attribute.
Differences from Markdown mode
| Feature | Markdown mode | HTML mode |
|---|---|---|
| Default stylesheet | Built-in (serif, A4, margins) | None — you provide all CSS |
| Frontmatter | YAML (title, author, etc.) |
Not supported |
| Lua blocks | ```{lua} |
Not supported (use companion .lua) |
| Inline expressions | {= expr =} |
Not supported |
| Go templates | --template flag |
Not supported |
@page rules |
Via frontmatter or CSS file | Via <style> or <link> |
HTML mode is ideal when you need full control over the document structure and styling, or when converting existing HTML content to PDF.