Skip to main content

A pure python bbcode parser and formatter.

Project description

Installing
==========

The easiest way to install the bbcode module is via PyPI, e.g.:

pip install bbcode

You can download the latest package from here:

http://pypi.python.org/pypi/bbcode


Requirements
============

Python, tested with versions 2.5 through 3.2.


Usage
=====

# Using the default parser.
import bbcode
html = bbcode.render_html(text)

# Installing simple formatters.
parser = bbcode.Parser()
parser.add_simple_formatter('hr', '<hr />', standalone=True)
parser.add_simple_formatter('sub', '<sub>%(value)s</sub>')
parser.add_simple_formatter('sup', '<sup>%(value)s</sup>')

# A custom render function.
def render_color(tag_name, value, options, parent, context):
return '<span style="color:%s;">%s</span>' % (tag_name, value)

# Installing advanced formatters.
for color in ('red', 'blue', 'green', 'yellow', 'black', 'white'):
parser.add_formatter(color, render_color)

# Calling format with context.
html = parser.format(text, somevar='somevalue')


Advantages Over Postmarkup
==========================

* More tag options for how/when to escape - for instance, you can specify
whether to escape html or perform cosmetic replacements on a tag-by-tag
basis. Same for auto-linking and transforming newlines.

* More liberal (and accurate) automatic link creation, using John Gruber's
URL regular expression:
http://daringfireball.net/2010/07/improved_regex_for_matching_urls

* Does not swallow unrecognized tags. For example, [3] will be output as
[3], not silently ignored.

* More flexible tag option parser. Tags may have standard bbcode options,
for example [url=something]text[/url], but may also have named options,
for example [url=something alt=icon]text[/url]. These options are passed
to the render function as a standard python dictionary.

* Ability to specify tag opening and closing delimiters (default: [ and ]).
A side benefit of this is being able to use this library to selectively
strip HTML tags from a string by using < and >.

* Includes a runnable unittest suite.

* Python 3 support.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bbcode-1.0.5.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file bbcode-1.0.5.tar.gz.

File metadata

  • Download URL: bbcode-1.0.5.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bbcode-1.0.5.tar.gz
Algorithm Hash digest
SHA256 b794cd6444cd217859f9585c320ed0b474e9aaaeb0f6416e93d10f17c376777c
MD5 f72f79c8cb1c004f9c738efc69369013
BLAKE2b-256 29e0e158d2081a34094c29801785082dfd34d3d739962226a88bd94fbc7b902d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page