From 7259e325b4e502530f701cbded78e2ab0dbea187 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Tue, 3 May 2022 19:23:51 +0200 Subject: [PATCH 1/4] add constructors for values of type `Omd.doc` Fixes: #252 --- src/omd.ml | 35 +++++++++++++++++++++++++++++++++++ src/omd.mli | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/omd.ml b/src/omd.ml index 6104ad75..55ae6d8f 100644 --- a/src/omd.ml +++ b/src/omd.ml @@ -14,6 +14,41 @@ let parse_inlines (md, defs) = in List.map (Mapper.map (parse_inline defs)) md +let txt ?(attrs = []) s = Text (attrs, s) + +let em ?(attrs = []) il = Emph (attrs, il) + +let strong ?(attrs = []) il = Strong (attrs, il) + +let code ?(attrs = []) s = Code (attrs, s) + +let hard_break attrs = Hard_break attrs + +let soft_break attrs = Soft_break attrs + +let link ?(attrs = []) li = Link (attrs, li) + +let img ?(attrs = []) li = Image (attrs, li) + +let html ?(attrs = []) s = Html (attrs, s) + +let pg ?(attrs = []) il = Paragraph (attrs, il) + +let ul ?(attrs = []) ?(spacing = Loose) l = List (attrs, Bullet '-', spacing, l) + +let ol ?(attrs = []) ?(spacing = Loose) l = + List (attrs, Ordered (1, '.'), spacing, l) + +let blq ?(attrs = []) blocks = Blockquote (attrs, blocks) + +let hr attrs = Thematic_break attrs + +let code_block ?(attrs = []) ~label s = Code_block (attrs, label, s) + +let html_block ?(attrs = []) s = Html_block (attrs, s) + +let def_list ?(attrs = []) l = Definition_list (attrs, l) + let of_channel ic = parse_inlines (Pre.of_channel ic) let of_string s = parse_inlines (Pre.of_string s) let to_html doc = Html.to_string (Html.of_doc doc) diff --git a/src/omd.mli b/src/omd.mli index f0b3f6ee..312e52b5 100644 --- a/src/omd.mli +++ b/src/omd.mli @@ -46,6 +46,48 @@ type 'attr block = type doc = attributes block list (** A markdown document *) +val txt : ?attrs:attributes -> string -> attributes inline + +val em : ?attrs:attributes -> attributes inline -> attributes inline + +val strong : ?attrs:attributes -> attributes inline -> attributes inline + +val code : ?attrs:attributes -> string -> attributes inline + +val hard_break : attributes -> attributes inline + +val soft_break : attributes -> attributes inline + +val link : ?attrs:attributes -> attributes link -> attributes inline + +val img : ?attrs:attributes -> attributes link -> attributes inline + +val html : ?attrs:attributes -> string -> attributes inline + +val pg : ?attrs:attributes -> attributes inline -> attributes block + +val ul : + ?attrs:attributes + -> ?spacing:list_spacing + -> attributes block list list + -> attributes block + +val ol : + ?attrs:attributes + -> ?spacing:list_spacing + -> attributes block list list + -> attributes block + +val blq : ?attrs:attributes -> attributes block list -> attributes block + +val hr : attributes -> attributes block + +val code_block : ?attrs:attributes -> label:string -> string -> attributes block + +val html_block : ?attrs:attributes -> string -> attributes block + +val def_list : ?attrs:attributes -> attributes def_elt list -> attributes block + val of_channel : in_channel -> doc val of_string : string -> doc val to_html : doc -> string From f913b5983ceb4228ea5c81f1ccdbb59242b7330d Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Fri, 13 May 2022 06:42:34 +0200 Subject: [PATCH 2/4] remove attributes for {soft,hard}_break and hr --- src/omd.ml | 6 +++--- src/omd.mli | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/omd.ml b/src/omd.ml index 55ae6d8f..5b777261 100644 --- a/src/omd.ml +++ b/src/omd.ml @@ -22,9 +22,9 @@ let strong ?(attrs = []) il = Strong (attrs, il) let code ?(attrs = []) s = Code (attrs, s) -let hard_break attrs = Hard_break attrs +let hard_break = Hard_break [] -let soft_break attrs = Soft_break attrs +let soft_break = Soft_break [] let link ?(attrs = []) li = Link (attrs, li) @@ -41,7 +41,7 @@ let ol ?(attrs = []) ?(spacing = Loose) l = let blq ?(attrs = []) blocks = Blockquote (attrs, blocks) -let hr attrs = Thematic_break attrs +let hr = Thematic_break [] let code_block ?(attrs = []) ~label s = Code_block (attrs, label, s) diff --git a/src/omd.mli b/src/omd.mli index 312e52b5..729d5764 100644 --- a/src/omd.mli +++ b/src/omd.mli @@ -54,9 +54,9 @@ val strong : ?attrs:attributes -> attributes inline -> attributes inline val code : ?attrs:attributes -> string -> attributes inline -val hard_break : attributes -> attributes inline +val hard_break : attributes inline -val soft_break : attributes -> attributes inline +val soft_break : attributes inline val link : ?attrs:attributes -> attributes link -> attributes inline @@ -80,7 +80,7 @@ val ol : val blq : ?attrs:attributes -> attributes block list -> attributes block -val hr : attributes -> attributes block +val hr : attributes block val code_block : ?attrs:attributes -> label:string -> string -> attributes block From ab6c48da1f15e7c3c971ee273064a445fbdfe8be Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Fri, 13 May 2022 06:54:09 +0200 Subject: [PATCH 3/4] fmt --- src/omd.ml | 15 --------------- src/omd.mli | 14 -------------- 2 files changed, 29 deletions(-) diff --git a/src/omd.ml b/src/omd.ml index 5b777261..012604c7 100644 --- a/src/omd.ml +++ b/src/omd.ml @@ -15,40 +15,25 @@ let parse_inlines (md, defs) = List.map (Mapper.map (parse_inline defs)) md let txt ?(attrs = []) s = Text (attrs, s) - let em ?(attrs = []) il = Emph (attrs, il) - let strong ?(attrs = []) il = Strong (attrs, il) - let code ?(attrs = []) s = Code (attrs, s) - let hard_break = Hard_break [] - let soft_break = Soft_break [] - let link ?(attrs = []) li = Link (attrs, li) - let img ?(attrs = []) li = Image (attrs, li) - let html ?(attrs = []) s = Html (attrs, s) - let pg ?(attrs = []) il = Paragraph (attrs, il) - let ul ?(attrs = []) ?(spacing = Loose) l = List (attrs, Bullet '-', spacing, l) let ol ?(attrs = []) ?(spacing = Loose) l = List (attrs, Ordered (1, '.'), spacing, l) let blq ?(attrs = []) blocks = Blockquote (attrs, blocks) - let hr = Thematic_break [] - let code_block ?(attrs = []) ~label s = Code_block (attrs, label, s) - let html_block ?(attrs = []) s = Html_block (attrs, s) - let def_list ?(attrs = []) l = Definition_list (attrs, l) - let of_channel ic = parse_inlines (Pre.of_channel ic) let of_string s = parse_inlines (Pre.of_string s) let to_html doc = Html.to_string (Html.of_doc doc) diff --git a/src/omd.mli b/src/omd.mli index 729d5764..6e622bf3 100644 --- a/src/omd.mli +++ b/src/omd.mli @@ -47,23 +47,14 @@ type doc = attributes block list (** A markdown document *) val txt : ?attrs:attributes -> string -> attributes inline - val em : ?attrs:attributes -> attributes inline -> attributes inline - val strong : ?attrs:attributes -> attributes inline -> attributes inline - val code : ?attrs:attributes -> string -> attributes inline - val hard_break : attributes inline - val soft_break : attributes inline - val link : ?attrs:attributes -> attributes link -> attributes inline - val img : ?attrs:attributes -> attributes link -> attributes inline - val html : ?attrs:attributes -> string -> attributes inline - val pg : ?attrs:attributes -> attributes inline -> attributes block val ul : @@ -79,15 +70,10 @@ val ol : -> attributes block val blq : ?attrs:attributes -> attributes block list -> attributes block - val hr : attributes block - val code_block : ?attrs:attributes -> label:string -> string -> attributes block - val html_block : ?attrs:attributes -> string -> attributes block - val def_list : ?attrs:attributes -> attributes def_elt list -> attributes block - val of_channel : in_channel -> doc val of_string : string -> doc val to_html : doc -> string From 40a3cadd1de7970efd4f6e79a107816304eed874 Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Wed, 1 Jun 2022 08:07:35 +0200 Subject: [PATCH 4/4] update names --- src/omd.ml | 16 ++++++++-------- src/omd.mli | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/omd.ml b/src/omd.ml index 012604c7..50b579b6 100644 --- a/src/omd.ml +++ b/src/omd.ml @@ -18,22 +18,22 @@ let txt ?(attrs = []) s = Text (attrs, s) let em ?(attrs = []) il = Emph (attrs, il) let strong ?(attrs = []) il = Strong (attrs, il) let code ?(attrs = []) s = Code (attrs, s) -let hard_break = Hard_break [] -let soft_break = Soft_break [] -let link ?(attrs = []) li = Link (attrs, li) +let br = Hard_break [] +let nl = Soft_break [] +let a ?(attrs = []) li = Link (attrs, li) let img ?(attrs = []) li = Image (attrs, li) let html ?(attrs = []) s = Html (attrs, s) -let pg ?(attrs = []) il = Paragraph (attrs, il) +let p ?(attrs = []) il = Paragraph (attrs, il) let ul ?(attrs = []) ?(spacing = Loose) l = List (attrs, Bullet '-', spacing, l) let ol ?(attrs = []) ?(spacing = Loose) l = List (attrs, Ordered (1, '.'), spacing, l) -let blq ?(attrs = []) blocks = Blockquote (attrs, blocks) +let blockquote ?(attrs = []) blocks = Blockquote (attrs, blocks) let hr = Thematic_break [] -let code_block ?(attrs = []) ~label s = Code_block (attrs, label, s) -let html_block ?(attrs = []) s = Html_block (attrs, s) -let def_list ?(attrs = []) l = Definition_list (attrs, l) +let code_bl ?(attrs = []) ~label s = Code_block (attrs, label, s) +let html_bl ?(attrs = []) s = Html_block (attrs, s) +let dl ?(attrs = []) l = Definition_list (attrs, l) let of_channel ic = parse_inlines (Pre.of_channel ic) let of_string s = parse_inlines (Pre.of_string s) let to_html doc = Html.to_string (Html.of_doc doc) diff --git a/src/omd.mli b/src/omd.mli index 6e622bf3..134c1640 100644 --- a/src/omd.mli +++ b/src/omd.mli @@ -50,12 +50,12 @@ val txt : ?attrs:attributes -> string -> attributes inline val em : ?attrs:attributes -> attributes inline -> attributes inline val strong : ?attrs:attributes -> attributes inline -> attributes inline val code : ?attrs:attributes -> string -> attributes inline -val hard_break : attributes inline -val soft_break : attributes inline -val link : ?attrs:attributes -> attributes link -> attributes inline +val br : attributes inline +val nl : attributes inline +val a : ?attrs:attributes -> attributes link -> attributes inline val img : ?attrs:attributes -> attributes link -> attributes inline val html : ?attrs:attributes -> string -> attributes inline -val pg : ?attrs:attributes -> attributes inline -> attributes block +val p : ?attrs:attributes -> attributes inline -> attributes block val ul : ?attrs:attributes @@ -69,11 +69,11 @@ val ol : -> attributes block list list -> attributes block -val blq : ?attrs:attributes -> attributes block list -> attributes block +val blockquote : ?attrs:attributes -> attributes block list -> attributes block val hr : attributes block -val code_block : ?attrs:attributes -> label:string -> string -> attributes block -val html_block : ?attrs:attributes -> string -> attributes block -val def_list : ?attrs:attributes -> attributes def_elt list -> attributes block +val code_bl : ?attrs:attributes -> label:string -> string -> attributes block +val html_bl : ?attrs:attributes -> string -> attributes block +val dl : ?attrs:attributes -> attributes def_elt list -> attributes block val of_channel : in_channel -> doc val of_string : string -> doc val to_html : doc -> string