Use Markdown Instead Of BBCode With Vimperator

(You can suggest changes to this post.)

I really love the Dwarf Fortress community, and a lot of it is centred around the bay12 forums. Unfortunately, I don’t love BBCode (aka phpBB syntax), which is what the bay12 forums require me to write posts in. I’d much rather use markdown. So I decided to fix that with the help of vimperator, and by writing my own markdown to BBcode parser.

If you install the Markdown::phpBB module from the CPAN, you’ll find a nifty little program named md2phpbb. This is a filter; it takes input in markdown, and emits output in BBcode.

$ cpanm Markdown::phpBB     # install using cpanm
$ cpan  Markdown::phpBB     # install using classic cpan

If you’re editing in vim, you can run :%!md2phpbb to replace your current buffer (written in markdown) with the equivalent text in BBcode. You can even bind it to a key, as I’ve done in my ~/.vimrc file:

:nmap <F5> :%!md2phpbb<CR>

If you’ve installed md2phpbb into a user (rather than system) directory, then you may find that vimperator won’t have your perl-specific environment variables in place. In that case you can use full paths in your ~/.vimrc:

:nmap <F5> :%!perl -I/home/pjf/perl5/lib/perl5 /home/pjf/perl5/bin/md2phpbb<CR>

If you’re using vimperator then you can already invoke vim from any textarea by pressing ctrl-i. However BBcode websites usually bind this to italics, so you’ll probably want to add an additional key for editing to your ~/.vimperatorrc file. I use ctrl-e, for edit:

:inoremap <C-e> <C-i>

Now you can use ctrl-e to open a vim window, write your response in markdown, and then just hit F5 to turn it into BBCode. Best of all, the filter doesn’t change existing BBCode at all, so you can hit F5 as many times as you like, to refresh your text after edits.

md2phpbb and supporting libraries are completely free and open source, and can be found on github.


See also: The world’s easiest guide to installing cpanm

Bitcoin QR code This site is ad-free, and all text, style, and code may be re-used under a Creative Commons Attribution 3.0 license. If like what I do, please consider supporting me on Patreon, or donating via Bitcoin (1P9iGHMiQwRrnZuA6USp5PNSuJrEcH411f).

comments powered by Disqus