Skip to content

Instantly share code, notes, and snippets.

@qerub
Created November 29, 2009 22:05
Show Gist options
  • Save qerub/245091 to your computer and use it in GitHub Desktop.
Save qerub/245091 to your computer and use it in GitHub Desktop.
textile+lhs2html
#!/usr/bin/env ruby
#
# textile+lhs2html
#
# A script for transforming Literate Haskell
# with Textile-formatted text to HTML with
# the help of Ruby and RedCloth.
#
# Written by Christoffer Sawicki in 2009.
# Released into the public domain.
require "redcloth"
require "erb" # for ERB::Util.h
def interact() STDOUT.puts(yield(STDIN.read)) end
interact { |text|
text.split("\n\n").map { |block|
if block.split("\n").all? { |line| line[0] == ?> }
%{<pre><code>#{ERB::Util.h(block)}</code></pre>}
else
RedCloth.new(block).to_html
end
}.join("\n\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment