bbparser

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

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

Go to latest
Published: May 21, 2018 License: MIT Imports: 3 Imported by: 1

README

bbparser

Simple bbcode parser library for Golang

Features
  1. Constructor function which add almost all needed tags handlers
  2. Easy way to add your own tags/handlers
  3. Define special strings which need to be replaced (like \n with <br> )
Instalation

go get github.com/KitlerUA/bbparser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FontColorHandler

func FontColorHandler(tag Tag, content string) string

FontColorHandler - parse color tag with color attribute

func FontSizeHandler

func FontSizeHandler(tag Tag, content string) string

FontSizeHandler - parse size tag with size attribute

func ListHandler

func ListHandler(tag Tag, content string) string

ListHandler - parse list with one-line tags (double tags like [li] parsed separated)

func SimpleHandler

func SimpleHandler(tag Tag, content string) string

SimpleHandler - handle tags that need just add html tags at the begin and the end

func TextAlignHandler

func TextAlignHandler(tag Tag, content string) string

func URLHandler

func URLHandler(tag Tag, content string) string

URLHandler - parse url tag with or without attribute

Types

type Handler

type Handler func(Tag, string) string

Handler - function type for handling content between bbcode tags

type Parser

type Parser struct {
	// Handlers - pairs with tagname - handler function
	Handlers map[string]Handler
	// SpecialChars - contains chars/strings that should be replaced
	SpecialChars map[string]string
}

Parser - parse bbcode to html

func New

func New() *Parser

New - return pointer on new Parser instance

func NewDefault

func NewDefault() *Parser

NewDefault - return pointer on parser with all defaults tags and special chars

func (*Parser) AddSpecialString

func (p *Parser) AddSpecialString(old, new string)

AddSpecialString - add string to be replaced with (if string already in parser - it will be override with new one)

func (*Parser) AddTag

func (p *Parser) AddTag(tagName string, handler Handler)

AddTag - add tag to parser (if tag already exists - it will be override with new one)

func (*Parser) Parse

func (p *Parser) Parse(str string) string

Parse - parse given string with parser settings

type Tag

type Tag struct {
	Name       string
	Closing    bool
	Attributes map[string]string
}

Tag - structure contains info about bbcode tag

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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