Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package render produces HTML for parsed diffs. Two modes share the same per-file structure (header + hunks); only line-level layout differs. Per-line syntax highlighting via Chroma; binary and image files get their own placeholders.

The renderer doesn't know about HTTP — callers wrap the output in `template.HTML` for the response. This keeps it usable from the commit page (S18), compare page (S20), and PR files-changed page (S22) without leaking response shape into the rendering surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(d *parse.Diff, opts Options) string

Diff renders a full Diff to HTML. Entry point for the templates. The output is one big string of HTML; for very large diffs callers can hit RenderFile instead and stream per-file.

func RenderFile

func RenderFile(f *parse.File, opts Options) string

RenderFile renders one File. Public so callers (the diff-fragment endpoint) can re-render a single file on demand.

Types

type Mode

type Mode string

Mode picks unified or split rendering.

const (
	ModeUnified Mode = "unified"
	ModeSplit   Mode = "split"
)

type Options

type Options struct {
	Mode             Mode
	HighlightCap     int
	PerFileLineCap   int // collapse files with > this many changed lines (0 = 1000 default)
	PerFileBytesCap  int // collapse files larger than this (0 = 500 KiB)
	WholeDiffFileCap int // truncate the whole-diff after this many files (0 = 100)
}

Options tunes a render. HighlightCap caps per-file highlight cost; past it the renderer falls back to plain `<pre>`. Zero uses the 200 KiB default from the spec.

Jump to

Keyboard shortcuts

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