Giter Site home page Giter Site logo

html2phpbbcode's Introduction

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:[email protected]">Mail Water.org</a>')
'[[email protected]]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.

html2phpbbcode's People

Contributors

tdiam avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

html2phpbbcode's Issues

[pip install] "error in html2bbcode setup command: use_2to3 is invalid."

Hello,

FWIW, I just tried installing it to use with Python 3.8.10 , and it fails:

c:\>pip install html2phpbbcode
Collecting html2phpbbcode
  Downloading html2phpbbcode-0.1.4-py3-none-any.whl (5.9 kB)
Collecting regex
  Downloading regex-2022.10.31-cp38-cp38-win32.whl (255 kB)
     ---------------------------------------- 255.8/255.8 kB 629.6 kB/s eta 0:00:00
Collecting html2bbcode
  Downloading html2bbcode-2.3.3.tar.gz (3.3 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  x python setup.py egg_info did not run successfully.
  ¦ exit code: 1
  ?-> [1 lines of output]
      error in html2bbcode setup command: use_2to3 is invalid.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

x Encountered error while generating package metadata.
?-> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Cheers,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.