parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectFileType

func DetectFileType(path string) string

DetectFileType maps file extension to type string. Returns: "md", "mdx", "txt", "tsx", "ts", or "unknown".

func IsBinary

func IsBinary(content []byte) bool

IsBinary checks first 512 bytes for null bytes.

func IsValidUTF8

func IsValidUTF8(content []byte) bool

IsValidUTF8 validates the content is valid UTF-8.

func StripBOM

func StripBOM(content []byte) []byte

StripBOM removes UTF-8 BOM (0xEF, 0xBB, 0xBF) if present.

func StripFrontmatter

func StripFrontmatter(content []byte) ([]byte, string, string)

StripFrontmatter removes YAML frontmatter (--- delimited) and returns the remaining content and extracted title/description if present.

Types

type ComponentType

type ComponentType string
const (
	ComponentTypeDocumentation ComponentType = "documentation"
	ComponentTypeCode          ComponentType = "code"
	ComponentTypeNone          ComponentType = ""
)

type Export

type Export struct {
	Type string `json:"type"`
	Name string `json:"name"`
	Line int    `json:"line"`
}

type Heading

type Heading struct {
	Level int    `json:"level"`
	Text  string `json:"text"`
	Line  int    `json:"line"`
}

type MDXParser

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

func NewMDXParser

func NewMDXParser() *MDXParser

func (*MDXParser) CanParse

func (p *MDXParser) CanParse(path string) bool

func (*MDXParser) Parse

func (p *MDXParser) Parse(_ string, content []byte) (*ParseResult, error)

type MarkdownParser

type MarkdownParser struct{}

func NewMarkdownParser

func NewMarkdownParser() *MarkdownParser

func (*MarkdownParser) CanParse

func (p *MarkdownParser) CanParse(path string) bool

func (*MarkdownParser) Parse

func (p *MarkdownParser) Parse(_ string, content []byte) (*ParseResult, error)

type Outline

type Outline struct {
	Type     OutlineType `json:"type"`
	Headings []Heading   `json:"headings,omitempty"`
	Exports  []Export    `json:"exports,omitempty"`
}

type OutlineType

type OutlineType string
const (
	OutlineTypeHeadings OutlineType = "headings"
	OutlineTypeExports  OutlineType = "exports"
	OutlineTypeNone     OutlineType = "none"
)

type ParseResult

type ParseResult struct {
	Description   string
	ComponentType ComponentType
	Outline       *Outline
	Lines         int
}

type Parser

type Parser interface {
	Parse(path string, content []byte) (*ParseResult, error)
	CanParse(path string) bool
}

Parser extracts description and outline from file content.

type TextParser

type TextParser struct{}

func NewTextParser

func NewTextParser() *TextParser

func (*TextParser) CanParse

func (p *TextParser) CanParse(path string) bool

func (*TextParser) Parse

func (p *TextParser) Parse(_ string, content []byte) (*ParseResult, error)

type TypeScriptParser

type TypeScriptParser struct{}

func NewTypeScriptParser

func NewTypeScriptParser() *TypeScriptParser

func (*TypeScriptParser) CanParse

func (p *TypeScriptParser) CanParse(path string) bool

func (*TypeScriptParser) Parse

func (p *TypeScriptParser) Parse(_ string, content []byte) (*ParseResult, error)

Jump to

Keyboard shortcuts

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