Documentation
¶
Overview ¶
Package markdown provides utilities for parsing and manipulating markdown documents. It uses the Goldmark library for parsing and supports YAML frontmatter via goldmark-meta.
Index ¶
- func AddTagToFile(filePath string, tag string) (bool, error)
- func FormatCheckboxItems(items []CheckboxItem) string
- func FormatGoalItems(items []GoalItem) string
- type CheckboxItem
- type Document
- func (doc *Document) ExtractLinks() []Link
- func (doc *Document) ExtractSections() []Section
- func (doc *Document) ExtractSectionsSimple() []Section
- func (doc *Document) FindSectionByHeading(headingText string) *Section
- func (doc *Document) FindSectionsByHeadings(headingTexts []string) []Section
- func (doc *Document) GetHeadings() []Heading
- func (doc *Document) GetMetadata(key string) (any, bool)
- func (doc *Document) GetMetadataString(key string) (string, bool)
- func (doc *Document) GetMetadataStringSlice(key string) ([]string, bool)
- func (doc *Document) GetNodeText(node ast.Node) string
- func (doc *Document) WalkAST(visitor func(node ast.Node, entering bool) ast.WalkStatus)
- type GoalItem
- type Heading
- type Link
- type Parser
- type Section
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTagToFile ¶
AddTagToFile adds a tag to the frontmatter tags array in a markdown file If the file doesn't have frontmatter or tags, it won't modify the file Returns true if the tag was added, false if it already existed or couldn't be added
func FormatCheckboxItems ¶
func FormatCheckboxItems(items []CheckboxItem) string
FormatCheckboxItems converts items back to markdown checkbox format
func FormatGoalItems ¶
FormatGoalItems converts goal items back to markdown format
Types ¶
type CheckboxItem ¶
CheckboxItem represents a task with a checkbox
func FilterPendingItems ¶
func FilterPendingItems(items []CheckboxItem) []CheckboxItem
FilterPendingItems returns only unchecked items
func ParseCheckboxItems ¶
func ParseCheckboxItems(content string) []CheckboxItem
ParseCheckboxItems extracts checkbox items from content
type Document ¶
type Document struct {
// FilePath is the path to the markdown file
FilePath string
// Content is the raw markdown content
Content []byte
// Metadata contains the YAML frontmatter
Metadata map[string]any
// AST is the parsed markdown abstract syntax tree
AST ast.Node
// Source is the source text reference for AST navigation
Source []byte
}
Document represents a parsed markdown document
func (*Document) ExtractLinks ¶
ExtractLinks extracts all markdown links from the document
func (*Document) ExtractSections ¶
ExtractSections extracts all sections from a document A section is defined as a heading and all content until the next heading
func (*Document) ExtractSectionsSimple ¶
ExtractSectionsSimple extracts sections using a simpler line-based approach
func (*Document) FindSectionByHeading ¶
FindSectionByHeading finds a section by its heading text (case-insensitive)
func (*Document) FindSectionsByHeadings ¶
FindSectionsByHeadings finds multiple sections by their heading texts (case-insensitive) Returns sections in the order they appear in the document
func (*Document) GetHeadings ¶
GetHeadings returns all headings in the document
func (*Document) GetMetadata ¶
GetMetadata returns a metadata value by key
func (*Document) GetMetadataString ¶
GetMetadataString returns a metadata value as a string
func (*Document) GetMetadataStringSlice ¶
GetMetadataStringSlice returns a metadata value as a string slice
func (*Document) GetNodeText ¶
GetNodeText extracts text content from a node
type GoalItem ¶
type GoalItem struct {
Text string
HasCheckbox bool
Checked bool // Only meaningful if HasCheckbox is true
}
GoalItem represents a goal that can be either a checkbox item or plain bullet point
func FilterUnfinishedGoals ¶
FilterUnfinishedGoals returns items that should be copied forward: - Unchecked checkbox items [ ] - Plain bullet points without checkboxes (unknown state) Does NOT include checked items [x]
func ParseGoalItems ¶
ParseGoalItems extracts both checkbox items and plain bullet points from content
type Link ¶
type Link struct {
// Text is the link text (what appears between [])
Text string
// Destination is the link target (what appears between ())
Destination string
// Line is the line number where the link appears (1-indexed)
Line int
// Node is the AST node for this link
Node *ast.Link
}
Link represents a markdown link found in a document
func FilterLinks ¶
FilterLinks filters links based on a predicate function
func (*Link) GetDateFromDestination ¶
GetDateFromDestination extracts the date portion from a link destination Returns the date string (YYYY-MM-DD) or empty string if not a date link
func (*Link) GetNoteTypeFromDestination ¶
GetNoteTypeFromDestination tries to determine the note type from the link destination Returns "journal", "standup", or "" if unknown
func (*Link) IsDateLink ¶
IsDateLink returns true if the link destination looks like a date (YYYY-MM-DD)
func (*Link) IsExternalLink ¶
IsExternalLink returns true if the link is an external URL
func (*Link) IsRelativeLink ¶
IsRelativeLink returns true if the link is a relative path