Skip to content

Commit

Permalink
Migrate to tyxml 4.3 and drop the 2 functors to build generic HTML mo…
Browse files Browse the repository at this point in the history
…dules.
  • Loading branch information
gildor478 committed Oct 15, 2019
1 parent 950b52c commit cc850f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 69 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## v0.2.0 - 2019-10-15

### Changed
- Use Tyxml 4.3, drop Make_Xhtml and Make_Html5 in favor of simply using
MarkdownHTML.text_to_html.

## v0.1.1 - 2013-06-06

### Changed
- Use Tyxml (thanks to Jacques-Pascal Deplaix).
5 changes: 0 additions & 5 deletions CHANGES.txt

This file was deleted.

2 changes: 1 addition & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Library html
FindlibParent: markdown
Path: src
Modules: MarkdownHTML
BuildDepends: markdown, tyxml (>= 3.0)
BuildDepends: markdown, tyxml (>= 4.3)

Executable test
Path: test
Expand Down
70 changes: 7 additions & 63 deletions src/MarkdownHTML.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
(* Copyright (C) 2009 Mauricio Fernandez <mfp@acm.org> *)

module Make_xhtml (Xhtml : Xhtml_sigs.T) = struct

open Markdown
open Xhtml
open Tyxml.Html

let rec elm_to_html ~render_pre ~render_link ~render_img elm =
let self = elm_to_html ~render_pre ~render_link ~render_img in
Expand All @@ -13,59 +11,7 @@ let rec elm_to_html ~render_pre ~render_link ~render_img elm =
Normal text -> p (par_text_to_html ~render_link ~render_img text)
| Pre (s, kind) -> begin match kind with
Some k -> render_pre ~kind:k s
| None -> pre [pcdata s]
end
| Heading (l, text) ->
let f =
match l with 1 -> h1 | 2 -> h2 | 3 -> h3 | 4 -> h4 | 5 -> h5 | _ -> h6
in f (par_text_to_html render_link render_img text)
| Quote ps -> blockquote (List.map self ps)
| Ulist (fst, others) ->
ul (item fst) (List.map item others)
| Olist (fst, others) ->
let item l = li (List.map self l) in
ol (item fst) (List.map item others)

and par_text_to_html ~render_link ~render_img =
List.map (text_to_html ~render_link ~render_img)

and text_to_html ~render_link ~render_img = function
Text s -> pcdata s
| Emph s -> em [pcdata s]
| Bold s -> b [pcdata s]
| Struck l -> del (List.map (text_to_html ~render_link ~render_img) l)
| Code s -> code [pcdata s]
| Anchor id ->
(* would like to do
a ~a:[XHTML.M_01_00.a_name_01_00 id] []
but that'd require switching to M_01_00 everywhere, so cheap hack *)
b ~a:[a_id id] []
| Link href -> begin match href.href_target with
s when String.length s >= 1 && s.[0] = '#' ->
a ~a:[a_href (uri_of_string s)] [pcdata href.href_desc]
| _ -> render_link href
end
| Image href -> render_img href

let to_html ~render_pre ~render_link ~render_img l =
List.map (elm_to_html ~render_pre ~render_link ~render_img) l

end

module Make_html5 (Html5 : Html5_sigs.T with type 'a Xml.wrap = 'a and type 'a wrap = 'a) = struct

open Markdown
open Html5

let rec elm_to_html ~render_pre ~render_link ~render_img elm =
let self = elm_to_html ~render_pre ~render_link ~render_img in
let item l = li (List.map self l)

in match elm with
Normal text -> p (par_text_to_html ~render_link ~render_img text)
| Pre (s, kind) -> begin match kind with
Some k -> render_pre ~kind:k s
| None -> pre [pcdata s]
| None -> pre [txt s]
end
| Heading (l, text) ->
let f =
Expand All @@ -82,24 +28,22 @@ and par_text_to_html ~render_link ~render_img =
List.map (text_to_html ~render_link ~render_img)

and text_to_html ~render_link ~render_img = function
Text s -> pcdata s
| Emph s -> em [pcdata s]
| Bold s -> b [pcdata s]
Text s -> txt s
| Emph s -> em [txt s]
| Bold s -> b [txt s]
| Struck l -> del (List.map (text_to_html ~render_link ~render_img) l)
| Code s -> code [pcdata s]
| Code s -> code [txt s]
| Anchor id ->
(* would like to do
a ~a:[XHTML.M_01_00.a_name_01_00 id] []
but that'd require switching to M_01_00 everywhere, so cheap hack *)
b ~a:[a_id id] []
| Link href -> begin match href.href_target with
s when String.length s >= 1 && s.[0] = '#' ->
a ~a:[a_href (uri_of_string s)] [pcdata href.href_desc]
a ~a:[a_href (uri_of_string s)] [txt href.href_desc]
| _ -> render_link href
end
| Image href -> render_img href

let to_html ~render_pre ~render_link ~render_img l =
List.map (elm_to_html ~render_pre ~render_link ~render_img) l

end

0 comments on commit cc850f4

Please sign in to comment.