formatter

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddColon

func AddColon(s string) string

AddColon adds a colon at the end if not already present

func AreChildrenSimilarLength added in v0.2.0

func AreChildrenSimilarLength(children []*workflowy.Item) bool

func Capitalize

func Capitalize(s string) string

Capitalize returns the string with the first letter capitalized

func ChildrenHaveGrandchildren added in v0.2.0

func ChildrenHaveGrandchildren(children []*workflowy.Item) bool

func EndsWithPunctuation added in v0.2.0

func EndsWithPunctuation(s string) bool

func EnsureCapitalized added in v0.2.0

func EnsureCapitalized(s string) string

func EnsurePunctuated added in v0.2.0

func EnsurePunctuated(s string) string

func FormatAsSentence added in v0.2.0

func FormatAsSentence(s string) string

func FormatItemsAsMarkdown added in v0.2.0

func FormatItemsAsMarkdown(items []*workflowy.Item) (string, error)

func HasTag

func HasTag(s string, tag string) bool

HasTag checks if the string contains a tag

func HeaderPrefix

func HeaderPrefix(level int) string

HeaderPrefix returns the markdown header prefix (e.g., "# ", "## ")

func IndentBullet

func IndentBullet(depth int) string

IndentBullet returns the appropriate markdown bullet indentation

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if a node's name is effectively empty (whitespace only)

func IsEmptyBullet added in v0.2.0

func IsEmptyBullet(item *workflowy.Item) bool

func IsListIntroduction added in v0.2.0

func IsListIntroduction(name string) bool

func IsListPattern added in v0.2.0

func IsListPattern(item *workflowy.Item) bool

func JoinParagraphs

func JoinParagraphs(paragraphs []string) string

JoinParagraphs joins multiple paragraph strings with a space

func Punctuate

func Punctuate(s string) string

Punctuate adds a period at the end if the string doesn't already end with punctuation

func StripTag

func StripTag(s string, tag string) string

StripTag removes a tag from the string (e.g., "#exclude", "#h1")

func Uppercase

func Uppercase(s string) string

Uppercase returns the string in all uppercase

func WordCount added in v0.2.0

func WordCount(s string) int

Types

type Config

type Config struct {
	Name string

	// Header rules
	H1Uppercase bool
	H2Uppercase bool
	H3Uppercase bool
	H4Uppercase bool
	H5Uppercase bool
	H6Uppercase bool

	// Paragraph rules
	ParagraphCapitalize     bool
	ParagraphPunctuate      bool
	JoinBulletsAsParagraphs bool // Join consecutive bullets as paragraphs until empty bullet

	// Punctuation rules
	AddColonBeforeLists bool // Add colon at end of paragraph node with bullet children

	// Tag recognition
	ExcludeTag string // default: "#exclude"
	H1Tag      string // default: "#h1"
	H2Tag      string // default: "#h2"
	H3Tag      string // default: "#h3"
	H4Tag      string // default: "#h4"
	H5Tag      string // default: "#h5"
	H6Tag      string // default: "#h6"

	// Fallback behavior when no layoutMode
	UseDepthForHeaders bool // depth 1=h1, 2=h2, 3=h3, etc.
}

Config holds formatter configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default formatter configuration

type DefaultFormatter

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

DefaultFormatter implements the Formatter interface with standard rules

func NewDefaultFormatter

func NewDefaultFormatter() *DefaultFormatter

NewDefaultFormatter creates a new formatter with default configuration

func NewFormatter

func NewFormatter(config *Config) *DefaultFormatter

NewFormatter creates a new formatter with custom configuration

func (*DefaultFormatter) FormatNode

func (f *DefaultFormatter) FormatNode(item *workflowy.Item, depth int) (string, error)

FormatNode converts a single node and its children to markdown

func (*DefaultFormatter) FormatTree

func (f *DefaultFormatter) FormatTree(items []*workflowy.Item) (string, error)

FormatTree converts entire tree to markdown

func (*DefaultFormatter) GetLayoutMode

func (f *DefaultFormatter) GetLayoutMode(item *workflowy.Item, depth int) LayoutMode

GetLayoutMode determines effective layoutMode considering tags, depth, config

func (*DefaultFormatter) ShouldExclude

func (f *DefaultFormatter) ShouldExclude(item *workflowy.Item) bool

ShouldExclude checks if node should be excluded from output

type Formatter

type Formatter interface {
	// FormatTree converts entire tree to markdown
	FormatTree(items []*workflowy.Item) (string, error)

	// FormatNode converts a single node to markdown
	FormatNode(item *workflowy.Item, depth int) (string, error)

	// ShouldExclude checks if node should be excluded from output
	ShouldExclude(item *workflowy.Item) bool

	// GetLayoutMode determines effective layoutMode considering tags, depth, config
	GetLayoutMode(item *workflowy.Item, depth int) LayoutMode
}

Formatter defines the interface for converting Workflowy items to markdown

type LayoutMode

type LayoutMode string

LayoutMode represents the type of content layout

const (
	LayoutH1      LayoutMode = "h1"
	LayoutH2      LayoutMode = "h2"
	LayoutH3      LayoutMode = "h3"
	LayoutH4      LayoutMode = "h4"
	LayoutH5      LayoutMode = "h5"
	LayoutH6      LayoutMode = "h6"
	LayoutP       LayoutMode = "p"
	LayoutBullets LayoutMode = "bullets"
	LayoutTodo    LayoutMode = "todo"
)

type MarkdownConfig added in v0.2.0

type MarkdownConfig struct {
	ExcludeTag string
	H1Tag      string
	H2Tag      string
	H3Tag      string
	PTag       string
	ListTag    string
}

func DefaultMarkdownConfig added in v0.2.0

func DefaultMarkdownConfig() *MarkdownConfig

type MarkdownFormatter added in v0.2.0

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

func NewMarkdownFormatter added in v0.2.0

func NewMarkdownFormatter() *MarkdownFormatter

func NewMarkdownFormatterWithConfig added in v0.2.0

func NewMarkdownFormatterWithConfig(config *MarkdownConfig) *MarkdownFormatter

func (*MarkdownFormatter) FormatTree added in v0.2.0

func (f *MarkdownFormatter) FormatTree(items []*workflowy.Item) (string, error)

Jump to

Keyboard shortcuts

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