Textile markup language support for OCaml

If you can read this text, this library works fine.

Features

It supports:

It doesn't (yet1) support:

Highlighting a code inside blockcodes

Are you guessing what textile attribute "language" stands for? Of course, it can be used to indicate in what language this code was written. So code highlighting can be gone with camlhighlight. See:

Example from gikia-common/highlight.in.ml and gikia-common/markup.ml:

let to_xhtml ?lang linenums s =
  let c =
    (try
      Camlhighlight_parser.from_string ?lang s
    with _ ->
      Camlhighlight_parser.from_string s) in
  write ~dummy_lines:false ~linenums c

let to_string ?lang linenums s =
  to_xhtml ?lang linenums s >> Duce_printer.string_of_xhtml

let string_of_textile escape tt =
  let f = function
    | Textile.Blockcode ((attrs, _, _), strings) ->
        let linenums = List.length strings > 1 in
        let lang = try Some (exude (function
          | Textile.Language s -> Some s
          | _ -> None) attrs) with Not_found -> None in
        let s = String.concat "\n" strings in
        Highlight.to_string ?lang linenums s
    | b -> Textile_html.of_block ~escape b in
  let next _ =
    try
      Some (f (Stream.next tt))
    with Stream.Failure -> None in
  let stream = Stream.from next in
  let buf = Buffer.create 1024 in
  Stream.iter (Buffer.add_string buf) stream;
  Buffer.contents buf

Another branches

Old branch

Inlcudes unreadable handmade parser.

With camlp5

The previous code looks too imperative and ugly for me, so I've tried to rewrite it with functional streams and parsers from camlp5. But it becomes tens times slower because Fstream.of_channel and other fstream/fparser things. Anyway, you can find this branch here:

1 See TODO file.