markdown

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTagToFile

func AddTagToFile(filePath string, tag string) (bool, error)

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

func FormatGoalItems(items []GoalItem) string

FormatGoalItems converts goal items back to markdown format

Types

type CheckboxItem

type CheckboxItem struct {
	Checked bool
	Text    string
}

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 (doc *Document) ExtractLinks() []Link

ExtractLinks extracts all markdown links from the document

func (*Document) ExtractSections

func (doc *Document) ExtractSections() []Section

ExtractSections extracts all sections from a document A section is defined as a heading and all content until the next heading

func (*Document) ExtractSectionsSimple

func (doc *Document) ExtractSectionsSimple() []Section

ExtractSectionsSimple extracts sections using a simpler line-based approach

func (*Document) FindSectionByHeading

func (doc *Document) FindSectionByHeading(headingText string) *Section

FindSectionByHeading finds a section by its heading text (case-insensitive)

func (*Document) FindSectionsByHeadings

func (doc *Document) FindSectionsByHeadings(headingTexts []string) []Section

FindSectionsByHeadings finds multiple sections by their heading texts (case-insensitive) Returns sections in the order they appear in the document

func (*Document) GetHeadings

func (doc *Document) GetHeadings() []Heading

GetHeadings returns all headings in the document

func (*Document) GetMetadata

func (doc *Document) GetMetadata(key string) (any, bool)

GetMetadata returns a metadata value by key

func (*Document) GetMetadataString

func (doc *Document) GetMetadataString(key string) (string, bool)

GetMetadataString returns a metadata value as a string

func (*Document) GetMetadataStringSlice

func (doc *Document) GetMetadataStringSlice(key string) ([]string, bool)

GetMetadataStringSlice returns a metadata value as a string slice

func (*Document) GetNodeText

func (doc *Document) GetNodeText(node ast.Node) string

GetNodeText extracts text content from a node

func (*Document) WalkAST

func (doc *Document) WalkAST(visitor func(node ast.Node, entering bool) ast.WalkStatus)

WalkAST walks the AST and calls the visitor function for each 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

func FilterUnfinishedGoals(items []GoalItem) []GoalItem

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

func ParseGoalItems(content string) []GoalItem

ParseGoalItems extracts both checkbox items and plain bullet points from content

type Heading

type Heading struct {
	Level int
	Text  string
	Node  ast.Node
}

Heading represents a markdown heading

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(links []Link, predicate func(Link) bool) []Link

FilterLinks filters links based on a predicate function

func (*Link) GetDateFromDestination

func (l *Link) GetDateFromDestination() string

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

func (l *Link) GetNoteTypeFromDestination() string

GetNoteTypeFromDestination tries to determine the note type from the link destination Returns "journal", "standup", or "" if unknown

func (l *Link) IsDateLink() bool

IsDateLink returns true if the link destination looks like a date (YYYY-MM-DD)

func (l *Link) IsExternalLink() bool

IsExternalLink returns true if the link is an external URL

func (l *Link) IsRelativeLink() bool

IsRelativeLink returns true if the link is a relative path

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser handles markdown parsing

func NewParser

func NewParser() *Parser

NewParser creates a new markdown parser

func (*Parser) Parse

func (p *Parser) Parse(filePath string, content []byte) (*Document, error)

Parse parses markdown content and returns a Document

func (*Parser) ParseFile

func (p *Parser) ParseFile(filePath string) (*Document, error)

ParseFile parses a markdown file and returns a Document

type Section

type Section struct {
	// Heading is the section heading
	Heading Heading

	// Content is the raw content of the section (everything between this heading and the next)
	Content string
}

Section represents a section of a document with a heading and its content

Jump to

Keyboard shortcuts

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