Convert Markdown to BBCode using a custom Mistune renderer.
Project description
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 atadmin.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 (derogatory).
Installation
Install as a CLI tool with pipx:
pipx install md2bbcode
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 import process_readme
bbcode = process_readme("# Hell World")
print(bbcode)
Pass a domain to rewrite relative URLs (e.g. images and links in a repo README) to absolute ones:
bbcode = process_readme(
markdown_text,
domain="https://raw.githubusercontent.com/yourusername/yourrepo/main/",
)
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:
-
Clone the repository:
git clone https://github.com/RedGuides/md2bbcode.git cd md2bbcode
-
Create a development environment and install dependencies:
hatch env create
-
Activate the development environment:
hatch shell
renderers/bbcode.py
The custom plugin for Mistune, which converts AST to bbcode.1
Additional Tools
html2bbcode
Converts most HTML tags typically allowed in Github Flavored Markdown to BBCode.2
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~~ |
|
| 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
-
Mistune does not convert Markdown HTML to AST, hence the need for
html2bbcode. ↩ -
Currently used for post-processing mistune output. Reference: https://github.github.com/gfm/#raw-html ↩
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md2bbcode-1.1.2.tar.gz.
File metadata
- Download URL: md2bbcode-1.1.2.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65a2a8c869af7a3b21a9eb3ac7f408e82dabd3240da22b07467175eb99647b52
|
|
| MD5 |
1b5c93116788de41646fd2ff5bcc9b30
|
|
| BLAKE2b-256 |
d6b846e3fa2993dcecfe40a26ac4b1b5e1d0041e22fdf4b8b7168845ecf513eb
|
Provenance
The following attestation bundles were made for md2bbcode-1.1.2.tar.gz:
Publisher:
publish.yml on RedGuides/md2bbcode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2bbcode-1.1.2.tar.gz -
Subject digest:
65a2a8c869af7a3b21a9eb3ac7f408e82dabd3240da22b07467175eb99647b52 - Sigstore transparency entry: 2087038467
- Sigstore integration time:
-
Permalink:
RedGuides/md2bbcode@2b70ca5dd0cce295ca5b548320c6344a933b019a -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/RedGuides
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2b70ca5dd0cce295ca5b548320c6344a933b019a -
Trigger Event:
push
-
Statement type:
File details
Details for the file md2bbcode-1.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: md2bbcode-1.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd91fe0ac969f6d0d8fb9b2166c870728e2a3973c178ed108715f775d3846666
|
|
| MD5 |
813bad8239b04a68d11168941ac78142
|
|
| BLAKE2b-256 |
858d8b198ce67a38f32eaa7ba40d2b106e7604ced21ec146a8d989ee3a597a3b
|
Provenance
The following attestation bundles were made for md2bbcode-1.1.2-py2.py3-none-any.whl:
Publisher:
publish.yml on RedGuides/md2bbcode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2bbcode-1.1.2-py2.py3-none-any.whl -
Subject digest:
fd91fe0ac969f6d0d8fb9b2166c870728e2a3973c178ed108715f775d3846666 - Sigstore transparency entry: 2087038918
- Sigstore integration time:
-
Permalink:
RedGuides/md2bbcode@2b70ca5dd0cce295ca5b548320c6344a933b019a -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/RedGuides
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2b70ca5dd0cce295ca5b548320c6344a933b019a -
Trigger Event:
push
-
Statement type: