Skip to main content

Convert Markdown to BBCode using a custom Mistune renderer.

Project description

Publish to PyPI

md2bbcode logo

md2bbcode

A wrapper and plugin for Mistune. It converts GitHub-flavored Markdown to Xenforo-flavored BBCode. Custom BBCodes made for RedGuides are included in bb_codes.xml.

Installation

You can install md2bbcode using pip:

pip install md2bbcode

Usage

After installation, you can use md2bbcode from the command line:

md2bbcode README.md

If the markdown includes relative images or other assets, you can use the --domain flag to prepend a domain to the relative URLs:

md2bbcode README.md --domain https://raw.githubusercontent.com/RedGuides/md2bbcode/main/

You can also use the package in your Python project:

from md2bbcode.main import process_readme

# Your Markdown content
markdown_text = "# Hell World"

# Optional domain to prepend to relative URLs
domain = 'https://raw.githubusercontent.com/yourusername/yourrepo/main/'

# Convert Markdown to BBCode
bbcode_output = process_readme(markdown_text, domain=domain)

# Output the BBCode
print(bbcode_output)

Debug Mode

You can use the --debug flag to save intermediate results to files for debugging:

md2bbcode README.md --debug

Development

If you want to contribute to md2bbcode or set up a development environment, follow these steps:

  1. Clone the repository:

    git clone https://github.com/RedGuides/md2bbcode.git
    cd md2bbcode
    
  2. Install Hatch, which is used for building and managing the project:

    pip install hatch
    
  3. Create a development environment and install dependencies:

    hatch env create
    
  4. Activate the development environment:

    hatch shell
    

renderers/bbcode.py

The custom plugin for Mistune, which converts AST to bbcode.[^1]

[^1]: Mistune does not convert Markdown HTML to AST, hence the need for html2bbcode.

Additional Tools

html2bbcode

Converts several HTML tags typically allowed in Markdown to BBCode.[^2]

[^2]: Currently used for post-processing mistune output, but there's a better way. See inside the file for a suggestion.

html2bbcode input_file.html

md2ast

For debugging Mistune's renderer, converts a Markdown file to AST (JSON format).

md2ast input.md output.json

Features Test

Here are a few GitHub-flavored Markdown features so you can use this README.md for testing:

  • Strikethrough: This text is struck through.

  • Superscript: This text is normal and this is superscript.

  • Table:

    Syntax Description
    Header Title
    Paragraph Text

Todo

  • refactor html2bbcode
  • update for new Xenforo 2.3 and 2.4 BBCode

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

md2bbcode-1.0.9.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

md2bbcode-1.0.9-py2.py3-none-any.whl (23.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file md2bbcode-1.0.9.tar.gz.

File metadata

  • Download URL: md2bbcode-1.0.9.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for md2bbcode-1.0.9.tar.gz
Algorithm Hash digest
SHA256 59eae2cb39ee9bc2c95b33302d1c06ef0465c3db6b28ccf73b7d7e5ebfc65c20
MD5 0bfd87bf20a0694507994810733839e1
BLAKE2b-256 8ad140c2f36aab46e4eae623adca056f2174116309b24996d26e4fc3b6643414

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2bbcode-1.0.9.tar.gz:

Publisher: publish.yml on RedGuides/md2bbcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file md2bbcode-1.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: md2bbcode-1.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for md2bbcode-1.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 381f661535cbd6abaaef340e94835e256202be0c59db47c728a8ea5ccf4ff762
MD5 4c2afd0a18cd11cdfe22ebd0046b85b4
BLAKE2b-256 360dd71368770e2a3fb5a6a542906bca3f6a45ddb2102967a21f9ec5a01c8fde

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2bbcode-1.0.9-py2.py3-none-any.whl:

Publisher: publish.yml on RedGuides/md2bbcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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