bbcode

package module
v0.0.0-...-f693092 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2014 License: MIT Imports: 6 Imported by: 1

README

bbcode Build Status

bbcode is a fast BBCode compiler for Go. Documentation can be found on GoDoc

Documentation

Overview

Package bbcode implements a parser and HTML generator for BBCode.

Index

Constants

View Source
const (
	TEXT        = "text"
	OPENING_TAG = "opening"
	CLOSING_TAG = "closing"
)

Variables

View Source
var DefaultTagCompilers map[string]TagCompilerFunc

Functions

func CompileText

func CompileText(in *BBCodeNode) string

func InsertNewlines

func InsertNewlines(out *HTMLTag)

func Lex

func Lex(str string) chan Token

func ValidURL

func ValidURL(raw string) string

Types

type BBClosingTag

type BBClosingTag struct {
	Name string
	Raw  string
}

type BBCodeNode

type BBCodeNode struct {
	Token
	Parent     *BBCodeNode
	Children   []*BBCodeNode
	ClosingTag *BBClosingTag

	Compiler *Compiler
	Info     interface{}
}

func Parse

func Parse(tokens chan Token) *BBCodeNode

func (*BBCodeNode) GetOpeningTag

func (n *BBCodeNode) GetOpeningTag() *BBOpeningTag

type BBOpeningTag

type BBOpeningTag struct {
	Name  string
	Value string
	Args  map[string]string
	Raw   string
}

func (*BBOpeningTag) String

func (t *BBOpeningTag) String() string

type Compiler

type Compiler struct {
	AutoCloseTags              bool
	IgnoreUnmatchedClosingTags bool
	// contains filtered or unexported fields
}

func NewCompiler

func NewCompiler(autoCloseTags, ignoreUnmatchedClosingTags bool) Compiler

func (Compiler) Compile

func (c Compiler) Compile(str string) string

func (Compiler) CompileTree

func (c Compiler) CompileTree(node *BBCodeNode) *HTMLTag

CompileTree transforms BBCodeNode into an HTML tag.

func (Compiler) SetDefault

func (c Compiler) SetDefault(compiler TagCompilerFunc)

func (Compiler) SetTag

func (c Compiler) SetTag(tag string, compiler TagCompilerFunc)

type HTMLTag

type HTMLTag struct {
	Name     string
	Value    string
	Attrs    map[string]string
	Children []*HTMLTag
}

HTMLTag represents a DOM node.

func CompileRaw

func CompileRaw(in *BBCodeNode) *HTMLTag

func NewHTMLTag

func NewHTMLTag(value string) *HTMLTag

NewHTMLTag creates a new HTMLTag with string contents specified by value.

func NewlineTag

func NewlineTag() *HTMLTag

Returns a new HTMLTag representing a line break

func (*HTMLTag) AppendChild

func (t *HTMLTag) AppendChild(child *HTMLTag) *HTMLTag

func (*HTMLTag) String

func (t *HTMLTag) String() string

type TagCompilerFunc

type TagCompilerFunc func(*BBCodeNode) (*HTMLTag, bool)
var DefaultTagCompiler TagCompilerFunc

type Token

type Token struct {
	ID    string
	Value interface{}
}

Jump to

Keyboard shortcuts

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