cmsrender

package
v1.4.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cmsrender owns Lesser's canonical Article rendering boundary.

Index

Constants

View Source
const (
	// FormatHTML identifies already-HTML source that must be sanitized before output.
	FormatHTML = "html"
	// FormatMarkdown identifies Markdown source rendered to HTML and then sanitized.
	FormatMarkdown = "markdown"

	// MaxArticleSourceBytes caps submitted Article source before rendering.
	MaxArticleSourceBytes = 256 * 1024
	// MaxArticleRenderedHTMLBytes caps server-rendered Article HTML output.
	MaxArticleRenderedHTMLBytes = 512 * 1024
)

Variables

View Source
var (
	// ErrUnsupportedContentFormat is wrapped when an Article content format is unsupported.
	ErrUnsupportedContentFormat = errors.New("unsupported article content format")
	// ErrArticleContentTooLarge is wrapped when Article source exceeds MaxArticleSourceBytes.
	ErrArticleContentTooLarge = errors.New("article content exceeds maximum source size")
	// ErrArticleRenderedContentTooLarge is wrapped when rendered output exceeds MaxArticleRenderedHTMLBytes.
	ErrArticleRenderedContentTooLarge = errors.New("rendered article content exceeds maximum output size")
)

Functions

func NormalizeFormat

func NormalizeFormat(format string) (string, error)

NormalizeFormat returns the storage-level content format. Empty source defaults to Markdown.

func SanitizeArticleHTML

func SanitizeArticleHTML(content string) string

SanitizeArticleHTML sanitizes Article HTML source/output using the CMS publication policy.

func ValidateArticleSource

func ValidateArticleSource(content string, format string) error

ValidateArticleSource enforces source-format and source-size rules without rendering.

Types

type LimitError

type LimitError struct {
	Field  string
	Limit  int
	Actual int
	Cause  error
}

LimitError reports deterministic, user-facing Article renderer limits.

func (*LimitError) Error

func (e *LimitError) Error() string

func (*LimitError) Unwrap

func (e *LimitError) Unwrap() error

Unwrap returns the sentinel limit cause.

type RenderedArticleContent

type RenderedArticleContent struct {
	HTML          string
	SourceFormat  string
	SourceBytes   int
	RenderedBytes int
}

RenderedArticleContent is the public Article body produced by the canonical renderer.

func RenderArticleContent

func RenderArticleContent(content string, format string) (RenderedArticleContent, error)

RenderArticleContent renders Article source to the canonical sanitized public HTML body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL