open ExtLib
open Printf
type attr =
| Class of string
| Id of string
| Style of string
| Language of string
type img_float =
| Float_left
| Float_right
type phrase =
| CData of string
| Emphasis of (attr list * phrase list)
| Strong of (attr list * phrase list)
| Italic of (attr list * phrase list)
| Bold of (attr list * phrase list)
| Citation of (attr list * phrase list)
| Deleted of (attr list * phrase list)
| Inserted of (attr list * phrase list)
| Superscript of (attr list * phrase list)
| Subscript of (attr list * phrase list)
| Span of (attr list * phrase list)
| Code of (attr list * string)
| Notextile of string
| Acronym of string * string
| Image of attr list * img_float option
* string * string option
| Link of (attr list * phrase list) *
string option * string
| Reference of int
type line =
phrase list
type talign =
| Right
| Left
| Center
| Justify
type valign =
| Top
| Middle
| Bottom
type padding =
int * int
type options =
attr list * talign option * padding
type cellspan =
int option * int option
type tableoptions =
options * valign option
type celltype =
| Data
| Head
type celloptions =
celltype * tableoptions * cellspan
type cell =
celloptions * line list
type row =
tableoptions * cell list
type element =
int * line
type block =
| Header of int * (options * line list)
| Blockquote of (options * line list)
| Footnote of int * (options * line list)
| Paragraph of (options * line list)
| Blockcode of (options * string list)
| Pre of (options * string list)
| Blocknott of (options * string list)
| Numlist of element list
| Bulllist of element list
| Table of (tableoptions * row list)
let rec string_of_line line =
let buf = Buffer.create 512 in
let add = Buffer.add_string buf in
let rec loop = function
| h::t -> (match h with
| CData s -> add s
| Emphasis (_, l)
| Strong (_, l)
| Italic (_, l)
| Bold (_, l)
| Citation (_, l)
| Deleted (_, l)
| Inserted (_, l)
| Superscript (_, l)
| Subscript (_, l)
| Span (_, l) ->
add (string_of_line l)
| Acronym (s, _)
| Code (_, s) ->
add s
| Notextile s ->
add s
| Image _ -> ()
| Link ((_, l), _, _) ->
add (string_of_line l)
| Reference i ->
Printf.bprintf buf "[%d]" i);
loop t
| [] -> Buffer.contents buf in
loop line