storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package storage provides types and utilities for working with Confluence Storage Format (XHTML). It includes an intermediate representation (IR) for content blocks, rendering to Storage XHTML, parsing from Storage XHTML, and validation.

Index

Constants

This section is empty.

Variables

View Source
var AllowedMacros = map[string]bool{}

AllowedMacros is a configurable allowlist of permitted macro names. If empty, all macros are allowed.

View Source
var ForbiddenTags = map[string]bool{
	"thead":    true,
	"tfoot":    true,
	"colgroup": true,
	"col":      true,
	"div":      true,
	"span":     true,
	"script":   true,
	"style":    true,
	"iframe":   true,
	"form":     true,
	"input":    true,
	"button":   true,
}

ForbiddenTags are HTML tags not allowed in Confluence Storage Format.

Functions

func IsValidXML

func IsValidXML(xhtml string) bool

IsValidXML checks if the string is well-formed XML.

func MustValidate

func MustValidate(xhtml string)

MustValidate panics if validation fails (useful for tests).

func Render

func Render(page *Page) (string, error)

Render converts a Page to Confluence Storage XHTML.

func RenderBlock

func RenderBlock(block Block) (string, error)

RenderBlock converts a single Block to Storage XHTML.

func RenderMacro

func RenderMacro(m *Macro) (string, error)

RenderMacro converts a Macro to Storage XHTML.

func Validate

func Validate(xhtml string) error

Validate checks if the given string is valid Confluence Storage XHTML.

func ValidateBlock

func ValidateBlock(block Block) error

ValidateBlock validates a single block's rendered output.

func ValidateBlockWithOptions

func ValidateBlockWithOptions(block Block, opts ValidatorOptions) error

ValidateBlockWithOptions validates a single block's rendered output with options.

func ValidateWithOptions

func ValidateWithOptions(xhtml string, opts ValidatorOptions) error

ValidateWithOptions checks if the given string is valid Confluence Storage XHTML using the provided options.

Types

type Block

type Block interface {
	// BlockType returns the type identifier (e.g., "table", "paragraph").
	BlockType() string
}

Block represents any content block in Confluence Storage Format.

type BulletList

type BulletList struct {
	Items []ListItem `json:"items"`
}

BulletList represents an unordered list.

func (BulletList) BlockType

func (BulletList) BlockType() string

BlockType implements Block.

type Cell

type Cell struct {
	Text  string `json:"text,omitempty"`
	Macro *Macro `json:"macro,omitempty"`
}

Cell represents a table cell which can contain text or a macro.

type CodeBlock

type CodeBlock struct {
	Language string `json:"language,omitempty"`
	Code     string `json:"code"`
}

CodeBlock represents a code block with optional language.

func (CodeBlock) BlockType

func (CodeBlock) BlockType() string

BlockType implements Block.

type Heading

type Heading struct {
	Level int    `json:"level"` // 1-6
	Text  string `json:"text"`
}

Heading represents a heading (h1-h6).

func (Heading) BlockType

func (Heading) BlockType() string

BlockType implements Block.

type HorizontalRule

type HorizontalRule struct{}

HorizontalRule represents a horizontal rule (<hr/>).

func (HorizontalRule) BlockType

func (HorizontalRule) BlockType() string

BlockType implements Block.

type ListItem

type ListItem struct {
	Text string `json:"text"`
}

ListItem represents a list item.

type Macro

type Macro struct {
	Name   string            `json:"name"`
	Params map[string]string `json:"params,omitempty"`
	Body   string            `json:"body,omitempty"`
}

Macro represents a Confluence macro (ac:structured-macro).

func (Macro) BlockType

func (Macro) BlockType() string

BlockType implements Block.

type NumberedList

type NumberedList struct {
	Items []ListItem `json:"items"`
}

NumberedList represents an ordered list.

func (NumberedList) BlockType

func (NumberedList) BlockType() string

BlockType implements Block.

type Page

type Page struct {
	Blocks []Block `json:"blocks"`
}

Page represents a full page's content as a sequence of blocks.

func Parse

func Parse(xhtml string) (*Page, error)

Parse converts Confluence Storage XHTML to a Page with Blocks.

type Paragraph

type Paragraph struct {
	Text string `json:"text"`
}

Paragraph represents a simple text paragraph.

func (Paragraph) BlockType

func (Paragraph) BlockType() string

BlockType implements Block.

type Row

type Row struct {
	Cells []Cell `json:"cells"`
}

Row represents a table row.

type Table

type Table struct {
	Headers []string `json:"headers"`
	Rows    []Row    `json:"rows"`
}

Table represents a Confluence table.

func (Table) BlockType

func (Table) BlockType() string

BlockType implements Block.

type ValidationError

type ValidationError struct {
	Message string
	Tag     string
}

ValidationError represents a Storage XHTML validation failure.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidatorOptions

type ValidatorOptions struct {
	// RequireTableTbody requires tables to have <tbody> elements.
	RequireTableTbody bool
	// AllowedMacros limits which macros are permitted. Empty means all allowed.
	AllowedMacros map[string]bool
	// ForbiddenTags specifies tags that are not allowed.
	ForbiddenTags map[string]bool
}

ValidatorOptions configures validation behavior.

func DefaultValidatorOptions

func DefaultValidatorOptions() ValidatorOptions

DefaultValidatorOptions returns the default validation options.

Jump to

Keyboard shortcuts

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