parser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitRichTextPer

func SplitRichTextPer(segments []RichTextSegment, count int) [][]RichTextSegment

SplitRichTextPer splits rich text segments into chunks where each chunk's total rune count does not exceed the given limit. Formatting is preserved across split boundaries by splitting individual segments as needed. It prefers splitting at word boundaries (spaces) similar to SplitPer.

func StripInlineFormatting

func StripInlineFormatting(s string) string

StripInlineFormatting removes markdown inline formatting from text and decodes HTML entities.

Types

type Blockquote

type Blockquote struct {
	Lines   []string
	Chapter int
	Section int
	Term    int
	Line    int
}

Blockquote represents a Markdown blockquote (lines starting with >).

func (Blockquote) RowNum

func (b Blockquote) RowNum() int

RowNum returns the number of Excel rows needed (lines + top/bottom padding).

func (Blockquote) Text

func (b Blockquote) Text() string

Text returns all blockquote lines joined with newlines.

func (Blockquote) ToString

func (b Blockquote) ToString() string

func (Blockquote) Type

func (Blockquote) Type() ComponentType

type Code

type Code struct {
	Codes   []string
	Lang    string
	Chapter int
	Section int
	Term    int
	Line    int
}

func (Code) RowNum

func (c Code) RowNum() int

RowNum returns the number of Excel rows needed (lines + top/bottom padding).

func (Code) Text

func (c Code) Text() string

Text returns all code lines joined with newlines.

func (Code) ToString

func (c Code) ToString() string

func (Code) Type

func (Code) Type() ComponentType

type Component

type Component interface {
	ToString() string
	Type() ComponentType
}

Component is the interface implemented by all parsed Markdown elements.

func Parse

func Parse(text string) []Component

Parse converts Markdown text into a slice of Components.

type ComponentType

type ComponentType int
const (
	TypeH1 ComponentType = iota
	TypeH2
	TypeH3
	TypeH4
	TypeH5
	TypeH6
	TypePlainText
	TypeTable
	TypeImage
	TypeCode
	TypeList
	TypeHorizontalRule
	TypeBlockquote
)

func (ComponentType) String

func (t ComponentType) String() string

type H1

type H1 struct {
	Text    string
	Chapter int
	Line    int
}

func (H1) ToString

func (h H1) ToString() string

func (H1) Type

func (H1) Type() ComponentType

type H2

type H2 struct {
	Text    string
	Chapter int
	Section int
	Line    int
}

func (H2) ToString

func (h H2) ToString() string

func (H2) Type

func (H2) Type() ComponentType

type H3

type H3 struct {
	Text    string
	Chapter int
	Section int
	Term    int
	Line    int
}

func (H3) ToString

func (h H3) ToString() string

func (H3) Type

func (H3) Type() ComponentType

type H4

type H4 struct {
	Text    string
	Chapter int
	Section int
	Term    int
	Item    int
	Line    int
}

func (H4) ToString

func (h H4) ToString() string

func (H4) Type

func (H4) Type() ComponentType

type H5

type H5 struct {
	Text    string
	Chapter int
	Section int
	Term    int
	Item    int
	SubItem int
	Line    int
}

func (H5) ToString

func (h H5) ToString() string

func (H5) Type

func (H5) Type() ComponentType

type H6

type H6 struct {
	Text    string
	Chapter int
	Section int
	Term    int
	Item    int
	SubItem int
	Detail  int
	Line    int
}

func (H6) ToString

func (h H6) ToString() string

func (H6) Type

func (H6) Type() ComponentType

type HorizontalRule

type HorizontalRule struct {
	Chapter int
	Section int
	Term    int
	Line    int
}

HorizontalRule represents a Markdown horizontal rule (---, ***, ___).

func (HorizontalRule) ToString

func (h HorizontalRule) ToString() string

func (HorizontalRule) Type

type Image

type Image struct {
	Path    string
	Alt     string
	Chapter int
	Section int
	Term    int
	Line    int
}

func (Image) ToString

func (i Image) ToString() string

func (Image) Type

func (Image) Type() ComponentType

type LinkInfo

type LinkInfo struct {
	Text string
	URL  string
}

LinkInfo holds a parsed Markdown link's text and URL.

func ExtractLinks(s string) []LinkInfo

ExtractLinks returns all Markdown links and autolinks found in the string, sorted by their position in the source text.

type List

type List struct {
	Items   []ListItem
	Chapter int
	Section int
	Term    int
	Line    int
}

List represents a bullet or numbered list.

func (List) ToString

func (l List) ToString() string

func (List) Type

func (List) Type() ComponentType

type ListItem

type ListItem struct {
	Text     string
	RichText []RichTextSegment
	Ordered  bool
	Checked  *bool
	Number   int // 1-based number for ordered lists
	Indent   int // nesting level (0-based)
}

ListItem represents a single item in a list.

type PlainText

type PlainText struct {
	Text     string
	Links    []LinkInfo
	RichText []RichTextSegment
	Chapter  int
	Section  int
	Term     int
	Line     int
}

func (PlainText) RuneCount

func (p PlainText) RuneCount() int

RuneCount returns the number of UTF-8 characters.

func (PlainText) SplitPer

func (p PlainText) SplitPer(count int) []string

SplitPer splits text into chunks of the given rune count. It prefers splitting at word boundaries (spaces) to avoid breaking words.

func (PlainText) ToString

func (p PlainText) ToString() string

func (PlainText) Type

func (PlainText) Type() ComponentType

type Position

type Position struct {
	Chapter int
	Section int
	Term    int
	Line    int
}

Position tracks the location context of a component.

type RichTextSegment

type RichTextSegment struct {
	Text   string
	Bold   bool
	Strike bool
	Italic bool
	Code   bool
}

RichTextSegment represents a segment of text with optional bold/italic/strikethrough/code formatting.

func ParseRichText

func ParseRichText(s string) []RichTextSegment

ParseRichText parses inline bold/italic formatting and returns segments. Inline code regions (backtick-delimited) are protected from emphasis parsing.

type Table

type Table struct {
	Header         []string
	HeaderRichText [][]RichTextSegment
	Data           [][]string
	DataRichText   [][][]RichTextSegment
	Alignments     []string
	Chapter        int
	Section        int
	Term           int
	Line           int
}

func (Table) MaxColDataBytes

func (t Table) MaxColDataBytes() []int

MaxColDataBytes returns the max byte length of each column's data.

func (Table) ToString

func (t Table) ToString() string

func (Table) Type

func (Table) Type() ComponentType

Jump to

Keyboard shortcuts

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