Code to Colored MyBB Forum Converter
Convert source code into syntax-highlighted MyBB BBCode with colored tags. Supports 12+ languages for beautiful forum posts.
About
Posting raw code on MyBB forums produces a monochrome wall of text. Readers lose context. Bugs hide in plain sight. This converter tokenizes your source code using a language-aware lexer and wraps each token in the appropriate [color] BBCode tag. It applies distinct colors to keywords, strings, numbers, comments, operators, and identifiers. The output pastes directly into any MyBB-compatible editor. The tokenizer handles single-line comments (//, #), block comments (/* */), nested strings with escape sequences, and language-specific keyword sets for 12 languages including JavaScript, Python, Java, C, PHP, SQL, and Go.
Limitations: this tool performs lexical analysis only. It does not build an AST, so context-dependent highlighting (e.g., distinguishing a function name from a variable) is approximate. Multi-line template literals and heredocs may tokenize imperfectly. For most forum posts under 500 lines, accuracy exceeds 95% of tokens. Pro tip: choose the correct language from the dropdown. The generic fallback applies C-family heuristics which miscolor Python decorators and Ruby symbols.
Formulas
The converter operates as a deterministic finite tokenizer. For a given input string S of length n, the algorithm scans left to right at position i = 0 to n − 1. At each position it attempts to match the longest token using ordered priority rules:
Where Rlang is the ordered ruleset for the selected language. Each rule is a pair (pattern, tokenType). The first matching pattern wins. The output function O maps each token to BBCode:
Where C is the color lookup table mapping token types to hex values. Whitespace tokens pass through unmodified. The final output is the concatenation of all O(Ti) values, optionally wrapped in [font=Courier New]...[/font] for monospace rendering. Time complexity is O(n ⋅ k) where k is the number of rules per language (typically 8 - 15).
Reference Data
| Token Type | Color | Hex Code | Example | MyBB Output |
|---|---|---|---|---|
| Keyword | ■ Medium Slate Blue | #7B68EE | function, if, class | [color=#7B68EE]function[/color] |
| String | ■ Sea Green | #2E8B57 | "hello" | [color=#2E8B57]"hello"[/color] |
| Number | ■ Chocolate | #D2691E | 42, 3.14 | [color=#D2691E]42[/color] |
| Comment | ■ Gray | #808080 | // todo | [color=#808080]// todo[/color] |
| Operator | ■ Indian Red | #CD5C5C | +, =, < | [color=#CD5C5C]+[/color] |
| Punctuation | ■ Dark Gray | #555555 | ( ) { } [ ] ; , | [color=#555555]{[/color] |
| Built-in / Type | ■ Dodger Blue | #1E90FF | console, int, String | [color=#1E90FF]console[/color] |
| Constant / Boolean | ■ Dark Goldenrod | #B8860B | TRUE, NULL, None | [color=#B8860B]true[/color] |
| Identifier | ■ Near Black | #333333 | myVar, count, getData | [color=#333333]myVar[/color] |
| Decorator / Annotation | ■ Purple | #AA22FF | @Override, @property | [color=#AA22FF]@Override[/color] |
| Preprocessor | ■ Lavender | #BC6EC5 | #include, #define | [color=#BC6EC5]#include[/color] |
| Regex Literal | ■ Rose | #DD4488 | /[a-z]+/gi | [color=#DD4488]/[a-z]+/gi[/color] |
| Whitespace | - | - | Spaces, tabs, newlines | (preserved as-is) |