Documentation
¶
Overview ¶
Package extensions provides custom goldmark extensions for enhanced markdown syntax.
Package extensions provides custom goldmark extensions for enhanced markdown syntax.
Package extensions provides custom goldmark extensions for enhanced markdown syntax.
Package extensions provides custom goldmark extensions for enhanced markdown syntax.
Package extensions provides custom goldmark extensions for enhanced markdown syntax.
Index ¶
- Variables
- func NewAdmonitionExtension() goldmark.Extender
- func NewBadgeExtension() goldmark.Extender
- func NewHighlightExtension() goldmark.Extender
- func NewMutedExtension() goldmark.Extender
- func NewStrictLinkifyExtension() goldmark.Extender
- type Admonition
- type AdmonitionType
- type Badge
- type Highlight
- type Muted
Constants ¶
This section is empty.
Variables ¶
var AdmonitionKind = ast.NewNodeKind("Admonition")
AdmonitionKind is the kind of Admonition AST node.
var BadgeKind = ast.NewNodeKind("Badge")
BadgeKind is the kind of Badge AST node.
var HighlightKind = ast.NewNodeKind("Highlight")
HighlightKind is the kind of Highlight AST node.
var MutedKind = ast.NewNodeKind("Muted")
MutedKind is the kind of Muted AST node.
var StrictEmailRegexp = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`)
StrictEmailRegexp matches valid email addresses but excludes package references. This uses a stricter pattern than goldmark's default that requires:
- Local part: letters, digits, and common email special chars (._%+-)
- Domain: letters, digits, hyphens, and dots
- TLD: at least 2 letters (not numbers)
The TLD requirement is what prevents package references like foo/bar@1.0.0 from matching: ".0" is numeric and doesn't match [a-zA-Z]{2,}.
Matches: user@example.com, support@company.org, user+tag@mail.co. Rejects: foo/bar@1.0.0, replicatedhq/replicated@0.124.1, user@localhost.
Functions ¶
func NewAdmonitionExtension ¶
NewAdmonitionExtension creates a new admonition extension.
func NewBadgeExtension ¶
NewBadgeExtension creates a new badge extension.
func NewHighlightExtension ¶
NewHighlightExtension creates a new highlight extension.
func NewMutedExtension ¶
NewMutedExtension creates a new muted extension.
func NewStrictLinkifyExtension ¶
NewStrictLinkifyExtension creates an extension that prevents package references like foo/bar@1.0.0 from being rendered as mailto: links.
Since glamour uses GFM which includes Linkify with a permissive email regex, this extension adds an AST transformer that runs after parsing and converts auto-linked package references back to plain text.
It identifies package references by:
- Presence of "/" in the URL (emails cannot contain slashes)
- URL not matching a strict email pattern (TLD must be letters)
Types ¶
type Admonition ¶
type Admonition struct {
ast.BaseBlock
AdmonitionType AdmonitionType
AdmonitionContent string
}
Admonition represents a GitHub-style alert block using > [!TYPE] syntax.
func NewAdmonition ¶
func NewAdmonition(admonitionType AdmonitionType, content string) *Admonition
NewAdmonition creates a new Admonition node.
func (*Admonition) Dump ¶
func (n *Admonition) Dump(source []byte, level int)
Dump dumps the node for debugging.
func (*Admonition) Kind ¶
func (n *Admonition) Kind() ast.NodeKind
Kind returns the kind of this node.
type AdmonitionType ¶
type AdmonitionType string
AdmonitionType represents the type of admonition.
const ( AdmonitionNote AdmonitionType = "NOTE" AdmonitionWarning AdmonitionType = "WARNING" AdmonitionTip AdmonitionType = "TIP" AdmonitionImportant AdmonitionType = "IMPORTANT" AdmonitionCaution AdmonitionType = "CAUTION" )
type Badge ¶
type Badge struct {
ast.BaseInline
BadgeVariant string // e.g., "warning", "success", "error", "info", or empty for default
BadgeText string // The badge text content
}
Badge represents a styled badge using [!BADGE text] or [!BADGE:variant text] syntax.
type Highlight ¶
type Highlight struct {
ast.BaseInline
}
Highlight represents highlighted text using ==text== syntax.