Help us shape the future of Go! Take the 2026 Go Developer Survey

parser

package
v0.10.18 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package parser extracts frontmatter, links, headings, and blocks from Markdown files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyNote

func ClassifyNote(fm map[string]interface{}) (isDomain bool, id string, noteType string)

ClassifyNote determines whether a note is a domain note (has both id and type as non-empty strings) or an unstructured note.

func ExtractFrontmatter

func ExtractFrontmatter(content []byte) (fm map[string]interface{}, body string, err error)

ExtractFrontmatter splits a raw .md file into its YAML frontmatter map and the remaining body text.

If the file has no frontmatter (does not start with "---\n"), fm is nil and body is the entire file content.

func StripForFTS

func StripForFTS(body string) string

StripForFTS converts Markdown body text to plain text for full-text search indexing.

func StripForFTSOffsets added in v0.10.10

func StripForFTSOffsets(body string) (string, []int)

StripForFTSOffsets applies the keyword lane's Markdown normalization while retaining the raw byte position of each remaining byte for excerpt delivery.

func StripHTMLComments added in v0.10.13

func StripHTMLComments(s string) string

StripHTMLComments removes every HTML comment. Search text and recall excerpts use it: those paths quote the note's words, not its comments. A VaultMind marker is removed here because every comment is. Delivery does not call this. An author comment is part of the note, and the only comment delivery hides is StripVaultMindMarkers.

func StripVaultMindMarkers added in v0.10.13

func StripVaultMindMarkers(s string) string

StripVaultMindMarkers removes HTML comments whose text starts with "vaultmind:". Those are VaultMind's own bookkeeping, written so a retried accept does not append a proposal twice. Any other HTML comment is the author's and stays. Whitespace after "<!--" is allowed; the comment accept writes is "<!-- vaultmind:".

Callers that load a body for an agent: QueryFullNote (ask, memory pack, arc recite, --read, summarize, MCP ask), populateRawSnippets, and the FTS preview. note get does not call this. It is an explicit raw read.

Types

type ExtractedBlock

type ExtractedBlock struct {
	BlockID string
	Heading string
	Line    int
}

ExtractedBlock is a block ID anchor (^block-id) found in a note body.

func ExtractBlocks

func ExtractBlocks(body string) []ExtractedBlock

ExtractBlocks returns all block ID anchors (^block-id) in document order. Block IDs inside fenced code blocks are ignored.

type ExtractedHeading

type ExtractedHeading struct {
	Level int
	Title string
	Slug  string
	Line  int
}

ExtractedHeading is a Markdown heading found in a note body.

func ExtractHeadings

func ExtractHeadings(body string) []ExtractedHeading

ExtractHeadings returns all Markdown headings in document order. Headings inside fenced code blocks are ignored.

type ExtractedLink struct {
	Target     string
	Display    string
	LinkType   LinkType
	TargetKind TargetKind
	Heading    string
	BlockID    string
	Line       int
}

ExtractedLink is a single outbound link found in a note body.

func ExtractLinks(body string) []ExtractedLink

ExtractLinks scans body text for all outbound links. Code fences and inline code spans are skipped.

type LinkType

type LinkType string

LinkType classifies how a link was expressed in the source text.

const (
	LinkTypeWikilink LinkType = "wikilink"
	LinkTypeEmbed    LinkType = "embed"
	LinkTypeMarkdown LinkType = "markdown"
)

type ParsedNote

type ParsedNote struct {
	Frontmatter map[string]interface{}
	Body        string
	FTSBody     string
	Links       []ExtractedLink
	Headings    []ExtractedHeading
	Blocks      []ExtractedBlock
	IsDomain    bool
	ID          string
	NoteType    string
}

ParsedNote is the complete result of parsing a single .md file.

func Parse

func Parse(content []byte) (*ParsedNote, error)

Parse converts raw .md file content into a ParsedNote. Returns an error only if YAML frontmatter is present but syntactically invalid.

type TargetKind

type TargetKind string

TargetKind classifies what the link target refers to.

const (
	TargetKindNote     TargetKind = "note"
	TargetKindHeading  TargetKind = "heading"
	TargetKindBlock    TargetKind = "block"
	TargetKindPath     TargetKind = "path"
	TargetKindExternal TargetKind = "external"
)

Jump to

Keyboard shortcuts

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