parser

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package parser provides Markdown parsing, slugification, and text chunking for notebrain-cli.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAttachmentLink(target string) bool

IsAttachmentLink returns true if target points to a non-markdown file or attachment (e.g., images, PDFs, canvas files).

func Slugify

func Slugify(name string) string

Slugify converts a note name/filename to a URL-safe slug. It lowercases, trims .md, replaces spaces with hyphens, and removes non-alphanumeric characters except hyphens.

func TitleFromPath

func TitleFromPath(path string) string

TitleFromPath derives a fallback title from the relative file path.

Types

type Chunk

type Chunk struct {
	NoteSlug    string
	Index       int
	Text        string // clean prose text for embedding (code blocks replaced with placeholders)
	RichText    string // full text with actual code inline (for storage/retrieval)
	HeadingPath string // e.g. "Architecture > Data Flow > Ingest"
	Level       int    // depth of the deepest heading in this chunk (1-6)
	CodeBlocks  int    // number of fenced code blocks in this chunk
	HasTable    bool
	HasTask     bool
	WordCount   int
}

Chunk is one section of a note, bounded by heading structure.

type Result

type Result struct {
	Chunks      []Chunk
	Tags        []string
	Links       []string
	Frontmatter map[string]any
}

Result is the output from parsing the full document, containing the chunks and metadata.

func Parse

func Parse(body, noteSlug string, maxChunkRunes, overlapRunes int, skipAttachments bool) Result

Parse parses body text into Chunks, extracting wikilinks, tags, and frontmatter. maxChunkRunes controls the maximum rune length per chunk. overlapRunes controls how many runes are repeated at the start of the next sub-chunk when a section is split (overlap). If skipAttachments is true, links pointing to non-markdown attachments (images, PDFs, etc.) are ignored.

Jump to

Keyboard shortcuts

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