Documentation
¶
Overview ¶
Package mdparser implements application.DocumentParser. It is the ONLY package in matlatl that imports goldmark (ADR 0002): markdown parsing and the third-party AST are quarantined here, so the domain stays pure.
It turns markdown bytes into a pure-domain corpus.Document: typed front matter (YAML/TOML), a nested Section tree, and the standard-markdown raw references (relative links, anchors, images, external links). Wikilink extraction is P2.
Slug dialect: the parser is configured with parser.WithAutoHeadingID(), whose GitHub-compatible algorithm is the canonical, validated slug dialect of ADR 0006. The slug stored on each Section is exactly goldmark's auto heading id.
Index ¶
Constants ¶
const DefaultMaxFrontMatterBytes = 64 << 10 // 64 KiB
DefaultMaxFrontMatterBytes caps the size of the leading front-matter block that will be decoded, guarding against YAML "billion laughs" / deep-alias bombs (ADR 0003). A block larger than this is stripped and the document degrades to "no front matter" plus a notice.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxFrontMatterBytes caps the decodable front-matter block size.
MaxFrontMatterBytes int
}
Config tunes a Parser. The zero value is valid; New fills safe defaults.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory mints Parsers backed by ONE shared, pre-built goldmark.Markdown. It implements application.DocumentParserFactory so the pipeline can request a parser per worker in P6 without re-constructing goldmark per worker.
func NewFactory ¶
NewFactory returns a parser Factory with the given config (defaults filled). The single canonical goldmark.Markdown is built and WARMED here, so every worker shares one immutable parser (see newGoldmark for the safety argument).
func (*Factory) Clone ¶
func (f *Factory) Clone() application.DocumentParser
Clone returns a DocumentParser safe to use on its own goroutine. It does NOT rebuild goldmark: each clone is a view over the Factory's single shared, already-warmed goldmark.Markdown (concurrency-safe — see newGoldmark), with per-call state isolated to the parser.Context allocated in ParseBytes.
func (*Factory) New ¶
func (f *Factory) New() application.DocumentParser
New returns a DocumentParser that shares the Factory's goldmark instance.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses markdown into corpus.Documents.
Concurrency (P6): a Parser is a thin VIEW over a single, shared goldmark.Markdown built once at factory time (see newGoldmark / NewFactory). Each ParseBytes call allocates its own parser.Context via parser.NewContext() — that Context (which goldmark threads front matter and auto-heading IDs through) is the ONLY per-call mutable state. The shared goldmark parser itself is safe for concurrent Parse calls once warmed: see the verification note on newGoldmark. So Factory.New/Clone hand each worker a Parser sharing the same goldmark.Markdown, and fan-out parsing is data-race-free without re-building (and re-registering the inline parser/extension on) goldmark per worker.
func New ¶
New returns a Parser owning its own freshly-built goldmark.Markdown. Prefer the Factory for fan-out parsing (it shares one warmed instance across workers); this standalone constructor is kept for direct, single-parser use (tests, the sequential fast path) and remains valid because each Parser still allocates a per-call parser.Context.
func (*Parser) Parse ¶
func (p *Parser) Parse(ctx context.Context, file application.ScannedFile) (*corpus.Document, error)
Parse reads the scanned file from disk and parses it. The file is assumed to already satisfy the scanner's size cap (ADR 0003). Reading is in-root because the scanner derived the path.
func (*Parser) ParseBytes ¶
func (p *Parser) ParseBytes(ctx context.Context, id identity.DocumentID, src []byte) (*corpus.Document, error)
ParseBytes parses raw markdown bytes into a Document with the given identity. It is the testable core of Parse (no filesystem). It never fails on malformed front matter — that degrades to "no front matter".