Documentation
¶
Overview ¶
Package markdown is a small, dependency-free Markdown renderer.
It parses a constrained subset of Markdown, enough for project docs and website content, and emits HTML directly. It is not CommonMark-strict; the goal is predictable output for the inputs we actually write, not edge-case fidelity.
Supported block elements:
- ATX headings (#, ##, … up to ######)
- Paragraphs
- Fenced code blocks (three or more ` or ~, with an optional info string: a language, then options this package passes through in data-meta)
- Unordered lists (-, *, +)
- Ordered lists (1., 2., …)
- Blockquotes (>)
- Horizontal rules (---, ***, ___)
- GFM-style tables (| col | col |)
- YAML-ish frontmatter (--- key: value --- at the top of the document)
Supported inline elements:
- Bold (**…** or __…__)
- Italic (*…* or _…_)
- Inline code (`…`)
- Links ([text](url)) and images ()
HTML in source is escaped, never passed through. Code blocks and inline code are rendered without syntax highlighting; callers can post-process if they want highlighted output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderHTML ¶
RenderHTML is a convenience wrapper that returns just the HTML body.
func Unquote ¶ added in v0.86.0
Unquote strips one layer of matching surrounding quotes (double or single) from a YAML frontmatter scalar, returning s unchanged when it is not quoted (or is too short to be). Exported for the skill frontmatter parser, which formerly carried a byte-identical trimYAMLQuotes copy.
Types ¶
type Document ¶
type Document struct {
// Frontmatter holds key/value pairs from a leading `--- ... ---` block.
// Values are kept as raw strings; callers do their own typing.
Frontmatter map[string]string
// HTML is the rendered body.
HTML render.HTML
// Title is the text of the first H1 in the document if present, otherwise
// the value of the `title` frontmatter key. Useful for setting <title>.
Title string
}
Document is the result of parsing a Markdown source.
type FenceInfo ¶ added in v0.83.0
type FenceInfo struct {
// Lang is the first whitespace-delimited token, the language name
// ("go", "bash"). Empty for a fence with no info string.
Lang string
// Meta is everything after Lang, verbatim and trimmed: `title="main.go"`,
// `{1,3-5}`, `showLineNumbers`. The renderer decides what those mean; this
// package only carries them through, in the <code> tag's data-meta
// attribute. Empty for a plain fence.
Meta string
}
FenceInfo is a parsed fence info string, the text after a fence's opening run.
func ParseFenceInfo ¶ added in v0.83.0
ParseFenceInfo splits a fence info string into its language and its options.