Skip to content
Snippets Groups Projects
Commit 6b0195a6 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[Lib/Markdown] optimisation of empty and nil

parent d0f6ca84
No related branches found
No related tags found
No related merge requests found
......@@ -65,11 +65,13 @@ let local ctxt job data =
(* --- Combinators --- *)
(* -------------------------------------------------------------------------- *)
let nil _fmt = ()
let empty= nil
let space fmt = Format.pp_print_space fmt ()
let newline fmt = Format.pp_print_newline fmt ()
let merge sep ds fmt =
match ds with
match List.filter (fun d -> d != nil) ds with
| [] -> ()
| d::ds -> d fmt ; List.iter (fun d -> sep fmt ; d fmt) ds
......@@ -78,9 +80,20 @@ let glue ?sep ds fmt =
| None -> List.iter (fun d -> d fmt) ds
| Some s -> merge s ds fmt
let (<@>) a b fmt = a fmt ; b fmt
let (<+>) a b fmt = a fmt ; space fmt ; b fmt
let (</>) a b fmt = a fmt ; newline fmt ; b fmt
let (<@>) a b =
if a == empty then b else
if b == empty then a else
fun fmt -> a fmt ; b fmt
let (<+>) a b =
if a == empty then b else
if b == empty then a else
fun fmt -> a fmt ; space fmt ; b fmt
let (</>) a b =
if a == empty then b else
if b == empty then a else
fun fmt -> a fmt ; newline fmt ; b fmt
let fmt_text k fmt = Format.fprintf fmt "@[<h 0>%t@]" k
let fmt_block k fmt = Format.fprintf fmt "@[<v 0>%t@]" k
......@@ -151,8 +164,6 @@ let href ?title (h : href) fmt =
(* --- Blocks --- *)
(* -------------------------------------------------------------------------- *)
let empty _fmt = ()
let aname anchor fmt =
Format.fprintf fmt "<a name=\"%s\"></a>@\n" anchor
......
......@@ -42,6 +42,7 @@ val (</>) : block -> block -> block (** Infix operator for [concat] *)
(** {2 Text Constructors} *)
val nil : text (** Empty *)
val raw : string -> text (** inlined markdown format *)
val rm : string -> text (** roman (normal) style *)
val it : string -> text (** italic style *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment