Documentation
¶
Index ¶
- func ExtractJSON(text string) interface{}
- func HTMLToMarkdown(htmlContent string) (string, error)
- func MarkdownToHTML(markdown string) (string, error)
- func ProcessExtract(process *process.Process) interface{}
- func ProcessExtractByType(process *process.Process) interface{}
- func ProcessExtractFirst(process *process.Process) interface{}
- func ProcessExtractJSON(process *process.Process) interface{}
- func ProcessHTMLToMarkdown(process *process.Process) interface{}
- func ProcessMarkdownToHTML(process *process.Process) interface{}
- type CodeBlock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractJSON ¶
func ExtractJSON(text string) interface{}
ExtractJSON extracts the first JSON or YAML block and returns parsed data Supports both JSON and YAML as they are both structured data formats Returns nil if no valid JSON/YAML found
func HTMLToMarkdown ¶
HTMLToMarkdown converts HTML to Markdown Uses goquery-based parsing for reliable HTML handling
func MarkdownToHTML ¶
MarkdownToHTML converts Markdown text to HTML Supports GitHub Flavored Markdown (GFM) extensions including: - Tables - Strikethrough - Task lists - Autolinks
func ProcessExtract ¶
ProcessExtract text.Extract Extracts code blocks from text (typically LLM output) Handles markdown code blocks and direct JSON/HTML/Code detection
Args:
- text string - The text to extract code blocks from
Returns: []CodeBlock - Array of extracted code blocks
Usage:
// Extract all code blocks from LLM response
var blocks = Process("text.Extract", llmResponse)
// Returns: [{"type": "json", "content": "{...}", "data": {...}}, ...]
// Handle markdown wrapped JSON
var blocks = Process("text.Extract", "```json\n{\"key\": \"value\"}\n```")
// Returns: [{"type": "json", "content": "{\"key\": \"value\"}", "data": {"key": "value"}}]
func ProcessExtractByType ¶
ProcessExtractByType text.ExtractByType Extracts all blocks of a specific type
Args:
- text string - The text to extract from
- blockType string - The type to filter by (e.g., "json", "html", "sql")
Returns: []CodeBlock - Array of matching code blocks
Usage:
// Extract only SQL blocks
var sqlBlocks = Process("text.ExtractByType", llmResponse, "sql")
func ProcessExtractFirst ¶
ProcessExtractFirst text.ExtractFirst Extracts and returns only the first code block Useful when you expect only one block (common in LLM responses)
Args:
- text string - The text to extract from
Returns: CodeBlock or null - The first extracted code block
Usage:
var block = Process("text.ExtractFirst", llmResponse)
if (block != null && block.data != null) {
// Use block.data directly
}
func ProcessExtractJSON ¶
ProcessExtractJSON text.ExtractJSON Extracts the first JSON or YAML block and returns parsed data directly Most convenient for LLM responses that return structured data Supports both JSON and YAML formats
Args:
- text string - The text containing JSON or YAML
Returns: parsed data or null
Usage:
// Direct JSON parsing from LLM response
var data = Process("text.ExtractJSON", "```json\n{\"keywords\": [\"a\", \"b\"]}\n```")
// Returns: {"keywords": ["a", "b"]}
// Also works without markdown wrapper
var data = Process("text.ExtractJSON", "{\"keywords\": [\"a\", \"b\"]}")
// Returns: {"keywords": ["a", "b"]}
// YAML is also supported
var data = Process("text.ExtractJSON", "```yaml\nkeywords:\n - a\n - b\n```")
// Returns: {"keywords": ["a", "b"]}
func ProcessHTMLToMarkdown ¶
ProcessHTMLToMarkdown text.HTMLToMarkdown Converts HTML to Markdown Uses goquery-based parsing for reliable HTML handling
Args:
- html string - The HTML content to convert
Returns: string - The converted Markdown text
Usage:
var md = Process("text.HTMLToMarkdown", "<h1>Hello</h1><p>This is <strong>bold</strong> text.</p>")
// Returns: "# Hello\n\nThis is **bold** text."
// With links and images
var md = Process("text.HTMLToMarkdown", "<a href=\"https://example.com\">Link</a>")
// Returns: "[Link](https://example.com)"
func ProcessMarkdownToHTML ¶
ProcessMarkdownToHTML text.MarkdownToHTML Converts Markdown text to HTML Supports GitHub Flavored Markdown (GFM) extensions including: - Tables, Strikethrough, Task lists, Autolinks
Args:
- markdown string - The Markdown text to convert
Returns: string - The converted HTML content
Usage:
var html = Process("text.MarkdownToHTML", "# Hello\n\nThis is **bold** text.")
// Returns: "<h1 id=\"hello\">Hello</h1>\n<p>This is <strong>bold</strong> text.</p>\n"
// With GFM table
var html = Process("text.MarkdownToHTML", "| A | B |\n|---|---|\n| 1 | 2 |")
// Returns: "<table>...</table>"
Types ¶
type CodeBlock ¶
type CodeBlock struct {
Type string `json:"type"` // Language type: json, html, python, sql, etc.
Content string `json:"content"` // Raw content of the code block
Data interface{} `json:"data,omitempty"` // Parsed data (for JSON/YAML)
Start int `json:"start,omitempty"` // Start position in original text
End int `json:"end,omitempty"` // End position in original text
}
CodeBlock represents an extracted code block from text
func Extract ¶
Extract extracts code blocks from text (typically LLM output) It handles: 1. Markdown code blocks (```lang ... ```) 2. Direct JSON/HTML/Code without markdown wrapper 3. JSON is parsed using fault-tolerant parser 4. Fallback: returns original text as type "text" if no blocks detected
Returns a slice of CodeBlock with type, content, and parsed data (for JSON)
func ExtractByType ¶
ExtractByType extracts all blocks of a specific type
func ExtractFirst ¶
ExtractFirst extracts and returns only the first code block Useful when you expect only one block (common in LLM responses)