Skip to main content

Convert Markdown to BBCode using a custom Mistune renderer.

Project description

Publish to PyPI

md2bbcode logo, original image 'A Specious Origin' by Jerry LoFaro.

md2bbcode

A wrapper and plugin for Mistune. It converts most GitHub-flavored Markdown to Xenforo-flavored BBCode.

[!TIP] Custom BBCodes made for RedGuides are included in bb_codes.xml, import the ones you want in your Xenforo installation at admin.php?bb-codes. Some custom BBCodes include css, which you can split off to your extra.css template for more efficiency.

[!NOTE]
This project is made with LLM assistance.

Usage

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

md2bbcode README.md

Output prints to stdout as UTF-8. To write straight to a file (recommended on Windows, where shell > redirection can mangle the encoding), use -o:

md2bbcode README.md -o output.bbcode

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. Create a development environment and install dependencies:

    hatch env create
    
  3. 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 most HTML tags typically allowed in Github Flavored Markdown to BBCode.[^2]

[^2]: Currently used for post-processing mistune output. Reference: https://github.github.com/gfm/#raw-html

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, including the table:

Feature Markdown Rendered
Bold **text** bold
Italic *text* italic
Strikethrough ~~text~~ struck
Code `code` inline
Link [text](url) example
Superscript <sup>2</sup> E=mc2
Subscript <sub>2</sub> H2O
HTML spoiler (details/summary)

html2bbcode test. This is hidden content. Water is H2O.

Font tag inside details size 3 Arial red

Inline style inside details green times new roman strikethrough italic bold underline

This is a quote by John Doe

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.1.1.tar.gz (27.1 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.1.1-py2.py3-none-any.whl (28.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: md2bbcode-1.1.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for md2bbcode-1.1.1.tar.gz
Algorithm Hash digest
SHA256 5ca5ca17f644ac6f7bf8cf9ab14e2772678f08ded51fa82a32ef533ac5358d2d
MD5 c5bb8162c6c3a28a9879b9d95890ec8a
BLAKE2b-256 aa16e352dbc0e96f4f32ddba03482a8c7e0fa3583c9acebccd38bcedd7e91003

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2bbcode-1.1.1.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.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: md2bbcode-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for md2bbcode-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b0bf43cb377bc2ff741d9a09b47125376f793e7b905ce43f84bd7dc2a57a5874
MD5 03ea32e265ddd768fe8b89cd93dac065
BLAKE2b-256 2fdc27f42b3a3d4e84da7cee095f62ee5e59432af5361ec813b77c0ae5094d60

See more details on using hashes here.

Provenance

The following attestation bundles were made for md2bbcode-1.1.1-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