Documentation
¶
Index ¶
Constants ¶
const Version = "0.3.1"
Version specifies the mobiledoc version.
Variables ¶
var DefaultImageSection = func(source string) bool { return len(source) > 0 }
DefaultImageSection defines the default image section validator.
var DefaultListSections = []string{"ul", "ol"}
DefaultListSections defines the default list sections.
var DefaultMarkupSections = []string{"aside", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6", "p"}
DefaultMarkupSections defines the default markup sections.
var DefaultMarkups = map[string]func(Map) bool{ "a": LinkValidator, "b": NoAttributesValidator, "code": NoAttributesValidator, "em": NoAttributesValidator, "i": NoAttributesValidator, "s": NoAttributesValidator, "strong": NoAttributesValidator, "sub": NoAttributesValidator, "sup": NoAttributesValidator, "u": NoAttributesValidator, }
DefaultMarkups defines the default expected markups with the tag as the key and a map of attributes and validator functions.
Functions ¶
func LinkValidator ¶ added in v0.1.1
LinkValidator validates the href attribute.
func NoAttributesValidator ¶ added in v0.1.1
NoAttributesValidator returns true if the provided attributes are empty.
Types ¶
type Document ¶
type Document struct {
Version string
Markups []Markup
Atoms []Atom
Cards []Card
Sections []Section
}
Document is a mobiledoc.
func ConvertText ¶ added in v0.3.0
ConvertText will convert a basic text with no formatting but newlines to a document.
func (*Document) MarshalBSONValue ¶ added in v0.3.1
MarshalBSONValue implements the bson.ValueMarshaler interface.
func (Document) MarshalJSON ¶ added in v0.3.0
MarshalJSON implements the json.Marshaler interface.
func (*Document) UnmarshalBSON ¶ added in v0.3.0
UnmarshalBSON implements the bson.Unmarshaler interface.
func (*Document) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON implements the json.Unmarshaler interface.
type HTMLRenderer ¶
type HTMLRenderer struct {
Atoms map[string]func(*bufio.Writer, string, Map) error
Cards map[string]func(*bufio.Writer, Map) error
}
HTMLRenderer implements a basic HTML renderer.
func NewHTMLRenderer ¶
func NewHTMLRenderer() *HTMLRenderer
NewHTMLRenderer creates a new HTMLRenderer.
type Marker ¶
type Marker struct {
Type MarkerType
OpenMarkups []*Markup
ClosedMarkups int
Text string
Atom *Atom
}
Marker is a single marker.
type MarkerType ¶
type MarkerType int
MarkerType defines a marker type.
const ( TextMarker MarkerType = 0 AtomMarker MarkerType = 1 )
The available marker identifiers.
type Section ¶
type Section struct {
Type SectionType
Tag string
Markers []Marker
Source string
Items [][]Marker
Card *Card
}
Section is a single section.
type SectionType ¶
type SectionType int
SectionType defines a section type.
const ( MarkupSection SectionType = 1 ImageSection SectionType = 2 ListSection SectionType = 3 CardSection SectionType = 10 )
The available section identifiers.
type TextRenderer ¶ added in v0.3.1
type TextRenderer struct {
Atoms map[string]func(*bufio.Writer, string, Map) error
Cards map[string]func(*bufio.Writer, Map) error
}
TextRenderer implements a basic text renderer.
func NewTextRenderer ¶ added in v0.3.1
func NewTextRenderer() *TextRenderer
NewTextRenderer creates a new TextRenderer.
type Validator ¶
type Validator struct {
// Markups defines the allowed markups with the name as key and a
// attributes validator function.
Markups map[string]func(attributes Map) bool
// Whether to allow unknown atoms and cards.
UnknownAtoms bool
UnknownCards bool
// Atoms defines the allowed atoms with the name as the key and a validator
// function.
Atoms map[string]func(name string, payload Map) bool
// Cards defines the allowed cards with the name as the key and a validator
// function.
Cards map[string]func(payload Map) bool
// MarkupSections defines the allowed markup sections.
MarkupSections []string
// ListSections defines the allowed list sections.
ListSections []string
// ImageSection defines whether the image section is allowed when a source
// validator is set.
ImageSection func(source string) bool
}
Validator validates a mobiledoc.
func NewDefaultValidator ¶ added in v0.1.1
func NewDefaultValidator() *Validator
NewDefaultValidator creates a validator that validates the default mobiledoc standard excluding atoms and cards.
func NewEmptyValidator ¶ added in v0.1.1
func NewEmptyValidator() *Validator
NewEmptyValidator creates an empty validator.
func NewFormatValidator ¶ added in v0.3.0
func NewFormatValidator() *Validator
NewFormatValidator creates a validator that validates the default mobiledoc standard including atoms and cards.