An open API service indexing awesome lists of open source software.

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.

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/

[![CI Status](https://github.com/dcwatson/bbcode/workflows/CI/badge.svg)](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')
```