parser

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 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.

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