https://github.com/dcwatson/bbcode
A pure python bbcode parser and formatter.
https://github.com/dcwatson/bbcode
bbcode markup python
Last synced: 9 months ago
JSON representation
A pure python bbcode parser and formatter.
- Host: GitHub
- URL: https://github.com/dcwatson/bbcode
- Owner: dcwatson
- License: bsd-2-clause
- Created: 2012-07-03T15:25:44.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T00:19:14.000Z (about 1 year ago)
- Last Synced: 2025-04-04T05:06:10.440Z (9 months ago)
- Topics: bbcode, markup, python
- Language: Python
- Size: 3.55 MB
- Stars: 69
- Watchers: 7
- Forks: 17
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Overview
========
**Latest Package**
http://pypi.python.org/pypi/bbcode
**Source Code**
https://github.com/dcwatson/bbcode
**Documentation**
https://dcwatson.github.io/bbcode/
[](https://github.com/dcwatson/bbcode/actions)
Installation
============
The easiest way to install the bbcode module is with pip, e.g.:
pip install bbcode
Requirements
============
Python 3.9+
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', '
', standalone=True)
parser.add_simple_formatter('sub', '%(value)s')
parser.add_simple_formatter('sup', '%(value)s')
# A custom render function.
def render_color(tag_name, value, options, parent, context):
return '%s' % (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')
```