parser

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetaExt goldmark.Extender = &metaExtension{}

MetaExt is a goldmark.Extender that parses YAML frontmatter.

Functions

func ExtractFrontmatter

func ExtractFrontmatter(source []byte) (map[string]any, error)

ExtractFrontmatter extracts YAML frontmatter from markdown bytes using goldmark-meta. Returns nil, nil if no frontmatter is present.

func ExtractMetadataTuples added in v0.2.0

func ExtractMetadataTuples(fm map[string]any) []store.MetadataTuple

ExtractMetadataTuples converts a frontmatter map into normalized MetadataTuples. Rules:

  • "tags" key is skipped (already handled by tag nodes + tagged edges).
  • Output is capped at maxTuplesPerDoc; excess keys are logged and dropped.
  • Values are truncated to maxValueLen characters.
  • value_type is inferred: date, bool, list (JSON array), number, ref, or string.
  • Top-level tuples use source="frontmatter".
  • Nested "skill_advisory" values use source="skill_advisory".

func FrontmatterToJSON

func FrontmatterToJSON(fm map[string]any) string

FrontmatterToJSON converts a frontmatter map to a JSON string. Returns "" if fm is nil.

func GetTags

func GetTags(fm map[string]any) []string

GetTags extracts the "tags" field from frontmatter, handling both []interface{} and []string.

func GetTitle

func GetTitle(fm map[string]any) string

GetTitle extracts the "title" field from frontmatter.

func GetWikilinks(fm map[string]any) []string

GetWikilinks scans all string values in the frontmatter map for [[...]] patterns and returns the wikilink targets. Handles both string and slice values.

func MetaGet

func MetaGet(pc parser.Context) map[string]any

MetaGet returns the YAML frontmatter map stored in a parser.Context.

func Slugify added in v0.2.3

func Slugify(s string) string

Slugify converts a heading or term into the lowercase, dash-separated anchor slug used in heading node IDs (relPath#slug): lowercase, whitespace runs collapsed to a single "-", keeping Unicode letters + digits + "-". Exported so the tools layer can resolve a section= argument that was copied from a search-result anchor back to its heading — the match must use this exact algorithm or it would drift.

Types

type ParseResult

type ParseResult struct {
	DocNode        store.Node
	Headings       []store.Node
	Defs           []store.Node
	Tags           []store.Node // Deduplicated tag nodes
	Edges          []store.Edge
	RawLinks       []RawLink
	FileInfo       store.FileInfo
	SectionChunks  []store.SectionChunk
	MetadataTuples []store.MetadataTuple // Normalized key/value pairs from frontmatter
}

ParseResult contains all data extracted from a single markdown file.

func ParseFile

func ParseFile(absPath string, relPath string, source []byte, contentHash string) (*ParseResult, error)

ParseFile parses a markdown file and extracts nodes, edges, and raw links.

type RawLink struct {
	Text       string // Display text
	Target     string // Link target (path, wikilink name, URL)
	Kind       string // "wikilink", "markdown_link", "embed", "external"
	Line       int
	FromNodeID string // ID of the containing node
}

RawLink represents a link found during parsing, before resolution.

Jump to

Keyboard shortcuts

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