Documentation
¶
Overview ¶
Package markup renders markup files to HTML.
Given a filename and its contents, it picks the right renderer and produces HTML. Markdown and Org-mode are rendered natively in Go. Other formats shell out to external tools (asciidoctor, rst2html, pod2html, etc).
The library has no global state. Construct a Registry, configure it, and call Render. Post-processing (sanitization, link rewriting, mention linking) is the consumer's responsibility.
Index ¶
- Constants
- Variables
- type ExternalConfig
- type ExternalRenderer
- type Format
- type InputMode
- type MarkdownRenderer
- type OrgRenderer
- type RSTRenderer
- type Registry
- func (r *Registry) Register(format Format, renderer Renderer, extensions ...string)
- func (r *Registry) RegisterFilename(format Format, renderer Renderer, filenames ...string)
- func (r *Registry) Render(filename string, content []byte) (Result, error)
- func (r *Registry) SetMaxInputSize(n int)
- func (r *Registry) Supported(filename string) bool
- type Renderer
- type RendererFunc
- type Result
Constants ¶
const DefaultMaxInputSize = 1024 * 1024
DefaultMaxInputSize is the default maximum input size (1MB).
Variables ¶
var ( ErrUnsupportedFormat = errors.New("unsupported markup format") ErrToolNotFound = errors.New("external tool not found") ErrInputTooLarge = errors.New("input exceeds maximum size") ErrOutputTooLarge = errors.New("output exceeds maximum size") )
Errors returned by Render.
Functions ¶
This section is empty.
Types ¶
type ExternalConfig ¶
type ExternalConfig struct {
Command string // Command to execute.
Args []string // Arguments. Use {file} as a placeholder for temp file path.
InputMode InputMode // How to pass content to the command.
Timeout time.Duration // Command timeout. Zero means 30s default.
BodyPattern string // Regex to extract body from full HTML output. Empty means use full output.
TempExt string // File extension for temp files (e.g. ".pod"). Inferred from command if empty.
}
ExternalConfig configures an external renderer.
type ExternalRenderer ¶
type ExternalRenderer struct {
// contains filtered or unexported fields
}
ExternalRenderer shells out to a command to render markup.
func NewExternalRenderer ¶
func NewExternalRenderer(config ExternalConfig) *ExternalRenderer
NewExternalRenderer creates a renderer that delegates to an external command.
func (*ExternalRenderer) Available ¶
func (r *ExternalRenderer) Available() bool
Available returns true if the external command is on $PATH.
type Format ¶
type Format int
Format represents a markup format.
const ( FormatUnknown Format = iota FormatMarkdown // .md, .markdown, .mdown, .mkdn, .mdn, .mdtext, .livemd FormatOrg // .org FormatAsciiDoc // .adoc, .asciidoc, .asc FormatRST // .rst, .rest, .rst.txt FormatTextile // .textile FormatMediaWiki // .mediawiki, .wiki FormatCreole // .creole FormatPod // .pod FormatRDoc // .rdoc )
type InputMode ¶
type InputMode int
InputMode controls how content is passed to an external command.
type MarkdownRenderer ¶
type MarkdownRenderer struct {
// contains filtered or unexported fields
}
MarkdownRenderer renders Markdown to HTML using goldmark.
func NewMarkdownRenderer ¶
func NewMarkdownRenderer() *MarkdownRenderer
NewMarkdownRenderer creates a Markdown renderer with GFM extensions (tables, strikethrough, task lists, autolinks) and unsafe HTML passthrough.
type OrgRenderer ¶
type OrgRenderer struct{}
OrgRenderer renders Org-mode files to HTML using go-org.
func NewOrgRenderer ¶
func NewOrgRenderer() *OrgRenderer
NewOrgRenderer creates an Org-mode renderer.
type RSTRenderer ¶
type RSTRenderer struct{}
RSTRenderer renders reStructuredText by trying rst2html first, then falling back to rst2html.py.
func NewRSTRenderer ¶
func NewRSTRenderer() *RSTRenderer
NewRSTRenderer creates a renderer for reStructuredText.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps file extensions and filenames to renderers.
func NewDefaultRegistry ¶
func NewDefaultRegistry() *Registry
NewDefaultRegistry creates a registry with all supported renderers. Native renderers (Markdown, Org-mode) are always available. External renderers (AsciiDoc, reStructuredText, Pod) are registered but return ErrToolNotFound if the required tool is not on $PATH.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an empty registry with the default max input size (25MB).
func (*Registry) Register ¶
Register adds a renderer for the given format and file extensions. Extensions should include the leading dot (e.g. ".md").
func (*Registry) RegisterFilename ¶
RegisterFilename adds a renderer for an exact filename match.
func (*Registry) Render ¶
Render converts markup content to HTML based on the filename. Returns ErrUnsupportedFormat if no renderer matches. Returns ErrToolNotFound if the format needs an external tool that isn't installed.
func (*Registry) SetMaxInputSize ¶
SetMaxInputSize sets the maximum allowed input size in bytes. Zero disables the limit.
type RendererFunc ¶
RendererFunc adapts a function to the Renderer interface.