renderer

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

anchor_namespace.go makes heading anchors unique across a whole book.

Heading ids are minted per document, so they are only unique within one chapter. That is fine for the multi-page site, where each chapter is its own page, but the standalone HTML concatenates every chapter into one document: the ids collide, the browser resolves each "#examples" link to whichever chapter happens to come first, and the resulting page is invalid HTML.

mdPress's own manual produced 195 duplicated ids, "notes" appearing twelve times — so eleven of every twelve sidebar links under that name went to the wrong chapter.

Package renderer assembles individual parts into the final HTML document. It uses html/template for safe HTML rendering, combining theme CSS, cover, TOC, and chapter content.

html_standalone.go renders a self-contained single-page HTML document. The output embeds CSS and JavaScript and implements a GitBook-style three-column layout: left sidebar (global TOC), center content area, right in-page TOC.

Additional features: dark/light/system theme toggle, code copy button with language label, callout boxes, full-text search (⌘K), prev/next navigation, image lightbox, Mermaid diagrams, and KaTeX math formulas.

margins.go resolves the two places a book can set page margins.

book.yaml has both `style.margin` (millimeters, as numbers) and `output.margin_top/bottom/left/right` (CSS lengths, as strings). Only the former reached the PDF: the generator asks Chrome to honor the document's own @page rule, and @page was built from style.margin alone. The output.* keys were parsed, validated, and documented in four places as the way to fix cramped output — and did nothing at all.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChapterHTML

type ChapterHTML struct {
	Title    string       // Chapter title
	ID       string       // Chapter unique identifier
	Content  string       // Chapter HTML content
	Depth    int          // Chapter depth in book structure (0-based)
	Headings []NavHeading // Heading tree within the chapter, used for navigation
}

ChapterHTML represents the HTML content of a single chapter.

type HTMLRenderer

type HTMLRenderer struct {
	// contains filtered or unexported fields
}

HTMLRenderer assembles individual parts into the final HTML document.

func NewHTMLRenderer

func NewHTMLRenderer(cfg *config.BookConfig, thm *theme.Theme) (*HTMLRenderer, error)

NewHTMLRenderer creates a new HTML renderer for assembling book content.

func (*HTMLRenderer) Render

func (r *HTMLRenderer) Render(parts *RenderParts) (string, error)

Render assembles all parts into a complete HTML document.

type NavHeading struct {
	Title    string
	ID       string
	Children []NavHeading
}

NavHeading represents a navigation heading tree within a chapter.

type RenderParts

type RenderParts struct {
	CoverHTML    string        // Cover page HTML
	TOCHTML      string        // Table of contents HTML
	ChaptersHTML []ChapterHTML // All chapters
	CustomCSS    string        // Custom CSS
}

RenderParts contains the individual parts to be rendered.

type StandaloneHTMLRenderer

type StandaloneHTMLRenderer struct {
	// contains filtered or unexported fields
}

StandaloneHTMLRenderer renders a self-contained single-page HTML document.

func NewStandaloneHTMLRenderer

func NewStandaloneHTMLRenderer(cfg *config.BookConfig, thm *theme.Theme) (*StandaloneHTMLRenderer, error)

NewStandaloneHTMLRenderer creates a single-page HTML renderer.

func (*StandaloneHTMLRenderer) Render

func (r *StandaloneHTMLRenderer) Render(parts *RenderParts) (string, error)

Render renders the complete single-page HTML document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL