项目作者: dcwatson

项目描述 :
A pure python bbcode parser and formatter.
高级语言: Python
项目地址: git://github.com/dcwatson/bbcode.git
创建时间: 2012-07-03T15:25:44Z
项目社区:https://github.com/dcwatson/bbcode

开源协议:BSD 2-Clause "Simplified" License

下载


Overview

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

Source Code
https://github.com/dcwatson/bbcode

Documentation
https://dcwatson.github.io/bbcode/

CI Status

Installation

The easiest way to install the bbcode module is with pip, e.g.:

  1. pip install bbcode

Requirements

Python 3.9+

Basic Usage

  1. # Using the default parser.
  2. import bbcode
  3. html = bbcode.render_html(text)
  4. # Installing simple formatters.
  5. parser = bbcode.Parser()
  6. parser.add_simple_formatter('hr', '<hr />', standalone=True)
  7. parser.add_simple_formatter('sub', '<sub>%(value)s</sub>')
  8. parser.add_simple_formatter('sup', '<sup>%(value)s</sup>')
  9. # A custom render function.
  10. def render_color(tag_name, value, options, parent, context):
  11. return '<span style="color:%s;">%s</span>' % (tag_name, value)
  12. # Installing advanced formatters.
  13. for color in ('red', 'blue', 'green', 'yellow', 'black', 'white'):
  14. parser.add_formatter(color, render_color)
  15. # Calling format with context.
  16. html = parser.format(text, somevar='somevalue')