Welcome to bbcode’s documentation!

Contents:

class bbcode.Parser(newline='<br />', normalize_newlines=True, install_defaults=True, escape_html=True, replace_links=True, replace_cosmetic=True, tag_opener='[', tag_closer=']', linker=None)
REPLACE_COSMETIC = (('---', '&mdash;'), ('--', '&ndash;'), ('...', '&#8230;'), ('(c)', '&copy;'), ('(reg)', '&reg;'), ('(tm)', '&trade;'))
REPLACE_ESCAPE = (('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;'))
TOKEN_DATA = 4
TOKEN_NEWLINE = 3
TOKEN_TAG_END = 2
TOKEN_TAG_START = 1
add_formatter(tag_name, render_func, **kwargs)

Installs a render function for the specified tag name. The render function should have the following signature:

def render(tag_name, value, options, parent, context)

The arguments are as follows:

tag_name
The name of the tag being rendered.
value
The context between start and end tags, or None for standalone tags. Whether this has been rendered depends on render_embedded tag option.
options
A dictionary of options specified on the opening tag.
parent
The parent TagOptions, if the tag is being rendered inside another tag, otherwise None.
context
The keyword argument dictionary passed into the format call.
add_simple_formatter(tag_name, format, **kwargs)

Installs a formatter that takes the tag options dictionary, puts a value key in it, and uses it as a format dictionary to the given format string.

format(data, **context)

Formats the input text using any installed renderers. Any context keyword arguments given here will be passed along to the render functions as a context dictionary.

install_default_formatters()

Installs default formatters for the following tags:

b, i, u, s, list (and *), quote, code, center, color, url

strip(data, strip_newlines=False)

Strips out any tags from the input text, using the same tokenization as the formatter.

tokenize(data)

Tokenizes the given string. A token is a 4-tuple of the form:

(token_type, tag_name, tag_options, token_text)

token_type
One of: TOKEN_TAG_START, TOKEN_TAG_END, TOKEN_NEWLINE, TOKEN_DATA
tag_name
The name of the tag if token_type=TOKEN_TAG_*, otherwise None
tag_options
A dictionary of options specified for TOKEN_TAG_START, otherwise None
token_text
The original token text
class bbcode.TagOptions(tag_name, **kwargs)
escape_html = True

True if HTML characters (<, >, and &) should be escaped inside this tag.

newline_closes = False

True if a newline should automatically close this tag.

render_embedded = True

True if tags should be rendered inside this tag.

replace_cosmetic = True

True if cosmetic replacements (elipses, dashes, etc.) should be performed inside this tag.

True if URLs should be replaced with link markup inside this tag.

standalone = False

True if this tag does not have a closing tag.

strip = True

True if leading and trailing whitespace should be stripped inside this tag.

swallow_trailing_newline = False

True if this tag should swallow the first trailing newline (i.e. for block elements).

tag_name = None

The name of the tag, all lowercase.

transform_newlines = True

True if newlines should be converted to markup.

bbcode.render_html(input, **context)

A module-level convenience method that creates a default bbcode parser, and renders the input string as HTML.

Indices and tables

Project Versions

Table Of Contents

This Page