Documentation
¶
Overview ¶
Package markdown provides utilities for parsing and querying markdown documents
Index ¶
- func CalculateLineColumn(content []byte, offset int) (line int, column int)
- func CalculateLineNumber(content []byte, offset int) int
- func CreateHeadingStructure(headings []string, baseLevel int) []byte
- func ExtractHeadingText(heading *ast.Heading, content []byte) string
- func FindInsertionPoint(content []byte, targetOffset int, prepend bool) int
- func FindSubtreeEnd(heading *ast.Heading, content []byte) int
- func GetNodeOffset(node ast.Node, content []byte) int
- func ParseDocument(content []byte) ast.Node
- func PathMatches(actualPath []string, targetSegments []string, skipLevels int) bool
- func TestCalculateLineNumberAdvanced(t *testing.T)
- func TestCreateHeadingStructure(t *testing.T)
- func TestFindAllHeadings(t *testing.T)
- func TestFindSubtreeAdvanced(t *testing.T)
- func TestParsePathAdvanced(t *testing.T)
- func TestPathMatches(t *testing.T)
- func TestTransformHeadingLevels(t *testing.T)
- func TransformHeadingLevels(content []byte, levelDiff int) []byte
- func ValidateOffset(content []byte, offset int) int
- type HeadingInfo
- type HeadingPath
- type LineHeadingMap
- type OffsetRange
- type Subtree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateLineColumn ¶
CalculateLineColumn calculates both line and column number from byte offset
func CalculateLineNumber ¶
CalculateLineNumber calculates line number from byte offset
func CreateHeadingStructure ¶
CreateHeadingStructure creates missing heading hierarchy
func ExtractHeadingText ¶
ExtractHeadingText extracts text from a heading node
func FindInsertionPoint ¶
FindInsertionPoint finds the best byte offset for inserting content at a specific location
func FindSubtreeEnd ¶
FindSubtreeEnd finds where a subtree ends (before next same-level heading) This is now public to allow external testing and usage
func GetNodeOffset ¶
GetNodeOffset gets the byte offset of a node in the content
func ParseDocument ¶
ParseDocument parses markdown content and returns the AST document
func PathMatches ¶
PathMatches checks if a path matches the given segments using contains matching
func TestFindAllHeadings ¶
func TestFindSubtreeAdvanced ¶
func TestParsePathAdvanced ¶
func TestPathMatches ¶
func TransformHeadingLevels ¶
TransformHeadingLevels adjusts heading levels in markdown content
func ValidateOffset ¶
ValidateOffset ensures an offset is within valid bounds for the given content
Types ¶
type HeadingInfo ¶
type HeadingInfo struct {
Text string // Heading text
Level int // Heading level (1-6)
Path []string // Full path to this heading
Offset int // Byte offset in document
}
HeadingInfo represents information about a heading in the document
func FindAllHeadings ¶
func FindAllHeadings(doc ast.Node, content []byte) []HeadingInfo
FindAllHeadings returns all headings in the document with their paths
type HeadingPath ¶
type HeadingPath struct {
File string // "inbox.md" - source file name
Segments []string // ["meeting", "attendees"] - path segments for navigation
SkipLevels int // Number of leading slashes (for unusual document structures)
}
HeadingPath represents a parsed path selector for navigating markdown headings
func ParsePath ¶
func ParsePath(pathStr string) (*HeadingPath, error)
ParsePath parses a path selector like "file.md#path/to/heading"
type LineHeadingMap ¶
LineHeadingMap represents the mapping from line numbers to heading paths
func FindNearestHeadingsForLines ¶
func FindNearestHeadingsForLines(content []byte, targetLines []int) (LineHeadingMap, error)
FindNearestHeadingsForLines efficiently finds the nearest dominant heading for multiple line numbers by parsing the document once and tracking heading context as we go. It stops parsing once all target lines have been resolved.
type OffsetRange ¶
OffsetRange represents a range of bytes in content
func (OffsetRange) Extract ¶
func (r OffsetRange) Extract(content []byte) []byte
Extract returns the content within the range
func (OffsetRange) IsValid ¶
func (r OffsetRange) IsValid(content []byte) bool
IsValid checks if the offset range is valid for the given content
func (OffsetRange) Length ¶
func (r OffsetRange) Length() int
Length returns the length of the range
type Subtree ¶
type Subtree struct {
Heading string // Original heading text
Level int // Original heading level (1-6)
Content []byte // Full subtree content (markdown)
StartOffset int // Byte position in source
EndOffset int // Byte position in source
}
Subtree represents a complete markdown subtree (heading + all nested content)
func FindSubtree ¶
FindSubtree finds a subtree matching the given path selector