Textile markup language support for OCaml
If you can read this text, this library works fine.
- darcs repository:
darcs get http://komar.in/darcs/textile-ocaml/
- Release sources in tarballs.
- last api docs
Features
It supports:
- stream parsing of textile markup language (
Textile_parser
) to abstract syntax tree (Textile
); - outputing HTML via ordinary OCaml strings (
Textile_html
) or via OCamlduce types from Ocsigen moduleXhtmltypes_duce
(Textile_duce
); - optional HTML escaping;
- command-line tool textiler.
It doesn't (yet1) support:
- replacing symbols to another, "much easer on the eye", like in RedCloth;
- URL encoding;
- link declaration like
"hobix":hobix [hobix]http://hobix.com
.
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.
darcs get http://komar.in/darcs/textile-ocaml-old/
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:
darcs get http://komar.in/darcs/textile-fstream/