HTML to phpBB-compatible BBCode converter
Project description
HTML2PHPBBCode
HTML2PHPBBCode is a Python 3 package that can be used to parse HTML code and convert it to phpBB-compatible BBCode.
Usage
>>> from html2phpbbcode.parser import HTML2PHPBBCode
>>> parser = HTML2PHPBBCode()
>>> parser.feed('<ul><li>Hello</li><li>World</li></ul>')
'[list][*]Hello[*]World[/list]'
>>> parser.feed('<ol><li>one<li>two</ol>')
'[list=1][*]one[*]two[/list]'
>>> parser.feed('<a href="https://water.org">Water.org</a>')
'[url=https://water.org]Water.org[/url]'
>>> parser.feed('<a href="mailto:info@water.org">Mail Water.org</a>')
'[email=info@water.org]Mail Water.org[/email]'
>>> parser.feed('<strong>Hello <i>World</i>. It's a wonderful world</strong>')
"[b]Hello [i]World[/i]. It's a wonderful world[/b]"
Acknowledgements
HTML2PHPBBCode is based on the html2bbcode package of Vladimir Korsun which is available under the BSD License.
The regex package by Matthew Barnett is also used, available under the Python Software Foundation License.
The code includes some regular expressions from the phpBB bulletin board software as well. Minor changes have been made for Python compatibility. phpBB code is available under GNU GPL v2.0.
Differences from html2bbcode
This package differs from html2bbcode in the following:
- The generated BBCode follows the syntax described in phpBB's BBCode guide.
<b>
,<i>
,<u>
,<s>
,<ol>
HTML tags are also supported.<font>
'ssize
attribute handling has been changed so that it maps to reasonable BBCode size values.- If the
href
attribute of an<a>
link uses themailto:
protocol, then the[email]
BBCode tag is used. - If the
href
attribute of an<a>
link is neither an email nor a valid http/https URL, the link is converted to plain-text in BBCode.
Installing
Install dependencies with:
pip install -r requirements.txt
Then install the package:
python setup.py install
Testing
pytest is used for testing. Just run pytest
in the project directory to execute the tests.
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
Built Distribution
Hashes for html2phpbbcode-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e446a6f6bd5744cc9c180fa54df754bc1181044e49604e2367e54fa61e4da16b |
|
MD5 | 0bdcf8f0c30b012167dc7c02175e9dd8 |
|
BLAKE2b-256 | a73e3a0a931c029d728860cd1014a9c89451c2917bcbc6ae5d96500a7390cb3a |