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 ¶
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 ¶
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 ¶
TitleFromPath derives a fallback title from the relative file path.
Types ¶
type AttachmentKind ¶ added in v2.13.0
type AttachmentKind string
AttachmentKind classifies a resolved reference.
const ( KindImage AttachmentKind = "image" KindPDF AttachmentKind = "pdf" KindOther AttachmentKind = "other" KindExternalLinks AttachmentKind = "external-links" )
type AttachmentSource ¶ added in v2.13.0
type AttachmentSource string
AttachmentSource records which markdown syntax produced a reference, so resolution can apply Obsidian semantics (wiki vs note-folder-relative).
const ( SrcWiki AttachmentSource = "wiki" SrcMarkdown AttachmentSource = "markdown" )
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 ExtractedRefs ¶ added in v2.13.0
type ExtractedRefs struct {
Refs []Ref
}
ExtractedRefs holds the references collected from a note body, deduped (by cleaned target or exact URL) in first-occurrence document order across all kinds.
func ExtractReferences ¶ added in v2.13.0
func ExtractReferences(body string) ExtractedRefs
ExtractReferences walks a note body's AST and collects direct references: local attachments (wiki and markdown syntax) and external http(s) website links. URLs and content inside code fences never match. Results are deduped by target (or exact URL) in first-occurrence document order, so an external link that appears before an image is reported before it.
type Ref ¶ added in v2.13.0
type Ref struct {
Target string
Kind AttachmentKind
Source AttachmentSource
}
Ref is one reference extracted from a note body. Target holds the cleaned wiki target, the raw markdown destination, or the full URL for external links; Kind classifies it; Source records which markdown syntax produced it so resolution can apply Obsidian semantics (wiki vs note-folder-relative). External links carry no Source: they are never resolved against the vault.
type Result ¶
Result is the output from parsing the full document, containing the chunks and metadata.
func Parse ¶
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.