Skip to content

Commit

Permalink
Add initial explorations of omd_tyxml module
Browse files Browse the repository at this point in the history
  • Loading branch information
shonfeder committed Jun 28, 2020
1 parent 6318e75 commit ec2379d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions omd_tyxml/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name omd_tyxml)
(libraries omd tyxml))
59 changes: 59 additions & 0 deletions omd_tyxml/omd_tyxml.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(* module Html_importer = Xml_stream.signal *)
open Tyxml


(* let rec of_inline (inline : Omd.Inline.t) =
* match inline with
* | Concat ls -> List.concat_map of_inline ls
* | Text t -> [Html.txt t]
* | Emph e -> [of_emph e]
* | Code _ -> raise (Failure "TODO of_inline Code")
* | Hard_break -> raise (Failure "TODO of_inline Hard_break")
* | Soft_break -> raise (Failure "TODO of_inline Soft_break")
* | Link _ -> raise (Failure "TODO of_inline Link")
* | Ref _ -> raise (Failure "TODO of_inline Ref")
* | Html raw -> [Tyxml.Html.Unsafe.data raw]
* | Tag _ -> raise (Failure "TODO of_inline tag")
*
* and of_emph (emph : Omd.Inline.emph) =
* match emph.kind with
* | Omd.Normal -> Html.em (of_inline emph.content)
* | Omd.Strong -> Html.strong (of_inline emph.content)
*
* let of_block (block : Omd.Block.t) =
* match block with
* | Paragraph inline -> Html.p (of_inline inline)
* | List _ -> raise (Failure "TODO of_block")
* | Blockquote _ -> raise (Failure "TODO of_block")
* | Thematic_break -> raise (Failure "TODO of_block")
* | Heading _ -> raise (Failure "TODO of_block")
* | Code_block _ -> raise (Failure "TODO of_block")
* | Html_block _ -> raise (Failure "TODO of_block")
* | Link_def _ -> raise (Failure "TODO of_block")
* | Def_list _ -> raise (Failure "TODO of_block")
* | Tag_block _ -> raise (Failure "TODO of_block") *)

let rec of_omd_html (h : Omd.Html.t) =
match h with
| Omd.Html.Element (eltype, tag, attrs, child) -> of_element eltype tag attrs child
| Omd.Html.Text _ -> (??)
| Omd.Html.Raw _ -> (??)
| Omd.Html.Null -> (??)
| Omd.Html.Concat (_, _) -> (??)

and of_element =
fun element_type tag attrs child ->
match element_type with
| Inline -> of_inline tag attrs child
| Block -> of_block tag attrs child


let of_omd ?(title="") : Omd.t -> Tyxml.Html.doc =
fun omd ->
let omd_html = Omd.Html.of_doc omd in
let title' = title in
let body' = of_omd_html omd_html in
let open Html in
html
(head (title (txt title')) [])
(body body')

0 comments on commit ec2379d

Please sign in to comment.