mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-01-16 09:02:10 +01:00
Introduces `context.Context` to the `FetchCourse` method and its call chain, allowing for cancellable network requests and timeouts. This improves application robustness when fetching remote course data. A new configuration package centralizes application settings, loading them from environment variables with sensible defaults for base URL, request timeout, and logging. Standard `log` and `fmt` calls are replaced with a structured logging system built on `slog`, supporting both JSON and human-readable text formats. This change also includes: - Extensive benchmarks and example tests. - Simplified Go doc comments across several packages. BREAKING CHANGE: The `NewArticulateParser` constructor signature has been updated to accept a logger, base URL, and timeout, which are now supplied via the new configuration system.
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
// Package exporters provides implementations of the Exporter interface
|
|
// for converting Articulate Rise courses into various file formats.
|
|
package exporters
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/kjanat/articulate-parser/internal/interfaces"
|
|
"github.com/kjanat/articulate-parser/internal/services"
|
|
)
|
|
|
|
// Factory implements the ExporterFactory interface.
|
|
// It creates appropriate exporter instances based on the requested format.
|
|
type Factory struct {
|
|
// htmlCleaner is used by exporters to convert HTML content to plain text
|
|
htmlCleaner *services.HTMLCleaner
|
|
}
|
|
|
|
// NewFactory creates a new exporter factory.
|
|
// It takes an HTMLCleaner instance that will be passed to the exporters
|
|
// created by this factory.
|
|
//
|
|
// Parameters:
|
|
// - htmlCleaner: Service for cleaning HTML content in course data
|
|
//
|
|
// Returns:
|
|
// - An implementation of the ExporterFactory interface
|
|
func NewFactory(htmlCleaner *services.HTMLCleaner) interfaces.ExporterFactory {
|
|
return &Factory{
|
|
htmlCleaner: htmlCleaner,
|
|
}
|
|
}
|
|
|
|
// CreateExporter creates an exporter for the specified format.
|
|
// Format strings are case-insensitive (e.g., "markdown", "DOCX").
|
|
func (f *Factory) CreateExporter(format string) (interfaces.Exporter, error) {
|
|
switch strings.ToLower(format) {
|
|
case "markdown", "md":
|
|
return NewMarkdownExporter(f.htmlCleaner), nil
|
|
case "docx", "word":
|
|
return NewDocxExporter(f.htmlCleaner), nil
|
|
case "html", "htm":
|
|
return NewHTMLExporter(f.htmlCleaner), nil
|
|
default:
|
|
return nil, fmt.Errorf("unsupported export format: %s", format)
|
|
}
|
|
}
|
|
|
|
// SupportedFormats returns a list of all supported export formats,
|
|
// including both primary format names and their aliases.
|
|
func (f *Factory) SupportedFormats() []string {
|
|
return []string{"markdown", "md", "docx", "word", "html", "htm"}
|
|
}
|