mobiledoc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2019 License: 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(string) bool { return true }

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.

View Source
var DefaultMarkups = map[string]func(Map) bool{
	"a":      func(Map) bool { return true },
	"b":      nil,
	"code":   nil,
	"em":     nil,
	"i":      nil,
	"s":      nil,
	"strong": nil,
	"sub":    nil,
	"sup":    nil,
	"u":      nil,
}

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

Functions

This section is empty.

Types

type Atom

type Atom struct {
	Name    string
	Text    string
	Payload interface{}
}

Atom is a single atom.

type Card

type Card struct {
	Name    string
	Payload interface{}
}

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, interface{}) error
	Cards map[string]func(*bufio.Writer, interface{}) 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.

func (MarkerType) Valid

func (t MarkerType) Valid() bool

Valid returns whether the marker type is valid.

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.

func (SectionType) Valid

func (t SectionType) Valid() bool

Valid returns whether the section type is valid.

type Validator

type Validator struct {
	// Markups defines the expected markups with the name as key and a map of
	// attributes and validations functions.
	Markups map[string]func(Map) bool

	// Atoms defines the expected atoms with the name as the key and a validator
	// function.
	Atoms map[string]func(string, interface{}) bool

	// Cards defines the expected cards with the name as the key and a validator
	// function.
	Cards map[string]func(interface{}) bool

	// MarkupSections defines the expected markup sections.
	MarkupSections []string

	// ListSections defines the expected list sections.
	ListSections []string

	// ImageSection defines whether the image section is allowed.
	ImageSection func(string) bool
}

Validator validates a mobiledoc.

func NewValidator

func NewValidator() *Validator

NewValidator creates a validator that validates the mobiledoc standard.

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