[ocaml-infra] markdown in "pure" OCaml

Philippe Wang philippe.wang at cl.cam.ac.uk
Thu Jul 25 22:33:29 BST 2013


On Jul 25, 2013, at 17:08 PM, Thomas Gazagnaire <thomas at gazagnaire.org> wrote:

>> I'm currently writing a markdown front-end in pure OCaml (only .ml files). It's a pattern-matching based implementation. It will be kept close to the github flavour markdown. (Sorry, I will probably refuse to reproduce their bugs: I will either replace them by my own bugs or I'll fix them.)
> 
> That's a good news. I am just curious about the fact that you are trying to avoid to write recursive functions. Any specific reasons for that (apart making the code uglier) ?

One of the reason for writing a "pure" OCaml version was that it could easily be embedded on a webpage with Js_of_ocaml (for those who would want that). I believe recursion is not well handled with Js_of_ocaml (please tell me if I'm wrong).

Anyways, I'm trying but not hard at all. I mean, it's so hard (for me) to think and write without recursion, when I'm not **exactly** sure where I'm heading, that for the moment I do it anyway.
So I planned on rewriting the code (later) with as little recursion as possible.

For the moment, I think that absence of recursion would not necessarily make things ugly.

>> I expect to have a working markdown-->html tool in a few days (I believe the hardest part has been done).
> 
> Do you plan to convert that directly to strings ?

The tool (i.e., the binary) will convert (textual) Markdown into (textual) HTML.
The library will provide a front-end with a sort of abstract representation of Markdown (of type md in https://github.com/pw374/omd/blob/master/src/md.ml)
(Now that I look at it, I wonder why there is a constructor "Sp"… it might just disappear tomorrow.)

> A good intermediate representation is the one used by xmlm: 
> 
> type 'a tree = [ `Data of string | `El of ((string * string) * ((string * string) * string) list) * 'a ]
> type t = (('a frag as 'a) frag) list

Polymorphic variants… Well I've realised that I can't understand type errors when I directly program using those. I'm not against using them when my program works, but for the moment, I'll just ignore their existence (I've already spent a lot of time trying to unravel type errors and type inference with polymorphic variants on this markdown project).

> And then you can easily embed HTML paragraphs (as you might sometimes switch to something more expressive than markdown).

I'll see about that; for the moment I'm not sure I get it.

> Last point, I use to have an extension of Mauricio's markdown parser which is able to tag a specific elements with an HTML class (example: @foo{Bla bla} to generate <span class="foo">Bla bla</span>). This is not standard, but very useful when you can tweak the associated CSS, and I'd be very happy if I can add it later to your parser without too much trouble.

Seems nice! I believe it'll be relatively easy to add to the parser (at least, it should be). :)

Philippe




More information about the Infrastructure mailing list