markup

package
v0.1.8 Latest Latest
Warning

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

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

Documentation

Overview

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

It adds four things to CommonMark and GFM:

  • [[slug]] and [[slug|text]] link to a node;
  • $...$ is inline math and a ```math block is display math, which KaTeX renders in the browser;
  • 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

This section is empty.

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
}

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)
}

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