bbgo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 10 Imported by: 0

README

bbgo

Build Status Go Report Card GitHub

BBGO is a fast bbcode compiler for Go with supporting custom tags.

Usage

bbg := bbgo.New()
fmt.Println(bbg.Parse("[b]Hello World[/b]"))

// Output:
// <b>Hello World</b>

Supported BBCode Syntax

[tag]basic tag[/tag]
[tag1][tag2]nested tags[/tag2][/tag1]

[tag=value]tag with value[/tag]
[tag arg=value]tag with named argument[/tag]
[tag="quote value"]tag with quoted value[/tag]

[tag=value foo="hello world" bar=baz]multiple tag arguments[/tag]

Default Tags

  • [b]text[/b] --> <b>text</b> (b, i, u, and s all map the same)
  • [url]link[/url] --> <a href="link">link</a>
  • [url=link]text[/url] --> <a href="link">text</a>
  • [img]link[/img] --> <img src="link">
  • [img=link]alt[/img] --> <img alt="alt" title="alt" src="link">
  • [color=red]text[/color] --> <span style="color: red;">text</span>
  • [quote]text[/quote] --> <blockquote><cite>Quote</cite>text</blockquote>
  • [quote=Somebody]text[/quote] --> <blockquote><cite>Somebody said:</cite>text</blockquote>
  • [quote name=Somebody]text[/quote] --> <blockquote><cite>Somebody said:</cite>text</blockquote>
  • [code][b]anything[/b][/code] --> <pre>[b]anything[/b]</pre>
  • [list][*] item 1[*] item 2[*] item 3[/list] --> <ul><li> item 1</li><li> item 2</li><li> item 3</li></ul>

Lists are not currently implemented as a default tag, but can be added as a custom tag.
A working implementation of list tags can be found here

Adding Custom Tags

bbg.RegisterTag("color", bbgo.Processor(func(ctx *context.Context, tag node.Tag, w io.Writer) {
    switch t := tag.(type) {
	case *node.OpeningTag:
        // write here logic for opening tag
    case *node.ClosingTag:
        // write here logic for opening tag
    case *node.SelfClosingTag:
        // write here logic for self-closing tag
	}
}))

The default tags can also be modified by calling bbg.RegisterTag:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BBGO

type BBGO struct {
	// contains filtered or unexported fields
}

BBGO is a main object.

func New

func New() *BBGO

New creates a new BBGO and registers default processors.

func (*BBGO) Parse

func (b *BBGO) Parse(input string) string

Parse parses the given input.

func (*BBGO) RegisterTag

func (b *BBGO) RegisterTag(name string, p Processor)

RegisterTag registers a new tag.

type Processor

type Processor func(*context.Context, node.Tag, io.Writer)

Processor process a bbcode tag and writes result to the given Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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