Overview
========
**Latest Package**
http://pypi.python.org/pypi/bbcode
**Source Code**
https://github.com/dcwatson/bbcode
**Documentation**
http://bbcode.readthedocs.org/
[](https://travis-ci.org/dcwatson/bbcode)
Installation
============
The easiest way to install the bbcode module is with pip, e.g.:
pip install bbcode
Requirements
============
Python, tested with versions 2.6 through 3.7. Also tested on PyPy (2 and 3).
Basic Usage
===========
```python
# 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](https://code.google.com/p/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.
========
**Latest Package**
http://pypi.python.org/pypi/bbcode
**Source Code**
https://github.com/dcwatson/bbcode
**Documentation**
http://bbcode.readthedocs.org/
[](https://travis-ci.org/dcwatson/bbcode)
Installation
============
The easiest way to install the bbcode module is with pip, e.g.:
pip install bbcode
Requirements
============
Python, tested with versions 2.6 through 3.7. Also tested on PyPy (2 and 3).
Basic Usage
===========
```python
# 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](https://code.google.com/p/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.
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.32.tar.gz
(11.6 kB
view details)
File details
Details for the file bbcode-1.0.32.tar.gz.
File metadata
- Download URL: bbcode-1.0.32.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.11.0 pkginfo/1.4.2 requests/2.19.0 setuptools/38.5.2 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29c07b5a4da2bc5a209f09bee74a6c451942cf5df328206adac850c581bad283
|
|
| MD5 |
0a09d9127709b3f0fe2a9da0f56c078b
|
|
| BLAKE2b-256 |
4d4c59f7408c4356bbd62c17fe6e59f79a545b4b8341e529085e088658080534
|