1 (* Copyright (C) 2009 Mauricio Fernandez <mfp@acm.org> *)
6 let rec elm_to_html ~render_pre ~render_link ~render_img elm
=
7 let self = elm_to_html ~render_pre ~render_link ~render_img
in
8 let item l
= li
(List.map
self l
)
11 Normal text
-> p
(par_text_to_html ~render_link ~render_img text
)
12 | Pre
(s
, kind
) -> begin match kind
with
13 Some k
-> render_pre ~kind
:k s
14 | None
-> pre
[pcdata s
]
16 | Heading
(l
, text
) ->
18 match l
with 1 -> h1
| 2 -> h2
| 3 -> h3
| 4 -> h4
| 5 -> h5
| _
-> h6
19 in f (par_text_to_html render_link render_img text
)
20 | Quote ps
-> blockquote
(List.map
self ps
)
21 | Ulist
(fst
, others
) ->
22 ul
(item fst
) (List.map
item others
)
23 | Olist
(fst
, others
) ->
24 let item l
= li
(List.map
self l
) in
25 ol
(item fst
) (List.map
item others
)
27 and par_text_to_html ~render_link ~render_img
=
28 List.map
(text_to_html ~render_link ~render_img
)
30 and text_to_html ~render_link ~render_img
= function
32 | Emph s
-> em
[pcdata s
]
33 | Bold s
-> b
[pcdata s
]
34 | Struck l
-> del
(List.map
(text_to_html ~render_link ~render_img
) l
)
35 | Code s
-> code
[pcdata s
]
38 a ~a:[XHTML.M_01_00.a_name_01_00 id] []
39 but that'd require switching to M_01_00 everywhere, so cheap hack *)
41 | Link href
-> begin match href
.href_target
with
42 s
when String.length s
>= 1 && s
.[0] = '#'
->
43 a ~a
:[a_href
(uri_of_string s
)] [pcdata href
.href_desc
]
44 | _
-> render_link href
46 | Image href
-> render_img href
48 let to_html ~render_pre ~render_link ~render_img l
=
49 List.map
(elm_to_html ~render_pre ~render_link ~render_img
) l