markdown

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAction = ActionQuestion

DefaultAction is the default action type for new comments.

View Source
const OverviewSectionID = "overview"

OverviewSectionID is the virtual section ID used for file-level comments on the overview/preamble.

Variables

ActionLabels is the ordered list of action labels for Tab cycling.

DecorationLabels is the ordered list of decoration labels for cycling.

Functions

func FormatActionLabel

func FormatActionLabel(action ActionType, deco Decoration) string

FormatActionLabel formats an action and decoration pair for display.

func FormatLineRef added in v0.6.0

func FormatLineRef(startLine, endLine int) string

FormatLineRef formats a line reference from start and end line numbers. Returns "L10" for single line, "L10-L15" for range, or "" if startLine is 0.

func FormatReview

func FormatReview(result *ReviewResult, d *Document, filePath string) string

FormatReview formats a ReviewResult as a Markdown string. Section-level comments are grouped under section headings. Line-level comments are listed separately by line number.

func SaveViewedState

func SaveViewedState(path string, state *ViewedState) error

SaveViewedState writes the viewed state to a JSON file.

func StatePath

func StatePath(filePath string) string

StatePath returns the sidecar file path for persisting viewed state.

Types

type ActionType

type ActionType string

ActionType is the type of review action, based on Conventional Comments labels.

const (
	ActionSuggestion ActionType = "suggestion"
	ActionIssue      ActionType = "issue"
	ActionQuestion   ActionType = "question"
	ActionNitpick    ActionType = "nitpick"
	ActionTodo       ActionType = "todo"
	ActionThought    ActionType = "thought"
	ActionNote       ActionType = "note"
	ActionPraise     ActionType = "praise"
	ActionChore      ActionType = "chore"
)

type Decoration

type Decoration string

Decoration is the decoration modifier for a Conventional Comment.

const (
	DecorationNone        Decoration = ""
	DecorationNonBlocking Decoration = "non-blocking"
	DecorationBlocking    Decoration = "blocking"
	DecorationIfMinor     Decoration = "if-minor"
)

type Document

type Document struct {
	Title       string     // H1 heading text (or filename if no H1)
	Preamble    string     // Text before the first heading
	Sections    []*Section // Top-level sections
	SourceLines []string   // Raw source lines (for line-level commenting)
}

Document is the parsed structure of an entire Markdown file.

func Parse

func Parse(source []byte) (*Document, error)

Parse parses a Markdown source into a Document structure. It uses goldmark to build an AST and walks headings to create sections.

func (*Document) AllSections

func (d *Document) AllSections() []*Section

AllSections returns a flat list of all sections in depth-first order.

func (*Document) FindSection

func (d *Document) FindSection(id string) *Section

FindSection returns the section with the given ID, or nil if not found.

type ReviewComment

type ReviewComment struct {
	SectionID  string     // Target section ID
	Action     ActionType // Comment action type
	Decoration Decoration // Comment decoration (e.g. non-blocking, blocking)
	Body       string     // Comment body text
	StartLine  int        // 1-based start line (0 = section-level comment)
	EndLine    int        // 1-based end line (0 = single line if StartLine > 0)
	Side       string     // "RIGHT" or "LEFT" (for PR diff comments)
}

ReviewComment is a review comment on a single section.

func (*ReviewComment) FormatLabel

func (c *ReviewComment) FormatLabel() string

FormatLabel returns the formatted label string for display. With decoration: "action (decoration)", without: "action".

func (*ReviewComment) FormatLineRef added in v0.6.0

func (c *ReviewComment) FormatLineRef() string

FormatLineRef returns a line reference string for display. Returns "L10" for single line, "L10-L15" for range, or "" for section-level.

type ReviewResult

type ReviewResult struct {
	Comments []ReviewComment
}

ReviewResult holds the entire review output.

type Section

type Section struct {
	ID        string     // Auto-numbered: "S1", "S1.1", "S2", etc.
	Title     string     // Heading text (without the "## " prefix)
	Level     int        // Heading level (2=##, 3=###, ...)
	Body      string     // Markdown text from heading to next heading
	Children  []*Section // Sub-sections (lower-level headings)
	Parent    *Section   // Parent section (nil for top-level)
	StartLine int        // 1-based line number of heading (0 = not set)
	EndLine   int        // 1-based line number of last body line (0 = not set)
}

Section is a single section in a document, corresponding to one heading.

type Status

type Status string

Status is the exit status of a TUI review session.

const (
	StatusSubmitted Status = "submitted"
	StatusApproved  Status = "approved"
	StatusCancelled Status = "cancelled"
)

type ViewedState

type ViewedState struct {
	Sections map[string]string `json:"sections"` // title -> content hash
}

ViewedState tracks which sections have been viewed and their content hashes.

func LoadViewedState

func LoadViewedState(path string) *ViewedState

LoadViewedState reads a viewed state file. Returns an empty state on any error.

func NewViewedState

func NewViewedState() *ViewedState

NewViewedState creates an empty ViewedState.

func (*ViewedState) IsSectionViewed

func (vs *ViewedState) IsSectionViewed(s *Section) bool

IsSectionViewed returns true if the section's title is tracked and its content hash matches.

func (*ViewedState) MarkViewed

func (vs *ViewedState) MarkViewed(s *Section)

MarkViewed records a section as viewed with its current content hash.

func (*ViewedState) UnmarkViewed

func (vs *ViewedState) UnmarkViewed(s *Section)

UnmarkViewed removes a section's viewed status.

Jump to

Keyboard shortcuts

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