Skip to main content

HTML to phpBB-compatible BBCode converter

Project description

Build Status PyPI version License

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&#39;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>'s size attribute handling has been changed so that it maps to reasonable BBCode size values.
  • If the href attribute of an <a> link uses the mailto: 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.
  • The parser removes excessive whitespace such as newlines between tags: <p>Hello</p>\n<p>World</p> (TODO: Use the W3C spec rules)

Installing

The package is available at PyPI and can be installed with the following command:

pip install html2phpbbcode

Installing from source is also an option:

python3 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

html2phpbbcode-0.1.4.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

html2phpbbcode-0.1.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file html2phpbbcode-0.1.4.tar.gz.

File metadata

  • Download URL: html2phpbbcode-0.1.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.1

File hashes

Hashes for html2phpbbcode-0.1.4.tar.gz
Algorithm Hash digest
SHA256 cd0551d347a3a3cd2dc11462b6845df6086e5e1a6cb2e8702e5650e00714b6c9
MD5 f3fea3208bb9b8d31a3babb0f2ace0d9
BLAKE2b-256 f9b45a73c0d36026e61c903a4bc0099515adce4e957304f2e25b485ff9988ac2

See more details on using hashes here.

File details

Details for the file html2phpbbcode-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: html2phpbbcode-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.1

File hashes

Hashes for html2phpbbcode-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4113caa2b828f8c82ad3e4e783756694591381b6e4f9d26b97ceeb3730b31a21
MD5 54a86e926a14898fc0601a2ebde0fb97
BLAKE2b-256 1bf846ad3fe1f0179a9b50d90405accc203a786863504bfd168dae5c500f3062

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page