Documentation
¶
Overview ¶
Package views parses fenced code blocks and connects them to custom view renderers.
Blocks preserves source order and normalizes CRLF line endings. Hash names an artifact by its language and source, while Path gives its relay URL. Figure emits accessible markup with the rendered image and an inline source fallback. Renderer maps each lowercased language to the first registered view that supports it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var HashPattern = regexp.MustCompile(`^[0-9a-f]{64}$`)
HashPattern is the shape of a block hash in a path.
var NamePattern = regexp.MustCompile(`^[a-z0-9-]{1,32}$`)
NamePattern is the shape of a custom view name.
Functions ¶
func ClosesFence ¶
ClosesFence reports whether a line closes the fence opened with marker: a run of at least as many of the same character and nothing else.
func Figure ¶
Figure is the markup for a block a custom view renders. The image remains transparent and follows the page color scheme, while the native details disclosure keeps the source available without requiring script.
func Hash ¶
Hash names a block: the SHA-256 of the language, a newline and the source, in hex. The same block in two texts has the same hash.
Types ¶
type Block ¶
type Block struct {
Index int `json:"index"`
Lang string `json:"lang"`
Source string `json:"source"`
}
Block is one fenced code block. Index counts every fenced block in the text from zero, whether or not it carries a language.
type Renderer ¶
Renderer decides how a fenced block is shown: the view that renders the language, if any. Languages maps a lowercase language to a view name.
func NewRenderer ¶
NewRenderer indexes views by the languages they render. The first view that names a language renders it.