codeblock

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package codeblock provides markdown code block parsing and extraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLanguage

func DetectLanguage(path string) string

DetectLanguage determines the language identifier for a file path.

Types

type CodeBlock

type CodeBlock struct {
	Language   string `json:"language"`              // From fence (python, bash, etc.)
	Content    string `json:"content"`               // The code itself
	StartLine  int    `json:"start_line"`            // Line number in source
	EndLine    int    `json:"end_line"`              // Ending line number
	FilePath   string `json:"file_path,omitempty"`   // Detected file path (if any)
	IsNew      bool   `json:"is_new,omitempty"`      // Appears to be new file vs modification
	SourcePane string `json:"source_pane,omitempty"` // Pane ID where block was found
}

CodeBlock represents a single code block extracted from markdown.

func ExtractFromText

func ExtractFromText(text string) []CodeBlock

ExtractFromText is a convenience function to extract code blocks from text.

func ExtractWithFilter

func ExtractWithFilter(text string, languages []string) []CodeBlock

ExtractWithFilter extracts code blocks filtered by language.

type Extraction

type Extraction struct {
	Source     string      `json:"source"`      // Session/pane identifier
	Blocks     []CodeBlock `json:"blocks"`      // Extracted code blocks
	TotalLines int         `json:"total_lines"` // Total lines in source
}

Extraction contains all code blocks from a source.

type Parser

type Parser struct {
	// Options for parsing
	LanguageFilter []string // Only extract blocks with these languages (empty = all)
}

Parser extracts code blocks from text.

func NewParser

func NewParser() *Parser

NewParser creates a new code block parser.

func (*Parser) Parse

func (p *Parser) Parse(text string) []CodeBlock

Parse extracts code blocks from the given text.

func (*Parser) WithLanguageFilter

func (p *Parser) WithLanguageFilter(langs []string) *Parser

WithLanguageFilter sets languages to filter for.

Jump to

Keyboard shortcuts

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