markdown

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package markdown parses *.md / *.markdown files into heading-level SymbolSpans so docs/ADR content becomes searchable alongside source code.

Strategy: line-based scan, no external dependency. Why direct rather than goldmark?

  • The transformation we need ("split at ATX headings, keep body including code fences") is ~80 LOC and easier to reason about than walking an AST node graph.
  • go.mod stays small; the user-global security rule asks us to justify every new dependency. A heading splitter is well below that bar.
  • Edge cases we DO need to handle (code-fence-internal hashes that look like headings, setext-style underlined headings) are local enough that line-scanning is precise.

Output contract:

  • Each ATX heading (`#`, `##`, ..., `######`) starts a SymbolSpan.
  • SymbolSpan.Text covers the heading line through the line BEFORE the next heading (or EOF).
  • SymbolSpan.Name is the heading text normalized via slugify (lowercase, runs of non-alphanumerics → "-", trimmed).
  • SymbolSpan.Kind is KindADRSection when the file path matches an ADR convention (ADR-*.md, docs/adr/*.md, etc.), otherwise KindDocSection.
  • A file with NO headings returns ONE SymbolSpan covering the whole file with Name="untitled" (the chunker labels it "FileHeader"-ish via DocSection so retrieval still works).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Slugify

func Slugify(s string) string

Slugify normalizes a heading into a chunk-friendly identifier: lowercase + non-alphanumeric runs collapsed to "-". Exported so tests and downstream tooling (eval fixtures) can match the same transformation deterministically.

"Vector store — decision matrix" → "vector-store-decision-matrix"
"§4 Embedding"                   → "4-embedding"

Types

type Parser

type Parser struct{}

Parser implements parse.Parser for *.md / *.markdown.

func New

func New() *Parser

New returns a stateless markdown parser. Cheap to construct; the builder allocates one per language.

func (*Parser) Language

func (p *Parser) Language() string

Language returns the CKV language tag.

func (*Parser) Parse

func (p *Parser) Parse(file string, src []byte) ([]cparse.SymbolSpan, error)

Parse splits src into heading-level spans. The file argument is inspected only to choose between DocSection / ADRSection — no disk reads happen here.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL