When I was writing changelogs for my QuickSwitch project, I needed to convert them from Markdown markup language to BBcode markup language for posting on forums.
That is how this converter was developed. It was successfully tested on the latest complex changelog.
Here's the list of key features:
- Full support for GitHub markdown syntax (basic and advanced).
- Support for html tags and spoilers.
- Delete comments, mark text that does not need to be converted.
- Recursive block elements conversion (lists containing lists, basic syntax containing basic syntax, etc).
- Support for any type of list (ordered, unordered, with any prefix and nesting level).
- Attaching / detaching markdown list items from BBcode lists (ability to add or detach quotes and other items from the converted list).
- Support for multi-level quotes with the ability to include lists, mentions, and other syntax.
- Support for Github issues, commits and relative to the selected repository root links.
- Restore text to its pre-conversion state for editing.
- Convert, copy, and clear with a single click.
- Convert file and save result to the new / existing file.
- Command line interface (CLI) for converting different files and combining their contents into a single file.
It uses the Maple Mono font for GUI elements. If something is not working for you, please let me know. If you think that app can be improved, write to me.
The converter supports basic syntax, complex blocks, and tables. For example, the tables with examples below can also be converted to BBcode tables (without alignment).
Basic syntax | |
---|---|
|
|
|
|
|
|
|
|
|
Links | |
---|---|
[Short name](link) | |
 |
Html tags | |
---|---|
|
|
|
|
Simple text |
Tags <details>
on GitHub are similar to spoilers: they turn into collapsed text. The <summary>
tag replaces the spoiler title "details" with the specified title.
Unknown tags are converted to headers. All converted spoilers and unknown tags will have an additional line break for readability.
Spoilers and comments | |
---|---|
|
|
Text that shouldn't be converted | |
Line breaks | |
---|---|
Line with trailing slash\ New line |
Line with trailing slash New line |
Line with 2 trailing spaces NewLine |
Line with 2 trailing spaces NewLine |
Line breaks affect the final appearance of BBcode lists and quotes, but do not affect the appearance of tables: a Markdown table can contain line breaks and they will be captured by the BBcode table. A Markdown list or quote can contain line breaks, but they may not be included in the BBcode list or quote (see detailed examples below).
Spaces between markup and words are optional, as well as spaces inside and outside tags and comments. It means that ** Bold **
and **Bold**
or <!-- alternate -->
and <!--alternate-->
are treated the same.
The blocks below are converted into opening and closing BBcode tags, split into several lines for readability (otherwise everything will turn into a horrible mess). Empty lines, spaces, and tabs between tags do not affect the rendered BBcode.
To reduce the demonsration, some tags are on the single line.
Code | |
---|---|
|
|
|
|
Block quotes | |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Lists | |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Links and images can be relative to the repository root (it usually starts with /
). You can specify the repository in the converter settings. All relative links will be appended into the repository URL. You can use all relative link operands, such as ./
or ../
. Relative link text should be on a single line.
The correctness of the converted link is not checked for performance reasons. Make sure that after adding the repository into the relative link, it is correct.
Relative links | |
---|---|
[Relative readme](./README.md) |
|
|
|
|
All issues and commits in short form will be appended into the repository URL. The converter cannot check whether #64
is a Pull Request (PR), discussion, or issue, so it always assumes that it is an issue.
Issues (PRs is not supported) | |
---|---|
|
|
|
|
|
|
|
Commits | |
---|---|
896111015666c8fa7a8b390232a52e79356319c4 |
|
|
|
The command interface allows you to convert files and any text directly from the terminal. The result can be saved to a file or printed to the terminal and passed to any command using the |
pipe operator.
You can use auto-completion for CLI directly in Powershell 5.1 and above. This requires an auto-completion module, such as PSReadLine and Register-AutocompleteCommand.
Auto-completion setup
Add the path to the directory containing md2bb.exe
to the path environment variable:
setx PATH "$env:path;\the\directory\to\add" -m
Then open the profile:
notepad $PROFILE
If you're using Cmder or Conemu, open %CMDER_ROOT%\config\user_profile.ps1
.
Add the following command:
Register-AutocompleteCommand -Commands 'md2bb'
# Set auto-complete list view
$options = @{
PredictionSource = 'HistoryAndPlugin'
PredictionViewStyle = 'ListView'
}
Set-PSReadLineOption @options
# Assign an auto-complete key, such as `Tab`
Set-PSReadLineKeyHandler -Chord 'Tab' -Function 'MenuComplete'
Restart your PC. Now, after entering md2bb and pressing Tab
, you will see a list of available parameters and their descriptions. When entering arguments, such as -repo
, you can press Tab
again to read its description. Press Tab
again to have autocomplete type the parameter for you.
Usage: md2bb (<file_name> | <text> | @listfile) [<parameters> <switches>]
Parameters | |
---|---|
-save, -write | The name / path of the file where to write the result. The result will be appended at the end of the file if it already exists. |
-repo, -repository, -domain | Url to the repository for resolving relative links and references. |
-sep, -separator, -delimiter | Separator for text parameters concatenation. |
Switches | |
---|---|
-h, -help | Displays help message. |
-overwrite | Overwrite the file where to write the result. |
Parameters order doesn't matter:
md2bb -save 'forum.md' 'readme.md'
md2bb 'readme.md' -save 'forum.md'
Text can be combined:
md2bb 'readme.md' 'add text' 'another text' 'license.md' -sep ' '
md2bb 'sentence' 'will be' 'splitted' -save 'forum.md'
The value of -repo
is stored on the disk, so it can be passed once. After that its value will be used for each md2bb
usage:
md2bb -repo 'https://github.com/JoyHak/MarkdownToBBCode' -> 'Repository has been saved'
md2bb 'issue #1' -> issue [url=https://github.com/JoyHak/MarkdownToBBCode/issues/1]#1[/url]
Parameters prefix can be / - --
.
Parameter without prefix will be treated as file name / text / listfile to convert:
md2bb 'readme.md' 'add text' '@listfile.md'
Reads and converts contents of 'readme.md', then converts 'add text', then reads and converts contents of 'listfile.md' line by line.
@listfile
can be @filename.ext
or @path
and it can contain anything. It will be readed and each line will be converted as the text. If line contains file name / path, it's contents will be converted (if it exists). Also it can be used to convert individual lines, combine them into one text and separate using symbol passed via -sep
.
You can pass the |
symbol as a text to force the separation of parts of the text from each other:
md2bb 'readme.md|@listfile.md'
Reads and converts 'readme.md' file, then reads and converts 'listfile.md' line by line.
md2bb 'sentence|will be|splitted'
Convert 'sentence' 'will be' 'splitted' separately.
Pass -sep
symbol to concatenate different parts:
md2bb 'sentence|will be|splitted' -sep '_' -> 'sentence_will be_splitted'
md2bb 'sentence' 'will be' 'splitted' -sep '_' -> 'sentence_will be_splitted'
md2bb 'readme.md' 'add text' -sep '_' -save 'forum.md'
Concatenates converted contents of 'readme.md' with 'add text' using '_' symbol and appends it to the 'forum.md'.
You can pass multi-line text and -sep
value:
md2bb ' > Multi-line -> [quote]Multi-line
> text' text[/quote]
md2bb '*New*' '*line*' -sep ' -> [i]New[/i]
+' [i]+line[/i]
You can also pass any line break tags to get several lines of the text:
md2bb '_New_<br>_line_' -> [i]New[/i]
[i]line[/i]
md2bb 'New<br/>line' -sep '+' -> [i]New[/i]
[i]line[/i]
Ignores '-sep' because text is treated as single part.
The -save
parameter appends the converted text at the end of existing file, removing all leading and trailing spaces, tabs, and blank lines. This allows you to create complex conversion chains:
md2bb 'readme.md' 'add text' '@listfile.md' 'add another text' '@lines.md' -save 'forum.md'
If you want to recreate the file, use -overwrite
switch:
md2bb 'readme.md' -save 'readme.md'
Appends converted contents of 'readme.md' at the end of this file.
md2bb 'readme.md' -save 'readme.md' -overwrite
Deletes 'readme.md' and appends converted content to the new 'readme.md'
To convert individual elements to different files, use separate commands:
md2bb 'readme.md' 'add text' -save 'forum.md'
md2bb 'license.md' 'add copyright' -save 'lic.md'