markup

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package markup turns the Markdown of nodes and proofs into HTML (spec 06.2).

It adds these things to CommonMark and GFM:

  • [[slug]], [owner/slug], [[slug#anchor]] and [[slug|text]] link to a node, an area or a card, and [[al:slug]] links to a page of the algorithm site;
  • [^n] cites the source n of the front matter, and {rule:...}, {std:...} and {since:...} are inline references;
  • a block quote that starts with [!note], [!warning], [!pitfall], [!history], [!tip] or [!since v="..."] is a callout;
  • $...$ is inline math, and $$...$$ or a ```math block is display math, which KaTeX renders at build time;
  • a ```pseudo block is pseudocode with stable line ids (spec 06.4);
  • other fenced blocks are highlighted with Chroma at build time.

Index

Constants

This section is empty.

Variables

View Source
var CalloutKinds = map[string]string{"note": "Note", "warning": "Warning", "pitfall": "Pitfall", "history": "History", "since": "Since", "tip": "Tip"}

CalloutKinds are the kinds of callout and their titles.

Functions

func Highlight

func Highlight(code, lang string) string

Highlight returns highlighted HTML for code in a language. It uses CSS classes, so that the light and the dark themes can share the markup.

func HighlightCSS

func HighlightCSS() string

HighlightCSS returns the CSS of the light and the dark code themes.

func Pseudo

func Pseudo(w util.BufWriter, code string) []string

Pseudo writes a pseudocode block (spec 06.4). A line that starts with an id such as L3 is a step. A line with no id is a header, such as "MERGE-SORT(A, p, r)". The text after ▷ is a comment. Words in upper case are calls, and they render in small capitals. It returns the ids in order.

Types

type Heading

type Heading struct {
	Level int
	ID    string
	Text  string
}

Heading is one entry of the table of contents.

type MathFunc

type MathFunc func(tex string, display bool) (string, error)

MathFunc renders TeX to HTML. display selects display math.

type Options

type Options struct {
	Resolve Resolver
	// Math renders formulas at build time. When it is nil, a formula is left as TeX between \( \) or \[ \], for a renderer in the browser.
	Math MathFunc
	// Sources is the number of sources in the front matter. A citation [^n] links to the source n, from 1 to Sources.
	Sources int
	// Since gives the version that added a feature, for {since:<slug>}.
	Since func(slug string) (string, bool)
	// RuleURL gives the URL of a rule of a language reference, for {rule:<owner>/<id>}. An empty URL gives no link.
	RuleURL func(owner, id string) string
}

Options are the inputs of RenderWith.

type Resolver

type Resolver func(slug string) (name, url string, ok bool)

Resolver finds the name and the URL of a node by its slug.

type Result

type Result struct {
	HTML        string
	TOC         []Heading
	Missing     []string // slugs of [[links]] that do not resolve
	LineIDs     []string // the line ids of the pseudocode blocks, in order
	Sections    []string // the texts of the level 2 headings, in order
	MathErrors  []string // the formulas that do not render (rule W07)
	Cites       []int    // the numbers of the citations [^n], in order
	BadCites    []int    // the citations with no source in the front matter (rule G02)
	BadCallouts []string // the callouts of a kind that is not known
}

Result is the output of Render.

func Render

func Render(src string, resolve Resolver) (Result, error)

Render renders Markdown to HTML.

func RenderWith

func RenderWith(src string, opt Options) (Result, error)

RenderWith renders Markdown to HTML with the options.

Jump to

Keyboard shortcuts

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