API Reference
The HTML library provides the following core components:
| Component | Description | Docs |
|---|---|---|
| Package functions | Convenience functions, suited for one-off calls | Package Functions |
| Processor | Processor instance, reusing resources and cache | Processor |
| Config | Configuration struct and presets | Config |
| Output Formats | Markdown and JSON output | Output Formats |
| Link Extraction | Standalone link extraction API | Link Extraction |
| Batch Processing | Concurrent batch extraction | Batch Processing |
| Interfaces | Extractor, StatsProvider, etc. | Interface Definitions |
| Types | Result, ImageInfo, etc. | Type Definitions |
| Constants & Errors | Defaults, sentinel errors | Constants & Errors |
| Security | Sanitization, input limits, path safety | Security |
| Audit System | Audit pipeline and Sinks | Audit System |
API Overview
Two Calling Modes
text
┌─────────────────────────────────────────┐
│ Package functions (convenience) │
│ html.Extract(data) → *Result, error │
│ Reuses Processor via sync.Pool │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────┐
│ Processor (instance mode) │
│ p, _ := html.New(cfg) │
│ defer p.Close() │
│ result, err := p.Extract(data) │
│ ✓ cache reuse ✓ stats ✓ audit log │
└─────────────────────────────────────────┘Function Naming Rules
| Pattern | Naming | Example |
|---|---|---|
| Base | Extract* | Extract, ExtractText |
| From file | Extract*FromFile | ExtractFromFile |
| With context | Extract*WithContext | ExtractWithContext |
| From file + context | Extract*FromFileWithContext | ExtractFromFileWithContext |
Module Information
- Module path:
github.com/cybergodev/html - Go version: 1.25+
- Dependencies:
golang.org/x/net,golang.org/x/text
Core Type Quick Reference
| Type | Description | Docs |
|---|---|---|
Result | Extraction result (text, title, images, links, statistics) | Type Definitions |
Config | Unified config struct and presets | Config |
Processor | Core processing engine with caching and statistics | Processor |
Statistics | Processing statistics (hits, errors, average time) | Type Definitions |
BatchResult | Batch extraction result | Batch Processing |
LinkResource | Link resource (with type classification) | Link Extraction |
AuditEntry | Audit log entry | Audit System |
Interface Quick Reference
| Interface | Description | Docs |
|---|---|---|
Extractor | Main extraction interface, for decoupling and mocking | Interface Definitions |
StatsProvider | Statistics query interface | Interface Definitions |
Scorer | Custom content scoring algorithm | Interface Definitions |
ContentNode | Node abstraction, hiding the internal parser type | Interface Definitions |
AuditSink | Audit log output target (custom backend) | Interface Definitions |
Preset Configurations
Start from a preset and fine-tune as needed; avoid hand-writing zero-value configs (the Config zero value is not directly usable):
| Preset | Purpose |
|---|---|
DefaultConfig() | General scenarios, balancing features and performance |
TextOnlyConfig() | Extract plain text only, disable all media, highest performance |
MarkdownConfig() | Output inline Markdown-format images and links |
HighSecurityConfig() | High-security environments: tighter limits, shorter timeouts, audit enabled |
See Config for details.
Find an API by Scenario
Common needs and their entry points:
| Need | Recommended API | Docs |
|---|---|---|
| Plain text only | ExtractText / Processor.ExtractText | Package Functions |
| Markdown output | ExtractToMarkdown or MarkdownConfig() | Output Formats |
| Extract all link resources | ExtractAllLinks | Link Extraction |
| Concurrent batch processing | ExtractBatch / ExtractBatchFiles | Batch Processing |
| Custom content identification | Scorer interface + Config.Scorer | Interface Definitions |
| Audit security events | AuditConfig + AuditSink | Audit System |
| High-frequency reuse + cache | html.New() long-lived Processor | Processor |