#! /bin/bash

cat $1 | ruby -pe 'puts " "*20 if $_.match("^```$")' \
  | pandoc -f markdown -t textile \
  | ruby -r cgi -n -e 'print CGI.unescapeHTML($_);' \
  | ruby -ne 'puts $_ unless $_.match(" "*20)' \
  > $2

# without spaces, pandoc outputs "bc." for code blocks, which isn't accepted to redmine
# it also annoyingly HTML escapes its pre- block contents
# for more info, see https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Writers/Textile.hs#L136 
# see http://johnmacfarlane.net/pandoc/README.html#bullet-lists for nested bullet syntax
