mobiledoc

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT, MIT Imports: 5 Imported by: 0

README

mobiledoc

Go package for handling the mobiledoc format.

Installation

Get the package using the go tool:

$ go get -u github.com/256dpi/mobiledoc

License

The MIT License (MIT)

Copyright (c) 2018 Joël Gähwiler

Documentation

Index

Constants

View Source
const Version = "0.3.1"

Version specifies the mobiledoc version.

Variables

View Source
var DefaultImageSection = func(source string) bool {
	return len(source) > 0
}

DefaultImageSection defines the default image section validator.

View Source
var DefaultListSections = []string{"ul", "ol"}

DefaultListSections defines the default list sections.

View Source
var DefaultMarkupSections = []string{"aside", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6", "p"}

DefaultMarkupSections defines the default markup sections.

DefaultMarkups defines the default expected markups with the tag as the key and a map of attributes and validator functions.

Functions

func LinkValidator

func LinkValidator(attributes Map) bool

LinkValidator validates the href attribute.

func NoAttributesValidator

func NoAttributesValidator(attributes Map) bool

NoAttributesValidator returns true if the provided attributes are empty.

Types

type Atom

type Atom struct {
	Name    string
	Text    string
	Payload Map
}

Atom is a single atom.

type Card

type Card struct {
	Name    string
	Payload Map
}

Card is a single card.

type Document

type Document struct {
	Version  string
	Markups  []Markup
	Atoms    []Atom
	Cards    []Card
	Sections []Section
}

Document is a mobiledoc.

func Parse

func Parse(doc Map) (Document, error)

Parse will parse the specified raw mobiledoc.

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.

func (*HTMLRenderer) Render

func (r *HTMLRenderer) Render(w io.Writer, doc Document) error

Render will render the document to the provided writer.

type List

type List = []interface{}

List is a general purpose list.

type Map

type Map = map[string]interface{}

Map is a general purpose map.

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 Markup

type Markup struct {
	Tag        string
	Attributes Map
}

Markup is a single markup.

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 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

	// 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

func NewDefaultValidator() *Validator

NewDefaultValidator creates a validator that validates the default mobiledoc standard.

func NewEmptyValidator

func NewEmptyValidator() *Validator

NewEmptyValidator creates an empty validator.

func (*Validator) Validate

func (v *Validator) Validate(doc Document) error

Validate will walk the specified mobiledoc and check if it is valid.

Jump to

Keyboard shortcuts

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