render

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package render turns untrusted author markdown into safe HTML. Hostile READMEs are a primary XSS vector, so this package is the only path by which user content reaches a browser, and it is deliberately strict: goldmark with raw HTML disabled, then a bluemonday allowlist, then invisible/bidi Unicode rendered as visible placeholders.

Index

Constants

View Source
const MaxInputBytes = 1 << 20

MaxInputBytes caps rendering input (the instruction-file quota is 1 MB; give README the same ceiling).

Variables

This section is empty.

Functions

func RevealInvisible

func RevealInvisible(safeHTML string) string

RevealInvisible replaces invisible characters in already-sanitized HTML with visible, escaped placeholders wrapped in a marker span. Text outside tags only — attribute values are left alone (they are already policy- filtered, and rewriting inside them could corrupt URLs).

Types

type Options

type Options struct {
	// ImageProxy maps an absolute http(s) image URL to a same-origin proxy
	// URL. nil keeps the
	// placeholder; a returned false keeps the placeholder for that URL.
	ImageProxy func(dest string) (string, bool)
}

Options tunes a Renderer. The zero value is the strict default: images become placeholders.

type Renderer

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

Renderer converts markdown to sanitized HTML. Safe for concurrent use.

func New

func New() *Renderer

New builds the renderer with the strict default policy.

func NewWithOptions

func NewWithOptions(opts Options) *Renderer

NewWithOptions builds a Renderer with the given options.

func (*Renderer) Markdown

func (r *Renderer) Markdown(src []byte) (string, error)

Markdown renders markdown to sanitized HTML with invisible characters made visible. The output is a fragment (no <html>/<body>) intended for a container element with the `readme` class.

func (*Renderer) PlainText

func (r *Renderer) PlainText(src []byte) string

PlainText renders markdown to plain text (search snippets, meta descriptions): tags stripped, invisible characters removed outright.

Jump to

Keyboard shortcuts

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