Documentation
¶
Index ¶
- Constants
- Variables
- func CSVForceQuote(field string) string
- func CSVQuoteEscape(field string) string
- func Capitalize(table *Table)
- func CopyReaderToWriter(reader io.Reader, writer io.Writer) error
- func CreateMCPServer(registry *FormatRegistry) *mcp.Server
- func DeduplicateRows(table *Table)
- func DeleteEmptyRows(table *Table)
- func DetectTableFormatByData(reader io.Reader) (string, error)
- func DetectTableFormatByExtension(filename string) string
- func FormatExists(format string) bool
- func GetAllFormats() []string
- func GetProjectRootPath() (string, error)
- func HtmlEscape(s string) string
- func InferPrintType(s string) string
- func InferType(value string) interface{}
- func LaTeXEscape(s string) string
- func LaTeXUnescape(s string) string
- func Lowercase(table *Table)
- func MarkdownEscape(s string) string
- func MarkdownUnescape(s string) string
- func MssqlIdentifierEscape(s string) string
- func OracleIdentifierEscape(s string) string
- func PerformConversionWithRegistry(registry *FormatRegistry, cfg *Config) error
- func PostgreSQLIdentifierEscape(s string) string
- func SQLIdentifierEscape(s string) string
- func SQLValueEscape(s string) string
- func ShowFormatHelp(format string)
- func ShowFormatsHelp()
- func Transpose(table *Table)
- func Uppercase(table *Table)
- func Usage()
- func ValidateIO(cfg *Config) error
- type BatchFile
- type Config
- func (c *Config) ApplyTransformations(table *Table)
- func (c *Config) GetBatchFiles() ([]BatchFile, error)
- func (c *Config) GetExtensionBool(key string, defaultValue bool) bool
- func (c *Config) GetExtensionInt(key string, defaultValue int) int
- func (c *Config) GetExtensionString(key string, defaultValue string) string
- type ConversionError
- type ConvertTableArgs
- type ConvertTableResult
- type FormatParam
- type FormatRegistry
- func (fr *FormatRegistry) GetMarshalFunc(format string) (MarshalFunc, bool)
- func (fr *FormatRegistry) GetUnmarshalFunc(format string) (UnmarshalFunc, bool)
- func (fr *FormatRegistry) RegisterFormat(name string, unmarshal UnmarshalFunc, marshal MarshalFunc)
- func (fr *FormatRegistry) RegisterFormatAlias(alias, format string)
- func (fr *FormatRegistry) RegisterWriteOnlyFormat(name string, marshal MarshalFunc)
- type GetFormatsArgs
- type GetFormatsResult
- type MCPFormatParam
- type MCPServerContext
- func (s *MCPServerContext) HandleConvertTable(ctx context.Context, req *mcp.CallToolRequest, args ConvertTableArgs) (*mcp.CallToolResult, ConvertTableResult, error)
- func (s *MCPServerContext) HandleGetFormats(ctx context.Context, req *mcp.CallToolRequest, args GetFormatsArgs) (*mcp.CallToolResult, GetFormatsResult, error)
- type MarshalFunc
- type ParseError
- type Table
- type UnmarshalFunc
Constants ¶
const ( TableFormatExcel = "excel" TableFormatCSV = "csv" TableFormatMarkdown = "markdown" TableFormatHTML = "html" TableFormatMediaWiki = "mediawiki" TableFormatLatex = "latex" TableFormatJSON = "json" TableFormatXML = "xml" TableFormatASCII = "ascii" TableFormatSQL = "sql" TableFormatTracWiki = "tracwiki" TableFormatTWiki = "twiki" )
Variables ¶
var FormatParamsRegistry = map[string][]FormatParam{
"ascii": {
{Name: "style", DefaultValue: "box", AllowedValues: "box, plus(+), dot(·), bubble(◌)", Description: "Table Style"},
},
"csv": {
{Name: "first-column-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first column as headers"},
{Name: "bom", DefaultValue: "false", AllowedValues: "", Description: "Add Byte Order Mark"},
{Name: "delimiter", DefaultValue: ",", AllowedValues: "COMMA, TAB, SEMICOLON, PIPE, SLASH, HASH", Description: "Value Delimiter"},
},
"excel": {
{Name: "first-column-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first column as headers"},
{Name: "sheet-name", DefaultValue: "Sheet1", AllowedValues: "", Description: "Excel Sheet Name"},
{Name: "auto-width", DefaultValue: "false", AllowedValues: "true, false", Description: "Auto Width"},
{Name: "text-format", DefaultValue: "true", AllowedValues: "true, false", Description: "force text format"},
},
"xlsx": {
{Name: "first-column-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first column as headers"},
{Name: "sheet-name", DefaultValue: "Sheet1", AllowedValues: "", Description: "Excel Sheet Name"},
{Name: "auto-width", DefaultValue: "false", AllowedValues: "true, false", Description: "Auto Width"},
{Name: "text-format", DefaultValue: "true", AllowedValues: "true, false", Description: "force text format"},
},
"html": {
{Name: "first-column-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first column as headers"},
{Name: "div", DefaultValue: "false", AllowedValues: "true, false", Description: "Convert into div table"},
{Name: "minify", DefaultValue: "false", AllowedValues: "true, false", Description: "Minify HTML table"},
{Name: "thead", DefaultValue: "false", AllowedValues: "true, false", Description: "Include thead and tbody tags"},
},
"json": {
{Name: "format", DefaultValue: "object", AllowedValues: "object, 2d, column, keyed", Description: "JSON Format"},
{Name: "minify", DefaultValue: "false", AllowedValues: "true, false", Description: "Minify JSON"},
{Name: "parsing-json", DefaultValue: "false", AllowedValues: "true, false", Description: "Parsing JSON"},
},
"jsonl": {
{Name: "parsing-json", DefaultValue: "false", AllowedValues: "true, false", Description: "Parsing JSON"},
},
"jsonlines": {
{Name: "parsing-json", DefaultValue: "false", AllowedValues: "true, false", Description: "Parsing JSON"},
},
"latex": {
{Name: "bold-first-column", DefaultValue: "false", AllowedValues: "true, false", Description: "Bold first column"},
{Name: "bold-first-row", DefaultValue: "false", AllowedValues: "true, false", Description: "Bold first row"},
{Name: "borders", DefaultValue: "1111,1111", AllowedValues: "1111,1111, 1101,1101, 0000,1101, 1111,0100, 0000,0100, 0000,0000", Description: "Table Border"},
{Name: "caption", DefaultValue: "", AllowedValues: "", Description: "Table Caption"},
{Name: "escape", DefaultValue: "true", AllowedValues: "true, false", Description: "Escape LaTeX table"},
{Name: "ht", DefaultValue: "false", AllowedValues: "true, false", Description: "Place here or top of page"},
{Name: "label", DefaultValue: "", AllowedValues: "", Description: "Table Label"},
{Name: "location", DefaultValue: "above", AllowedValues: "above, below", Description: "Caption Location"},
{Name: "mwe", DefaultValue: "false", AllowedValues: "true, false", Description: "Minimal working example"},
{Name: "table-align", DefaultValue: "centering", AllowedValues: "centering, raggedleft, raggedright", Description: "Table Alignment"},
{Name: "text-align", DefaultValue: "l", AllowedValues: "l, c, r", Description: "Text Alignment"},
},
"markdown": {
{Name: "align", DefaultValue: "l", AllowedValues: "l, c, r", Description: "Text Alignment, columns seperate by comma"},
{Name: "bold-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Table Header Bold"},
{Name: "bold-first-column", DefaultValue: "false", AllowedValues: "true, false", Description: "Bold first column"},
{Name: "escape", DefaultValue: "true", AllowedValues: "true, false", Description: "Escape Markdown table"},
{Name: "pretty", DefaultValue: "true", AllowedValues: "true, false", Description: "Pretty-print Markdown"},
},
"md": {
{Name: "align", DefaultValue: "l", AllowedValues: "l, c, r", Description: "Text Alignment, columns seperate by comma"},
{Name: "bold-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Table Header Bold"},
{Name: "bold-first-column", DefaultValue: "false", AllowedValues: "true, false", Description: "Bold first column"},
{Name: "escape", DefaultValue: "true", AllowedValues: "true, false", Description: "Escape Markdown table"},
{Name: "pretty", DefaultValue: "true", AllowedValues: "true, false", Description: "Pretty-print Markdown"},
},
"mediawiki": {
{Name: "first-row-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first row as headers"},
{Name: "minify", DefaultValue: "false", AllowedValues: "true, false", Description: "Minify MediaWiki table"},
{Name: "sort", DefaultValue: "false", AllowedValues: "true, false", Description: "Make table sortable in Wikipedia"},
},
"mysql": {
{Name: "style", DefaultValue: "box", AllowedValues: "box", Description: "MySQL table style (box format)"},
},
"twiki": {
{Name: "first-row-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first row as headers"},
},
"tracwiki": {
{Name: "first-row-header", DefaultValue: "false", AllowedValues: "true, false", Description: "Use first row as headers"},
},
"tmpl": {
{Name: "template", DefaultValue: "", AllowedValues: "", Description: "Template file path"},
},
"template": {
{Name: "template", DefaultValue: "", AllowedValues: "", Description: "Template file path"},
},
"sql": {
{Name: "one-insert", DefaultValue: "false", AllowedValues: "true, false", Description: "Insert multiple rows at once"},
{Name: "replace", DefaultValue: "false", AllowedValues: "true, false", Description: "Use REPLACE instead of INSERT"},
{Name: "dialect", DefaultValue: "mysql", AllowedValues: "none, mysql, oracle, mssql, postgresql", Description: "identity escape SQL Dialect, none for no escape"},
{Name: "table", DefaultValue: "", AllowedValues: "", Description: "Table Name"},
},
"xml": {
{Name: "minify", DefaultValue: "false", AllowedValues: "true, false", Description: "Minify XML"},
{Name: "root-element", DefaultValue: "dataset", AllowedValues: "string", Description: "Root Element Tag"},
{Name: "row-element", DefaultValue: "record", AllowedValues: "string", Description: "Row Element Tag"},
{Name: "declaration", DefaultValue: "true", AllowedValues: "true, false", Description: "Include XML Declaration"},
},
}
FormatParamsRegistry maps format names to their supported extension parameters
var GlobalTransformParams = []FormatParam{
{Name: "transpose", DefaultValue: "false", AllowedValues: "true, false", Description: "Transpose the table (swap rows and columns)"},
{Name: "delete-empty", DefaultValue: "false", AllowedValues: "true, false", Description: "Remove empty rows from the table"},
{Name: "deduplicate", DefaultValue: "false", AllowedValues: "true, false", Description: "Remove duplicate rows"},
{Name: "uppercase", DefaultValue: "false", AllowedValues: "true, false", Description: "Convert all text to UPPERCASE"},
{Name: "lowercase", DefaultValue: "false", AllowedValues: "true, false", Description: "Convert all text to lowercase"},
{Name: "capitalize", DefaultValue: "false", AllowedValues: "true, false", Description: "Capitalize the first letter of each cell"},
}
GlobalTransformParams are transformation parameters available for all formats
Functions ¶
func CSVForceQuote ¶
CSVForceQuote returns a string with quotes
func CSVQuoteEscape ¶
CSVQuoteEscape function is used to escape quotes in CSV fields
func Capitalize ¶
func Capitalize(table *Table)
Capitalize converts the first letter of each cell value to uppercase
func CopyReaderToWriter ¶
CopyReaderToWriter is a utility function that copies data from reader to writer Useful for passthrough scenarios or testing
func CreateMCPServer ¶
func CreateMCPServer(registry *FormatRegistry) *mcp.Server
CreateMCPServer creates the MCP server with tableconvert tools
func DeduplicateRows ¶
func DeduplicateRows(table *Table)
DeduplicateRows removes duplicate rows (rows with identical values in all columns)
func DeleteEmptyRows ¶
func DeleteEmptyRows(table *Table)
DeleteEmptyRows removes rows that are completely empty (all cells are empty strings)
func DetectTableFormatByExtension ¶
DetectTableFormatByExtension detects the table format by the file extension.
func FormatExists ¶
FormatExists checks if a format is supported
func GetAllFormats ¶
func GetAllFormats() []string
GetAllFormats returns a list of all supported formats
func GetProjectRootPath ¶
func HtmlEscape ¶
func InferPrintType ¶
func InferType ¶
func InferType(value string) interface{}
InferType attempts to convert a string value to a more specific type (bool, int64, float64, nil) If no conversion is successful, it returns the original string.
func LaTeXEscape ¶
LaTeXEscape escapes special LaTeX characters in the content
func LaTeXUnescape ¶
func MarkdownEscape ¶
func MarkdownUnescape ¶
func MssqlIdentifierEscape ¶
func OracleIdentifierEscape ¶
func PerformConversionWithRegistry ¶
func PerformConversionWithRegistry(registry *FormatRegistry, cfg *Config) error
PerformConversionWithRegistry performs conversion using a registry of format functions
func SQLIdentifierEscape ¶
SQLIdentifierEscape mysql identifier escape
func SQLValueEscape ¶
SQLValueEscape values for SQL insertion (handle quotes, NULLs, etc.)
func ShowFormatHelp ¶
func ShowFormatHelp(format string)
ShowFormatHelp displays help for a specific format
func ShowFormatsHelp ¶
func ShowFormatsHelp()
ShowFormatsHelp displays help for all supported formats and their parameters
func Transpose ¶
func Transpose(table *Table)
Transpose converts columns to rows and rows to columns. The first column of the new table contains the original headers. The first row of the new table contains "" and then "Row_1", "Row_2", etc.
func ValidateIO ¶
ValidateIO validates that reader and writer are properly set
Types ¶
type Config ¶
type Config struct {
From string
To string
File string
Result string
Verbose bool
MCPMode bool
Batch string // Batch mode pattern (e.g., "*.csv")
Recursive bool // Recursive directory traversal
OutputDir string // Output directory for batch mode
Reader io.Reader
Writer io.Writer
Extension map[string]string
}
Config holds configuration, reader/writer, and extension parameters
func ParseConfig ¶
ParseConfig parses arguments in format "--key=value" or "--key value" and returns a key-value map
func (*Config) ApplyTransformations ¶
ApplyTransformations applies data transformations to the table based on configuration. Transformations are applied in a specific order: transpose -> delete-empty -> deduplicate -> case transformations
func (*Config) GetBatchFiles ¶
GetBatchFiles expands the batch pattern and returns a list of files to process
func (*Config) GetExtensionBool ¶
GetExtensionBool gets a boolean value from Extension with default
func (*Config) GetExtensionInt ¶
GetExtensionInt gets an int value from Extension with default
type ConversionError ¶
ConversionError represents a conversion error with context
func (*ConversionError) Error ¶
func (e *ConversionError) Error() string
func (*ConversionError) Unwrap ¶
func (e *ConversionError) Unwrap() error
type ConvertTableArgs ¶
type ConvertTableArgs struct {
From string `json:"from" jsonschema:"source format (e.g., csv, mysql, markdown)"`
To string `json:"to" jsonschema:"target format (e.g., json, csv, markdown)"`
Input string `json:"input" jsonschema:"table data as a string"`
Options map[string]string `json:"options,omitempty" jsonschema:"format-specific options as key-value pairs"`
Transformations map[string]bool `` /* 141-byte string literal not displayed */
}
ConvertTableArgs represents the arguments for the convert_table tool
type ConvertTableResult ¶
type ConvertTableResult struct {
Output string `json:"output"`
Error string `json:"error,omitempty"`
}
ConvertTableResult represents the result of a conversion
type FormatParam ¶
FormatParam represents a single format-specific parameter
func GetFormatParams ¶
func GetFormatParams(format string) []FormatParam
GetFormatParams returns the parameters for a specific format
type FormatRegistry ¶
type FormatRegistry struct {
UnmarshalMap map[string]UnmarshalFunc
MarshalMap map[string]MarshalFunc
}
FormatRegistry holds format-specific unmarshal and marshal functions
func NewFormatRegistry ¶
func NewFormatRegistry() *FormatRegistry
NewFormatRegistry creates a new format registry
func (*FormatRegistry) GetMarshalFunc ¶
func (fr *FormatRegistry) GetMarshalFunc(format string) (MarshalFunc, bool)
GetMarshalFunc returns the marshal function for a format
func (*FormatRegistry) GetUnmarshalFunc ¶
func (fr *FormatRegistry) GetUnmarshalFunc(format string) (UnmarshalFunc, bool)
GetUnmarshalFunc returns the unmarshal function for a format
func (*FormatRegistry) RegisterFormat ¶
func (fr *FormatRegistry) RegisterFormat(name string, unmarshal UnmarshalFunc, marshal MarshalFunc)
RegisterFormat adds a format's unmarshal and marshal functions to the registry
func (*FormatRegistry) RegisterFormatAlias ¶
func (fr *FormatRegistry) RegisterFormatAlias(alias, format string)
RegisterFormatAlias adds an alias for an existing format
func (*FormatRegistry) RegisterWriteOnlyFormat ¶
func (fr *FormatRegistry) RegisterWriteOnlyFormat(name string, marshal MarshalFunc)
RegisterWriteOnlyFormat registers a format that only supports writing (no Unmarshal)
type GetFormatsArgs ¶
type GetFormatsArgs struct {
Format string `json:"format,omitempty" jsonschema:"specific format to get help for"`
}
GetFormatsArgs represents the arguments for the get_formats tool
type GetFormatsResult ¶
type GetFormatsResult struct {
Formats map[string]string `json:"formats"`
Parameters map[string][]FormatParam `json:"parameters,omitempty"`
}
GetFormatsResult represents the result of getting format information
type MCPFormatParam ¶
type MCPFormatParam struct {
Name string `json:"name"`
DefaultValue string `json:"default_value"`
AllowedValues string `json:"allowed_values"`
Description string `json:"description"`
}
MCPFormatParam represents a format-specific parameter for MCP (compatible with FormatParam)
type MCPServerContext ¶
type MCPServerContext struct {
Registry *FormatRegistry
}
MCPServerContext holds the registry for MCP handlers
func NewMCPServerContext ¶
func NewMCPServerContext(registry *FormatRegistry) *MCPServerContext
NewMCPServerContext creates a new MCP server context with a format registry
func (*MCPServerContext) HandleConvertTable ¶
func (s *MCPServerContext) HandleConvertTable(ctx context.Context, req *mcp.CallToolRequest, args ConvertTableArgs) (*mcp.CallToolResult, ConvertTableResult, error)
HandleConvertTable handles the convert_table tool call
func (*MCPServerContext) HandleGetFormats ¶
func (s *MCPServerContext) HandleGetFormats(ctx context.Context, req *mcp.CallToolRequest, args GetFormatsArgs) (*mcp.CallToolResult, GetFormatsResult, error)
HandleGetFormats handles the get_formats tool call (static version)
type MarshalFunc ¶
MarshalFunc is a function type that converts a Table to output format
type ParseError ¶
ParseError represents an error during parsing.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type UnmarshalFunc ¶
UnmarshalFunc is a function type that parses input data into a Table