bbConvert

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 9 Imported by: 1

README

bbConvert GoDoc Coverage Status Go Report Card

bbConvert is an easy way to process BBCode and Markdown and convert it to HTML. BBCode additionally has support for custom processing to allow for custom tags or even conversion to something other then HTML. This library is largely powered by this regexp library and is additionally uses this support program to generate code for additional performance.

Support

If you have any questions, feel free to open an issue and ask it. I don't have a life; I'll probably answer quickly.

BBCode

[b]Some Text[/b] //bolded text
[bold]Some Text[/bold] //bolded text
[i]Some Text[/i] //italicized text
[italics]Some Text[/italics] //italicized text
[u]Some Text[/u] //underlined text
[underline]Some Text[/underline] //underlined text
[s]some Text[/s] //strikedthrough text
[strike]Some Text[/strike] //strikethrough text
[code]{Some Code}[/code] //code text
[font=Verdana]Some Text[/font] //text in verdana font
[font size=20pt]Some Text[/font] //20pt size text
[font color=red]Some Text[/font] //red text. Must be a CSS color.
[font color=#000000]Some Text[/font] //text with the color of #000000. The # is necessary
[font variant=upper]Some Text[/font] //uppercased text
[font variant=lower]Some Text[/font] //lowercase text
[font variant=smallcaps]Some Text[/font] //smallcaps text
[size=20pt]Some Text[/size] //20pt size text
[color=red]Some Text[/color] //red text
[color=#000000]Some Text[/color] //text with the color of #000000. The # is necessary
[smallcaps]Some Text[/smallcaps] //smallcaps text
[url]Link address[/url] //linked text
[url=address]Some Text[/url] //linked text
[url title="Title"]Link address[/url] //linked text with title
[url tab]Link address[/url] //link that opens into a new tab (target=_blank)
[link]Link address[/link] //linked text
[link=address]Some Text[/link] //linked text
[link title="Title"]Link address[/link] //linked text with tooltip
[link tab]Link address[/link] //link that opens into a new tab (target=_blank)
[youtube]Youtube URL or video ID[/youtube] //youtube video
[youtube height=200 width=500]Youtube URL or video ID[/youtube] //youtube video with set size
[youtube=500x200]Youtube URL or video ID[/youtube] //youtube video with set size
[youtube left]Youtube URL or video ID[/youtube] //youtube video floated left
[youtube right]Youtube URL or video ID[/youtube] //youtube video floated right
[img]Image URL[/img] //an image
[img=500x200]Image URL[/img] //an image with set size
[img height=200 width=500]Image URL[/img] //an image with set size
[img left]Image URL[/img] //an image floated left
[img right]Image URL[/img] //an image floated right
[img alt="Alternate text"]Image URL[/img] //an image with alternate text
[img title="Title"]Image URL[/img] //an image with title
[image]Image URL[/image] //same as [img] tag
[title]Some Text[/title] //Large text made for use as a title
[t1]Some Text[/t1] //Large text made for use as a title. Same as [title]
[t2]Some Text[/t2] //Slightly smaller text than [t1]. Meant for use as a title of some sort
[t3]Some Text[/t3] //Slightly smaller text than [t2]. Meant for use as a title of some sort
[t4]Some Text[/t4] //Slightly smaller text than [t3]. Meant for use as a title of some sort
[t5]Some Text[/t5] //Slightly smaller text than [t4]. Meant for use as a title of some sort
[t6]Some Text[/t6] //Slightly smaller text than [t5]. Meant for use as a title of some sort
[align=center]Some Text[/align] //Aligns the text. The text will be in a separate paragraph
[align center]Some Text[/align] //Equal sign is optional
[float=right]Floaty McFloat Face[/float] //Float the content content (for HTML, this will be a floated div)
[float right]Floaty McFloat Face[/float] //Equal sign is optional
[bullet]Bullet 1 * Bullet 2[/bullet] //bulleted list
[ul]
* Item 1
Item 2
[/ul] //an unordered (bulleted) list
[ol]
* Item 1
Item 2
[/ol] //an ordered (numbered) list
[bullet] * Item 1 * Item 2[/bullet] //same as [ul]
[number] * Item 1 * Item 2[/number] //same as [ol]
[ul]* Item 1 * Item 2[/ul] //an unordered (bulleted) list
[ol]* Item 1 * Item 2[/ol] //an ordered (numbered) list

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BBConvert added in v1.0.2

type BBConvert func(BBTag) string

type BBConverter added in v1.0.2

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

A converter for BBCode

func NewBBConverter added in v1.0.2

func NewBBConverter() BBConverter

func (BBConverter) CustomConvert added in v1.0.2

func (b BBConverter) CustomConvert(bb string, convert map[string]BBConvert) string

Parse and Convert BBCode. The BBCode is replaced with the return from the given conversion function. The key in the map is the BBCode's tag

func (BBConverter) HTMLConvert added in v1.0.2

func (b BBConverter) HTMLConvert(bb string) string

Converts BBCode into HTML.

type BBTag added in v1.0.2

type BBTag struct {
	Tag string
	// Leading value (if it exists). Eg. [img=500x200]
	Leading string
	// If the parameter doesn't have an associated value then it'll be set to an empty string
	// Eg. [float right] = {"right": ""}
	// Eg. [font color=red] = {"color": "red"}
	Values map[string]string
	// The string in between the tags
	Middle string
}

type ComboConverter added in v1.0.2

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

A BBCode and Markdown converter all in one. Attemps to prevent some potential errors when doing them separately.

func NewComboConverter added in v1.0.2

func NewComboConverter() ComboConverter

func (ComboConverter) BBHTMLConvert added in v1.0.2

func (c ComboConverter) BBHTMLConvert(in string) string

Converts just BBCode to HTML

func (ComboConverter) HTMLConvert added in v1.0.2

func (c ComboConverter) HTMLConvert(combo string) string

Convert BBCode and Markdown to HTML

func (ComboConverter) MarkdownHTMLConvert added in v1.0.2

func (c ComboConverter) MarkdownHTMLConvert(in string) string

Converts just Markdown to HTML

type MarkdownConverter added in v1.0.2

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

func NewMarkdownConverter added in v1.0.2

func NewMarkdownConverter() MarkdownConverter

func (MarkdownConverter) HTMLConvert added in v1.0.2

func (m MarkdownConverter) HTMLConvert(mk string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳