cmsrender

package
v1.6.28 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 14 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 ArticleMedia added in v1.6.28

type ArticleMedia struct {
	// Role selects the placement semantics (hero, inline, social_card).
	Role ArticleMediaRole
	// InlinePosition is the zero-based insertion point for inline media: the
	// figure is inserted before the Nth top-level block of the rendered
	// article. Positions at or past the block count append at the end.
	InlinePosition int
	URL            string
	AltText        string
	Caption        string
	CreditLine     string
	Width          int
	Height         int
	ContentType    string
}

ArticleMedia is one composed editorial image descriptor. The URL must be a minted published serving (durable) or a caller-authorized short-lived serving (draft preview); the renderer never mints or resolves URLs and only emits the exact descriptors it is given.

type ArticleMediaRole added in v1.6.28

type ArticleMediaRole string

ArticleMediaRole describes how one bound editorial asset composes into article HTML. The canonical renderer treats the role as presentation semantics only: hero leads the article, inline inserts at a zero-based block position, and social-card media is never emitted into the body.

const (
	// ArticleMediaRoleHero is the article's leading image.
	ArticleMediaRoleHero ArticleMediaRole = "hero"
	// ArticleMediaRoleInline places an image at a modeled block position.
	ArticleMediaRoleInline ArticleMediaRole = "inline"
	// ArticleMediaRoleSocialCard is the promotional card presentation; it does
	// not compose into the article body.
	ArticleMediaRoleSocialCard ArticleMediaRole = "social_card"
)

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.

func RenderArticleContentWithMedia added in v1.6.28

func RenderArticleContentWithMedia(content string, format string, media []ArticleMedia) (RenderedArticleContent, error)

RenderArticleContentWithMedia renders Article source to the canonical sanitized public HTML body, composing bound editorial media into the output. Media descriptors carry only the URL, alt, caption, credit, dimensions, and placement of each asset; the renderer never resolves, mints, or authorizes URLs itself. When no media is supplied the result is byte-identical to RenderArticleContent.

Jump to

Keyboard shortcuts

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