parser

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 21 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 known attachment file (e.g. images, canvas files, archives). Dotted note names such as "Note 1.2.3" are notes, not attachments.

func Slugify

func Slugify(name string) string

Slugify converts a note name/filename to a slug. It lowercases, trims .md, replaces spaces with hyphens, and removes punctuation, emoji, and other symbols. Unicode letters and numerals are preserved so accented or CJK names do not collapse into the same slug.

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 and RichText are the overlap-free display text used for storage and
	// retrieval output. Text is clean prose (code blocks replaced with
	// placeholders); RichText keeps actual code and markdown inline.
	Text     string
	RichText string
	// EmbedText is the text fed to the embedding model. For split sections it
	// includes the configured chunk-overlap so sentence-level continuity across
	// sub-chunk boundaries survives embedding. It is never stored or displayed.
	EmbedText   string
	HeadingPath string // e.g. "Architecture > Data Flow > Ingest"
	Level       int    // depth of the deepest heading in this chunk (1-6)
	HasTask     bool
	HasCode     bool // true when the chunk contains a fenced code block
}

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