{"modulePath":"github.com/JordanCoin/docmap","version":"v0.6.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package parser\n\n## Constants\n\n```go\nconst (\n\t// MaxHitsPerSection is how many matching lines SectionLineHits returns.\n\tMaxHitsPerSection = 3\n)\n```\n\n```go\nconst PDFTextCommandEnv = \"DOCMAP_PDF_TEXT_CMD\"\n```\nPDFTextCommandEnv names an external text extractor. When set, its value is a command line that receives the PDF path (substituted for \"{}\", or appended when there is no \"{}\") and writes plain text to stdout, with a form feed between pages if it wants page structure preserved:\n\n\tDOCMAP_PDF_TEXT_CMD=\"pdftotext -layout {} -\"\n\ndocmap keeps its own outline structure and anchors it to that text (#34). The value is split on whitespace and run directly, never through a shell. If the command fails, docmap says so on stderr and uses its built-in extractor.\n\n## Variables\n\n```go\nvar (\n\t// ErrNotRepo is returned when the path is not inside a git work tree.\n\tErrNotRepo = errors.New(\"not a git repository\")\n\t// ErrBadRef is returned when --since names a ref git cannot resolve.\n\tErrBadRef = errors.New(\"unknown git ref\")\n)\n```\n\n## Functions\n\n```go\nfunc ChangedLines(file, ref string) (map[int]bool, error)\n```\nChangedLines returns the set of line numbers in \\`file\\` that have been modified since the given git ref. It shells out to \\`git diff --unified=0\\` and parses the hunk headers, which in unified-0 mode give exact line ranges in the new (working) file.\n\nGit is always run from the file's repository root, so the caller does not have to be in the work tree (or even in the same directory as the file). Paths are canonicalized with EvalSymlinks so macOS /var vs /private/var (and any other intermediate symlink) still maps onto git's pathspec.\n\nNew files (untracked, or added after \\`ref\\`) are treated as fully changed. Renames compare against the pre-rename blob so only real edits light up. Binary diffs (no text hunks) light up every current line. Missing git, a path outside any work tree, or an unknown ref return a typed error (ErrNotRepo / ErrBadRef) with an empty set.\n\n```go\nfunc ChangedLinesBatch(root, ref string, files []string) (map[string]map[int]bool, error)\n```\nChangedLinesBatch returns changed line sets for each path in files since ref, keyed by the exact strings passed in. It runs one repo-level \\`git diff --unified=0 -M ref\\` (plus one ls-tree for paths absent from the diff) instead of spawning git once per file.\n\nBehavior matches ChangedLines: renames light up only real edits, binaries and new/untracked files mark every current line, and ErrNotRepo / ErrBadRef are returned when the root or ref is invalid.\n\n```go\nfunc ContainsText(text, query string) bool\n```\nContainsText reports whether query occurs in text the way a reader would say it does: case-insensitively, with any run of whitespace (including a line wrap) matching a single space, and seeing through end-of-line hyphenation (\"under-\\\\nmined\" contains \"undermined\"). query must already be lowercase.\n\nWrapped prose is the norm in PDFs, plain text and hard-wrapped markdown, and a phrase search that fails because the phrase straddles a line break is a wrong answer, not a miss.\n\n```go\nfunc EnsureRef(dir, ref string) error\n```\nEnsureRef reports whether dir is in a git work tree and ref names a commit.\n\n```go\nfunc GitRoot(dir string) string\n```\nGitRoot returns the work tree root that contains dir, or \"\" if dir is not inside a git repository.\n\n```go\nfunc IsDocPath(rel string) bool\n```\nIsDocPath reports whether path looks like a documentation file docmap walks.\n\n```go\nfunc RecentFiles(dir string, limit int) []string\n```\nRecentFiles returns up to \\`limit\\` unique paths changed in recent commits under dir, newest first. Paths are relative to dir. Returns nil when git is unavailable or dir is not a work tree.\n\n```go\nfunc Walk(root Node, fn func(Node) bool)\n```\nWalk invokes fn for every node reachable from root, depth-first. Returning false from fn skips descending into that node's children.\n\n## Types\n\n```go\ntype AutoLink struct {\n\tBaseNode\n\tURL    string\n\tIsBare bool\n\tIsMail bool\n}\n```\nAutoLink is \\\u003curl\u003e or a GFM bare-URL autolink.\n\n```go\ntype BaseNode struct {\n\tNKind    NodeKind\n\tStart    int\n\tEnd      int\n\tTokCount int\n\tKids     []Node\n}\n```\nBaseNode holds fields common to every node and is embedded in each concrete type. Its exported fields let constructors populate state without per-type setters.\n\n```go\nfunc (b *BaseNode) Children() []Node\n```\n\n```go\nfunc (b *BaseNode) Kind() NodeKind\n```\n\n```go\nfunc (b *BaseNode) LineEnd() int\n```\n\n```go\nfunc (b *BaseNode) LineStart() int\n```\n\n```go\nfunc (b *BaseNode) Tokens() int\n```\n\n```go\ntype Blockquote struct {\n\tBaseNode\n}\n```\nBlockquote is a \u003e quoted block, possibly nested.\n\n```go\ntype Callout struct {\n\tBaseNode\n\tVariant CalloutKind\n}\n```\nCallout is a GFM alert (\u003e \\[!NOTE] / \\[!TIP] / \\[!IMPORTANT] / \\[!WARNING] / \\[!CAUTION]).\n\n```go\ntype CalloutKind string\n```\nCalloutKind identifies the variant of a GFM alert (\u003e \\[!NOTE] etc).\n\n```go\nconst (\n\tCalloutNote      CalloutKind = \"note\"\n\tCalloutTip       CalloutKind = \"tip\"\n\tCalloutImportant CalloutKind = \"important\"\n\tCalloutWarning   CalloutKind = \"warning\"\n\tCalloutCaution   CalloutKind = \"caution\"\n)\n```\n\n```go\ntype CodeBlock struct {\n\tBaseNode\n\tLanguage string\n\tInfo     string\n\tFenced   bool\n\tCode     string\n}\n```\nCodeBlock is a fenced or indented code block.\n\n```go\ntype CommitRef struct {\n\tBaseNode\n\tSHA string\n}\n```\nCommitRef is a SHA autolink (GFM).\n\n```go\ntype ContentSummary struct {\n\tCallouts     int\n\tTables       int\n\tCodeBlocks   int\n\tMathBlocks   int\n\tHTMLBlocks   int\n\tFootnotes    int\n\tDefLists     int\n\tLinkRefDefs  int\n\tTasks        int\n\tTasksChecked int\n\tWikiLinks    int\n\tWikiEmbeds   int\n\tMentions     int\n\tIssueRefs    int\n\tCommitRefs   int\n\tEmojis       int\n}\n```\nContentSummary is an at-a-glance inventory of notable constructs across an entire Document. Used by the renderer to draw the file header.\n\n```go\ntype Definition struct {\n\tBaseNode\n}\n```\nDefinition is a single definition for a term.\n\n```go\ntype DefinitionList struct {\n\tBaseNode\n}\n```\nDefinitionList is a Pandoc-style definition list.\n\n```go\ntype DefinitionTerm struct {\n\tBaseNode\n\tTerm string\n}\n```\nDefinitionTerm is the term being defined.\n\n```go\ntype Delete struct {\n\tBaseNode\n}\n```\nDelete is ~~text~~ (GFM strikethrough).\n\n```go\ntype Document struct {\n\tFilename    string\n\tSource      string // original file text; used by --expand to dump real markdown\n\tTotalTokens int\n\tSections    []*Section\n\tReferences  []Reference // Links to other .md files\n\tNodes       []Node      // Typed AST (populated by the new parser)\n\t// contains filtered or unexported fields\n}\n```\nDocument represents a parsed markdown document.\n\nThe legacy Sections tree is heading-only and is what the renderer currently consumes. Nodes holds the richer typed AST produced by the new goldmark-based parser (frontmatter, tables, callouts, code blocks, Obsidian wiki links, etc.) once it lands. Both exist side-by-side during the migration so existing callers keep working.\n\n```go\nfunc Parse(content string) *Document\n```\nParse parses markdown content into a Document using goldmark (CommonMark + GFM + Obsidian extensions) and derives the legacy Section tree and cross-file Reference list from the resulting typed AST.\n\n```go\nfunc ParseFile(path string) (*Document, error)\n```\nParseFile reads path, optionally consults the on-disk mtime parse cache in the user cache dir, parses, and stores a fresh entry. Set DOCMAP\\_NO\\_CACHE=1 to skip the cache entirely. Cache I/O errors are ignored.\n\n```go\nfunc ParsePDF(filepath string) (*Document, error)\n```\nParsePDF parses a PDF file into a Document structure. Outlined PDFs get their bookmark tree anchored to the text layer; PDFs without an outline get one section per page. Either way doc.Source holds the extracted text and section line numbers index into it, so --expand, --at and --search work.\n\n```go\nfunc ParseText(content string) *Document\n```\nParseText parses a plain-text file. Text with markdown ATX headings is parsed as markdown. Anything else gets a structure inferred from the conventions extracted or hand-written text actually uses, in this order:\n\n  - underlined titles (=== / --- / ~~~ under a line),\n  - numbered headings (\"2.3 Methods\") and ALL-CAPS lines, each standing alone between blank lines,\n  - form feeds, which pdftotext and friends emit between pages,\n  - failing all of those, one section spanning the file,\n\nso every byte of the file belongs to a section and is reachable by search, --expand and --at. Line numbers are real file lines.\n\n```go\nfunc ParseYAML(content string) (*Document, error)\n```\nParseYAML parses YAML content into a Document structure\n\n```go\nfunc (d *Document) FindSections(name string) []*Section\n```\nFindSections returns every section matching name, best first: an exact title, then a title that starts with name, then one that merely contains it; document order within each rank. A first-substring match is the wrong default when a paper titled \"… Smudgeplot …\" also has a section called \"Smudgeplot\".\n\nname may be a breadcrumb, \"Parent \u003e Child\": the last part is matched against the title and the earlier parts, in order, against its ancestors.\n\n```go\nfunc (d *Document) GetAllSections() []*Section\n```\nGetAllSections returns a flat list of all sections\n\n```go\nfunc (d *Document) GetSection(name string) *Section\n```\nGetSection finds the section that best matches name (case-insensitive). See FindSections for what \"best\" means.\n\n```go\nfunc (d *Document) SourceSpan(start, end int) string\n```\nSourceSpan returns the original source for the inclusive 1-based line range. Empty when Source was not captured (PDF) or the range is invalid. Lines are split once per document and reused across calls.\n\n```go\nfunc (d *Document) SuggestSections(name string, limit int) []string\n```\nSuggestSections returns up to limit section titles that share a word with name, for \"did you mean\" output when a lookup finds nothing.\n\n```go\nfunc (d *Document) Summary() ContentSummary\n```\nSummary walks the typed AST once and returns inventory counts for every notable construct in the document. Used by the renderer to draw the file header's content summary.\n\n```go\ntype Emoji struct {\n\tBaseNode\n\tName string\n}\n```\nEmoji is :name: (GFM).\n\n```go\ntype Emphasis struct {\n\tBaseNode\n}\n```\nEmphasis is \\*text\\* or \\_text\\_.\n\n```go\ntype Entity struct {\n\tBaseNode\n\tRaw     string\n\tDecoded string\n}\n```\nEntity is an HTML entity (\u0026copy;, \u0026#169;, \u0026#x2665;).\n\n```go\ntype FootnoteDef struct {\n\tBaseNode\n\tID string\n}\n```\nFootnoteDef is a footnote definition (\\[^id]: content).\n\n```go\ntype FootnoteRef struct {\n\tBaseNode\n\tID string\n}\n```\nFootnoteRef is \\[^id] in flowing text.\n\n```go\ntype Frontmatter struct {\n\tBaseNode\n\tFormat FrontmatterFormat\n\tRaw    string\n}\n```\nFrontmatter is a YAML/TOML/JSON header block at the top of a file.\n\n```go\ntype FrontmatterFormat string\n```\nFrontmatterFormat is the serialization format of a frontmatter block.\n\n```go\nconst (\n\tFrontmatterYAML FrontmatterFormat = \"yaml\"\n\tFrontmatterTOML FrontmatterFormat = \"toml\"\n\tFrontmatterJSON FrontmatterFormat = \"json\"\n)\n```\n\n```go\ntype HTMLBlock struct {\n\tBaseNode\n\tRaw string\n}\n```\nHTMLBlock is a raw HTML block (includes \\\u003cdetails\u003e, \\\u003cdiv\u003e, comments).\n\n```go\ntype Heading struct {\n\tBaseNode\n\tLevel    int\n\tTitle    string\n\tRawTitle string\n\tIsSetext bool\n\tID       string\n}\n```\nHeading is an ATX (# Title) or Setext (underline) heading.\n\n```go\ntype Image struct {\n\tBaseNode\n\tURL   string\n\tAlt   string\n\tTitle string\n\tRefID string\n}\n```\nImage is an inline or reference image.\n\n```go\ntype InlineCode struct {\n\tBaseNode\n\tCode string\n}\n```\nInlineCode is \\`text\\`.\n\n```go\ntype InlineHTML struct {\n\tBaseNode\n\tRaw string\n}\n```\nInlineHTML is raw inline HTML like \\\u003ckbd\u003e.\n\n```go\ntype InlineMath struct {\n\tBaseNode\n\tTeX string\n}\n```\nInlineMath is $...$.\n\n```go\ntype IssueRef struct {\n\tBaseNode\n\tRepo   string\n\tNumber int\n}\n```\nIssueRef is #123 / GH-123 / user/repo#123 (GFM).\n\n```go\ntype LineBreak struct {\n\tBaseNode\n\tHard bool\n}\n```\nLineBreak is a hard (two-space / backslash) or soft line break.\n\n```go\ntype LineHit struct {\n\tLine int    `json:\"line\"`\n\tText string `json:\"text\"` // the line, trimmed to a snippet around the match\n}\n```\nLineHit is one source line that matches a search query.\n\n```go\nfunc SectionLineHits(doc *Document, s *Section, query string) ([]LineHit, int)\n```\nSectionLineHits is the line-level matcher behind search: the first few lines of s's own text (not its subsections') that contain query, which must be lowercase, and how many such lines there are in all. A phrase that wraps onto the next line, or a word hyphenated across the break, is reported at the line where it starts. Documents without line-addressable source return nothing.\n\n```go\ntype Link struct {\n\tBaseNode\n\tURL   string\n\tTitle string\n\tText  string\n\tRefID string\n}\n```\nLink is an inline or reference link.\n\n```go\ntype LinkRefDef struct {\n\tBaseNode\n\tLabel string\n\tURL   string\n\tTitle string\n}\n```\nLinkRefDef is a reference link definition (\\[label]: url \"title\").\n\n```go\ntype List struct {\n\tBaseNode\n\tOrdered bool\n\tTight   bool\n\tStart   int\n\tMarker  rune\n}\n```\nList is an ordered or unordered list.\n\n```go\ntype ListItem struct {\n\tBaseNode\n}\n```\nListItem is a regular item inside a list.\n\n```go\ntype MathBlock struct {\n\tBaseNode\n\tTeX   string\n\tFence string\n}\n```\nMathBlock is a block-level math expression ($$...$$ or \\\\\\[...\\\\]).\n\n```go\ntype Mention struct {\n\tBaseNode\n\tUser string\n}\n```\nMention is @user (GFM).\n\n```go\ntype Node interface {\n\tKind() NodeKind\n\tLineStart() int\n\tLineEnd() int\n\tTokens() int\n\tChildren() []Node\n}\n```\nNode is the common interface every markdown construct implements. Concrete types embed BaseNode to satisfy it.\n\n```go\nfunc FindByKind(root Node, kind NodeKind) []Node\n```\nFindByKind returns every descendant of root whose Kind matches kind.\n\n```go\ntype NodeKind string\n```\nNodeKind enumerates every markdown construct docmap recognizes. The taxonomy covers CommonMark + GFM + Obsidian wiki links/embeds.\n\n```go\nconst (\n\tKindFrontmatter    NodeKind = \"frontmatter\"\n\tKindHeading        NodeKind = \"heading\"\n\tKindParagraph      NodeKind = \"paragraph\"\n\tKindBlockquote     NodeKind = \"blockquote\"\n\tKindCallout        NodeKind = \"callout\"\n\tKindList           NodeKind = \"list\"\n\tKindListItem       NodeKind = \"list_item\"\n\tKindTaskItem       NodeKind = \"task_item\"\n\tKindTable          NodeKind = \"table\"\n\tKindTableRow       NodeKind = \"table_row\"\n\tKindTableCell      NodeKind = \"table_cell\"\n\tKindCodeBlock      NodeKind = \"code_block\"\n\tKindMathBlock      NodeKind = \"math_block\"\n\tKindThematicBreak  NodeKind = \"thematic_break\"\n\tKindHTMLBlock      NodeKind = \"html_block\"\n\tKindDefinitionList NodeKind = \"definition_list\"\n\tKindDefTerm        NodeKind = \"definition_term\"\n\tKindDefinition     NodeKind = \"definition\"\n\tKindFootnoteDef    NodeKind = \"footnote_def\"\n\tKindLinkRefDef     NodeKind = \"link_ref_def\"\n\n\tKindText        NodeKind = \"text\"\n\tKindEmphasis    NodeKind = \"emphasis\"\n\tKindStrong      NodeKind = \"strong\"\n\tKindDelete      NodeKind = \"delete\"\n\tKindInlineCode  NodeKind = \"inline_code\"\n\tKindLink        NodeKind = \"link\"\n\tKindAutoLink    NodeKind = \"autolink\"\n\tKindImage       NodeKind = \"image\"\n\tKindWikiLink    NodeKind = \"wiki_link\"\n\tKindWikiEmbed   NodeKind = \"wiki_embed\"\n\tKindFootnoteRef NodeKind = \"footnote_ref\"\n\tKindMention     NodeKind = \"mention\"\n\tKindIssueRef    NodeKind = \"issue_ref\"\n\tKindCommitRef   NodeKind = \"commit_ref\"\n\tKindEmoji       NodeKind = \"emoji\"\n\tKindLineBreak   NodeKind = \"line_break\"\n\tKindEntity      NodeKind = \"entity\"\n\tKindInlineMath  NodeKind = \"inline_math\"\n\tKindInlineHTML  NodeKind = \"inline_html\"\n)\n```\n\n```go\ntype NotableStats struct {\n\tTasks        int\n\tTasksChecked int\n\tWikiLinks    int\n\tWikiEmbeds   int\n\tMentions     int\n\tIssueRefs    int\n\tCommitRefs   int\n\tEmojis       int\n}\n```\nNotableStats aggregates counts of constructs that would be noisy if listed per-instance under a section.\n\n```go\ntype Paragraph struct {\n\tBaseNode\n\tText string\n\tRaw  string\n}\n```\nParagraph is a block of flowing text. Text is the inline-rendered form (newlines collapsed); Raw preserves the original multi-line source so post-passes (math fences, etc.) can operate on real line boundaries.\n\n```go\ntype PathChange struct {\n\tPath    string // relative to the directory passed to ChangedPaths\n\tOldPath string // set for renames (R) / copies (C)\n\tStatus  string // A, M, D, R, C (untracked files are A)\n}\n```\nPathChange is one path git reports as different from ref.\n\n```go\nfunc ChangedPaths(dir, ref string) ([]PathChange, error)\n```\nChangedPaths lists documentation files that differ from ref under dir, including deletions, renames, and untracked files. Paths are slash- separated and relative to dir. Non-doc paths are omitted.\n\n```go\nfunc ChangedPathsAll(dir, ref string) ([]PathChange, error)\n```\nChangedPathsAll lists every path that differs from ref under dir, including non-doc files (e.g. .go), deletions, renames, and untracked files. Paths are slash-separated and relative to dir.\n\n```go\ntype Reference struct {\n\tText   string // Link text\n\tTarget string // Target file path\n\tLine   int    // Line number where reference appears\n}\n```\nReference represents a link to another markdown file\n\n```go\ntype Section struct {\n\tLevel     int // 1 = #, 2 = ##, etc.\n\tTitle     string\n\tContent   string   // raw content (excluding children)\n\tTokens    int      // estimated tokens for this section\n\tKeyTerms  []string // extracted key concepts\n\tChildren  []*Section\n\tParent    *Section\n\tLineStart int\n\tLineEnd   int\n\tNotables  []Node\n\tStats     NotableStats\n}\n```\nSection represents a heading and the content that follows it up to the next same-or-higher heading.\n\nNotables lists the discoverable block nodes inside this section that an agent might want to jump to directly — callouts, tables, code blocks, math blocks, HTML blocks, footnote definitions, definition lists. It is populated one-per-instance so the renderer can print each as its own line.\n\nStats aggregates counts of things that would be noisy per-instance (task list items, Obsidian wiki links, Obsidian embeds). They are rendered as a single summary line per section.\n\n```go\ntype Strong struct {\n\tBaseNode\n}\n```\nStrong is \\*\\*text\\*\\* or \\_\\_text\\_\\_.\n\n```go\ntype Table struct {\n\tBaseNode\n\tHeaders []string\n\tAligns  []TableAlign\n}\n```\nTable is a GFM table.\n\n```go\ntype TableAlign string\n```\nTableAlign specifies a column's alignment in a GFM table.\n\n```go\nconst (\n\tAlignNone   TableAlign = \"\"\n\tAlignLeft   TableAlign = \"left\"\n\tAlignCenter TableAlign = \"center\"\n\tAlignRight  TableAlign = \"right\"\n)\n```\n\n```go\ntype TableCell struct {\n\tBaseNode\n\tAlign TableAlign\n}\n```\nTableCell is one cell within a row.\n\n```go\ntype TableRow struct {\n\tBaseNode\n\tIsHeader bool\n}\n```\nTableRow is a single row of a table.\n\n```go\ntype TaskItem struct {\n\tBaseNode\n\tChecked bool\n}\n```\nTaskItem is a GFM task list item (\\[ ] or \\[x]).\n\n```go\ntype Text struct {\n\tBaseNode\n\tValue string\n}\n```\nText is a plain run of characters.\n\n```go\ntype ThematicBreak struct {\n\tBaseNode\n}\n```\nThematicBreak is --- / \\*\\*\\* / \\_\\_\\_.\n\n```go\ntype WikiEmbed struct {\n\tBaseNode\n\tTarget string\n\tWidth  int\n\tHeight int\n}\n```\nWikiEmbed is !\\[\\[file]] / !\\[\\[file|200]] / !\\[\\[file|200x100]] (Obsidian).\n\n```go\ntype WikiLink struct {\n\tBaseNode\n\tTarget string\n\tAlias  string\n\tAnchor string\n\tBlock  string\n}\n```\nWikiLink is \\[\\[Page]] / \\[\\[Page|alias]] / \\[\\[Page#header]] / \\[\\[Page#^block]] (Obsidian).\n\n","path":"github.com/JordanCoin/docmap/parser","name":"parser","synopsis":"","isRedistributable":true}
