Documentation
¶
Overview ¶
Package parser implements the Markdown processing pipeline for kwelea.
The two exported entry points are:
Parse converts a Markdown source file into rendered HTML, an in-page table-of-contents, and the plain-text H1 title (if present). It runs the full goldmark pipeline including syntax highlighting, admonitions, and D2 diagram rendering.
ChromaCSS generates a combined Chroma stylesheet containing both a light-mode and a dark-mode rule set, written once per build to assets/chroma.css in the output directory.
Markdown extensions provided by this package:
Admonitions: ::: info / ::: tip / ::: warning / ::: danger / ::: details blocks rendered as styled <div> or <details> elements.
D2 diagrams: fenced code blocks with language "d2" are compiled to inline SVG pairs (light + dark) using the D2 Go library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Admonitions goldmark.Extender = &admonitionsExtension{}
Admonitions is the goldmark.Extender that adds ::: container block support.
var KindAdmonition = goldmarkast.NewNodeKind("Admonition")
KindAdmonition is the goldmark AST node kind for ::: container blocks.
var KindD2 = goldmarkast.NewNodeKind("D2Diagram")
KindD2 is the goldmark AST node kind for rendered D2 diagrams.
Functions ¶
func ChromaCSS ¶
func ChromaCSS(themeCfg config.ThemeConfig) (string, error)
ChromaCSS generates a combined Chroma syntax-highlighting CSS string for both the light and dark themes specified in themeCfg.
The light theme uses standard .chroma selectors. Dark-theme rules are prefixed with [data-theme="dark"] so they activate only when that attribute is set on <html>, matching the toggle logic in the template.
func NewD2Extension ¶
NewD2Extension returns a goldmark.Extender that intercepts ```d2 fenced code blocks at AST-transform time and replaces them with pre-rendered dual-theme inline SVG.
func Parse ¶
func Parse(filePath string, src []byte, themeCfg config.ThemeConfig) (template.HTML, []nav.TocItem, string, error)
Parse processes a Markdown source file and returns the rendered HTML body, a table of contents extracted from h2/h3 headings, the plain text of the first H1 heading (empty string if absent), and any error.
The first H1 heading is stripped from the AST before rendering so that it does not appear in the HTML body — the page template renders the title from Page.Title, avoiding a duplicate. The extracted text is returned so the builder can use it as a Page.Title fallback when frontmatter provides no title.
filePath is used for error messages only. themeCfg selects the Chroma style names written into CSS classes (see ChromaCSS for the matching stylesheet).
Types ¶
type AdmonitionNode ¶
type AdmonitionNode struct {
goldmarkast.BaseBlock
AdmonitionType string // "info" | "tip" | "warning" | "danger" | "details"
Title string // for details: the <summary> text; otherwise empty
}
AdmonitionNode is an AST block node wrapping a ::: container block. Its children are the parsed Markdown contents of the block body.
func NewAdmonitionNode ¶
func NewAdmonitionNode(admonType, title string) *AdmonitionNode
NewAdmonitionNode allocates an AdmonitionNode with the given type and title.
func (*AdmonitionNode) Dump ¶
func (n *AdmonitionNode) Dump(source []byte, level int)
Dump writes a debug representation of the node to standard output, satisfying the goldmark ast.Node interface.
func (*AdmonitionNode) Kind ¶
func (n *AdmonitionNode) Kind() goldmarkast.NodeKind
Kind returns KindAdmonition, satisfying the goldmark ast.Node interface.
type D2Node ¶
type D2Node struct {
goldmarkast.BaseBlock
SVG []byte // rendered HTML: <div class="d2-diagram"><div class="d2-light">…</div><div class="d2-dark">…</div></div>
}
D2Node is an AST block node that holds pre-rendered SVG HTML for a D2 diagram. It replaces FencedCodeBlock nodes with language "d2" during the AST transform pass, before goldmark-highlighting processes fenced blocks.
func (*D2Node) Dump ¶
Dump writes a debug representation of the node to standard output, satisfying the goldmark ast.Node interface.
func (*D2Node) Kind ¶
func (n *D2Node) Kind() goldmarkast.NodeKind
Kind returns KindD2, satisfying the goldmark ast.Node interface.