Enter HaCoTeB
by Mithrandir
I am dissatisfied with the WordPress.com code posting capabilities. All of the possible solutions (using the included <code> tag or the included [ code ] plug-in or posting the entire html generated from the code via vim’s TOhtml or via highlight) were incomplete.
I wanted something which will allow me to write the post in a text file using some syntax (Creole, Markdown, my own) for markup and with the ability to introduce source code with a simple paste or some other markups. Afterward, the tool will convert the entire file to an HTML which will be used to enter the blog post into WordPress blogs (right now, I don’t care about other platforms).
For this purpose, I created HaCoTeB. Even if it is in his infancy, the project can be used to make simple posts like this one (yet, it still needs a lot of editing in the WordPress editor :().
For example, the following code section lists the Main.hs file (yes, Ha from the name means Haskell) of the project.
module Main where
import HaCoTeB
main = do
s <- readFile "test"
writeFile "test.html" $ representFileContent s
Because this post is short, I intend to give below the entire source file used to generate it.
END
I am dissatisfied with the Wordpress.com code posting capabilities. All of the
possible solutions using the included <code> tag or the included
plug-in or posting the entire html generated from the code via vim's TOhtml or
via highlight) were incomplete.
END
I wanted something which will allow me to write the post in a text file using
some syntax Creole, Markdown, my own) for markup and with the ability to
introduce source code with a simple paste or some other markups. Afterward,
the tool will convert the entire file to an HTML which will be used to enter
the blog post into Wordpress blogs right now, I don't care about other
platforms).
END
For this purpose, I created HaCoTeB. Even if it is in his infancy, the project
can be used to make simple posts like this one.
END
For example, the following code section lists the Main.hs file (yes, Ha from
the name means Haskell) of the project.
END
[c]
module Main where
import HaCoTeB
main = do
s <- readFile "test"
writeFile "test.html" $ representFileContent s
END
[t]
Because this post is short, I intend to give below the entire source file used
to generate it.
END
[co]
...
END
...
As you can see, the sections are divided by a separator (think multipart HTTP responses) and their type is given by the first line of the section (if of the form [..]) or is implicit. What is written in the brackets is any prefix of the proper type, allowing for lazy typing :).
That’s all. I will come up with a new version in a few more days, one which will have the basic text parsing capabilities (including proper highlighting of links and text formatting like bold or alignment). And one which will solve the bugs found while posting this.
I expect you are aware that the pandoc package on Hackage can convert Markdown to html. I am adding wiki-creole support — I hope to submit code to the package maintainer soon.
That looks nice. TFS. Have you considered using hevea (an ocaml tool to convert latex to html)?
Depending on your requirements, you might find (literate haskell , lhs2tex , hevea) combo decent.
@Dave,
Can it do something like taking a file which contains text and source code (in the most advanced form as a reference to a file and some line numbers) and output it in a valid HTML just to be pasted into WordPress? With syntax colouring for code and many formatting options?
@kapilash
At the beginning of this year I had one big toolchain for posting code. But it was buggy and I had to do it in steps if I wanted to include code from multiple files or not in the same order as it is in a file
The website has a tutorial about [scripting with Pandoc](http://johnmacfarlane.net/pandoc/scripting.html) — the illlustrations include: the peculiariities of WordPress Latex; including files, or chunks of them, etc. I haven’t used syntax highlight but it is possible to compile it with the `highlighting-kate` library — or maybe you could rope in `hscolour` or [illuminate](http://github.com/jgm/illuminate)
Thanks. Will look upon it :)
How does this differ from BlogLiterately: http://hackage.haskell.org/package/BlogLiterately ?
I believe that BlogLiterately is intended for Haskell only. At least, this was what I believed first time when I looked upon it.
Nope; BlogLiterately now supports all other languages that highlighting-kate does (so it says; I’ve never tried it myself).
Well, I’m still working on this. At least for experience gathering :)