bbcoder is a command-line application which simplifies the writing of complex BBCode posts. When a post reaches a certain size and complexity, I find it can become difficult to find your place in your code to make a simple change, a problem that is compounded when you wish to make the same change in multiple areas.
Enter bbcoder. Instead of writing BBCode, you write in a simple, custom XML-based markup language I have created called BBXML. If you've ever written some HTML, it should look very familiar. BBXML offers the following features over BBCode:
- Classes: you can assign a class to any BBCode which has an option (e.g. [DIV=]). A class is mostly intended for CSS properties in combination with[DIV], but it could be used for any type of option content. You start by defining a class somewhere in your project, giving it a name and a value; you can then re-use that class's value for any tag, avoiding the need to copy-paste CSS properties constantly.
- Templates: if a class isn't enough, you can use a template. This is a more powerful tool as it lets you define a BBXML template, with optional parameters, then insert that template in your post. A simple example is a status box for your character: you would define the formatting once, and then for every subsequent post you just have to include the status box template, filling it in with the character's mood, location, etc.
- Project structure: BBXML can be split over multiple files that are then combined to create a single BBCode post. This allows you to define commonly-used code in one file and create one file for each new post you make.
- Insensitive to whitespace or newlines: being able to make a new paragraph just by pressing Enter is convenient when writing standard RP posts, but for formatting-heavy posts it can be a nightmare. BBXML requires that line breaks be explicitly specified with the <br />tag.
- XML-based syntax: one indirect advantage of using BBXML is that it will look very familiar to most editors. This means you can get all the advantages of traditional code editors, such as syntax coloration, auto-completion, etc.
- Browser extension: you don't have to install bbcoder if you want to try it out. Check out the Chrome and Firefox browser extensions, which add a BBXML editor to RpNation.
The new workflow when using bbcoder is to create your project, build one of its targets (i.e. a specific post), and copy the resulting BBCode to your post. This may be improved somewhat in later releases.
C
Usage
Quick Start
- Download bbcoder for your system
- Extract the archive contents somewhere on your computer
- Run bbcoder
- Windows: just double-click on the bbcoder.exefile
- macOS: make a note of the location where you extracted bbcoder, open Terminal, type cd /the/path/to/your/bbcoder/folder(replacing it with the actual path to the contents of the archive), then type./bbcoder
- Other operating systems: you'll have to compile the program from source for your system.
- Windows: just double-click on the
- You should now have a file in the targets/folder calledsample-post.txt. Congratulations, you've just built your first BBXML target!
Installation
bbcoder consists of a single executable file, bundled with a starting project structure. To install it, just download the archive, extract it somewhere on your computer, and you're set up!
If you just wish to try out the functionality or don't need the full flexibility of a project, you can download and install the browser extensions instead.
Setting up your project
bbcoder works on BBXML projects - a set of files linked together through inclusions and a master project definition file. bbcoder is distributed with a skeleton project you can fill in as you go, consisting of the following files:
- project.xml: this file defines your project and lets bbcoder know where the other files are. It consists of the following sections:
- : defines a set of paths to BBXML files located anywhere on your computer. Useful if you want to have a common folder located outside of your project directory, for example.
- : defines the targets (i.e. posts) which bbcoder will build. Each target has a name and a source file: bbcoder reads the source file, then outputs the target BBCode in a file with the target's name. By default, all targets that are defined will be built, but you can set the defaultattribute to the target you want to build. In the sample project, it only defines one target calledsample-post.
- src/sample.xml: a sample BBXML post file. When you run bbcoder, this will create a file calledtarget/sample-post.txt.
Of course, this is just a very basic project. As an example, my personal project currently consists of about 20 post files, along with a few library files (i.e. files that are only included, not used to build posts), all organized within several folders.
Creating a new target
Say you want to create a new target: you'll need to create a new source file for it and a new target entry in
project.xml
. A source file consists of four key sections.The
include
tags allow you to include other files in this project, which lets you re-use classes and templates defined in other files.The
classes
section defines the classes you can use in your project. Each class is identified by a name and a value. The value can be arbitrary text, but this is usually CSS and functions somewhat like a CSS class.The
templates
section contains template definitions. You can see these as more advanced classes, which you can use when you want to re-use a bunch of code. Templates can contain parameters, which take the form of {your_parameter_name}
. These will be replaced by their new values when the templates are included. The inside of a template works just like the body
section.Finally, the
body
contains your actual post. Here, almost any tag you use will be interpreted as a BBCode tag (e.g. <b></b>
is the same as [b][/b]
). There are a few key differences however:- Classes and options: every BBCode tag supports options using =can have a class (or classes) and an option specified. Theclassattribute can be used to specify a list of space-separated classes, while theoptionattribute indicates values specific to this tag. They can be used together, in which case the specific option will be appended to the end of the class's value. Example:<div class="class1 class2" option="background-color: yellow;">
- Including templates: you can include templates using the <include>tag, which indicates the name of the template to include. The body of the tag then contains a list of<p>tags indicating the values of the template's parameters. The value can be simple text or additional BBXML code.
- Line breaks: you have to explicitly require a line break using the special <br />tag.
- Lists: list elements must be surrounded by <li></li>tags instead of prefixed by[*]
Note: you can abbreviate a lot of these names:
- The class,optionandtemplateattributes can be shortened toc,oandt, respectively.
- The div,includeandparamtags can be abbreviated tod,inandp, respectively.
Building
You can then build your project simply by running bbcoder from the root of your project. The resultant BBCode will be in the
target/
subdirectory.C
Downloads
The current version is 0.2.0. This is a stable release - it is mostly feature-complete, and while there might be a few bugs, they are likely to be very minor.
The recommended way of running bbcoder is from the command-line (on Windows this is the Command Prompt by default, and on macOS this is the Terminal).
As an example of a setup: I use IntelliJ IDEA (a free IDE) for editing BBXML projects. I have configured bbcoder as an External Tool and bound it to F10 - whenever I want to build the BBCode, I just hit F10 and copy the result.
Warning: your browser may inform you that the file is potentially dangerous because it is not frequently downloaded. This is normal. If you have any doubts as to its security, feel free to look at the source code and to compile it yourself.
Windows: bbcoder-win-0.2.0.zip
macOS: bbcoder-mac-0.2.0.zip (the macOS build might lag behind a few versions)
Google Chrome extension: https://chrome.google.com/webstore/detail/bbcoder-for-rpnation/ldbjelfkggmnndhpmnanakbgjfgmooho/
Firefox extension: https://addons.mozilla.org/en-GB/firefox/addon/bbcoder-for-rpnation/
Source Code: https://github.com/Lyrositor/bbcoder
C
Planned Features
I am planning on working on the following features for upcoming releases; this is not a promise that they will be released, just an indication of what I'd like to see implemented:
- Aliasing: BBXML can be very verbose (as is XML), and I would like to provide a way to alias certain frequently-repeated parts.
- Live preview: I have an idea of how this could be implemented. Essentially, it would watch your project, and whenever a file is updated, it re-compiles the BBCode and displays a preview of the result in your browser.
- Better error messages: it's not always clear where an error in your project comes from currently; I hope to improve this.
- Ease of use: various quality of life improvements to make installing and using bbcoder simpler
Known bugs
- Circular includes aren't currently detected
C
License
bbcoder is licensed under the CC0 1.0 Universal license. Essentially, it has been released into the public domain, and you are free to use, modify or distribute its code without providing attribution (though it would be appreciated).
C
Source
The BBXML source code for the original version of this post has been provided as an example:
- project.xml: https://gist.github.com/Lyrositor/a8d0b9f1609c78d7cec2b402980f9103
- src/lib/common.xml: https://gist.github.com/Lyrositor/0e214d0039cb5204bcc2475281d88a14
- src/bbcoder-post.xml: https://gist.github.com/Lyrositor/c0cf4577e955ceca4cc4ac2362767b0a
- BBCode: https://gist.githubusercontent.com/Lyrositor/391f4d60b3a6a60eac17204c4da6dcaf/raw/bbcode.txt
Last edited: