You are not logged in.

#1 2013-08-28 01:40:44

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,443
Website

[script] markdown2bbcode (includes Pandoc BBCode writer)

Introduction

If you find it tedious to use the full formatting range of BBCode when posting longer posts here on the forum then this is for you. This script contains a Pandoc writer that can be used in your own scripts to convert any format recognized by Pandoc to BBCode. The script itself will compile to an executable that converts Markdown on stdin to BBCode on stdout for simplified forum posting.

This entire post was written in Markdown. You can get it here.

Pandoc Simplified BBCode Writer

The writer is simple and could be optimized. It only supports FluxBB's (sub?)set of BBCode, so some formatting features are not supported (e.g. subscripts and superscripts).

Features

Emphasized, strongly emphasized, struckout text and inline code (which I have arbitrarily made red for now).

Code blocks:

$ echo foo

Bullet lists:

  • foo

  • bar

  • baz

Numbered lists:

  1. foo

  2. bar

  3. baz

Alphabetic lists:

  1. foo

  2. bar

  3. baz

Quotes:

And also, Allan insulted me

Images:

test

It also supports headers and links as seen above.

markdown2bbcode

The script's main function will read Markdown from stdin and print BBcode to stdout.

Download

You could also use xacget:

$ xacget markdown2bbcode.hs
Build Dependencies
  • ghc

  • haskell-pandoc

  • upx (optional: for reducing the binary size)

Building
ghc -O2 --make -o markdown2bbcode pandocWriteBbcode.hs

By default GHC will create a relatively large, independent executable. To create a smaller dynamically linked exectuable, use

ghc -dynamic -O2 --make -o markdown2bbcode pandocWriteBbcode.hs

To reduce the size further, use upx:

upx --best markdown2bbcode
Usage

Open an editor, write your post in Markdown, save it to input.md, then run

markdown2bbcode < input.md > output.txt

Open output.txt, copy the contents and paste it into the forum text area. Preview it and then submit if everything looks good.

Package

I will package this if people show interest. I need to figure out how to properly package Haskell modules before I do as this should install Text.Pandoc.Writers.BBCode along with the script markdown2bbcode. I'll try to get to that soon as I have a larger Haskell project that I hope to release in the coming weeks.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2013-09-24 19:13:53

flako
Member
Registered: 2008-10-24
Posts: 56

Re: [script] markdown2bbcode (includes Pandoc BBCode writer)

What an awesome idea. I write most of my stuff in markdown, and was thinking about a solution for converting markdown to BBCode so I googled it and of course wound up at the Community Contributions part of our forum smile

Unfortunately I can't get it to compile, GHC just returns

<no location info>: can't find file: pandocWriteBbcode.hs

I have ghc 7.6.3-1 and haskell-pandoc 1.11.1-8

Offline

#3 2013-09-24 20:23:49

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,443
Website

Re: [script] markdown2bbcode (includes Pandoc BBCode writer)

Sorry, at some point I changed the name of the file without updating the build commands on the page.  It should match the name of the source file, e.g.

 ghc -O2 --make -o markdown2bbcode markdown2bbcode.hs
[1 of 1] Compiling Main             ( markdown2bbcode.hs, markdown2bbcode.o )
Linking markdown2bbcode .

Note that the current version requires haskell-pandoc 1.12. If you can't upgrade, there are 2 lines in the file that can be commented out for pandoc <1.12 support. They are marked in the file with comments. Just prepend "--" to those two lines.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2013-09-25 08:35:52

flako
Member
Registered: 2008-10-24
Posts: 56

Re: [script] markdown2bbcode (includes Pandoc BBCode writer)

Oh, I should have figured that out myself! Thanks for the heads up about haskell-pandoc 1.12. I switched to using the [haskell-core] repo instead. Great script, it does exactly what is says, and using markdown instead of bbcode for long forum post is much quicker/easier.

Offline

Board footer

Powered by FluxBB