Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constructors for values of type Omd.doc #268

Merged
merged 6 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/omd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ 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 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 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 blockquote ?(attrs = []) blocks = Blockquote (attrs, blocks)
let hr = Thematic_break []
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)
Expand Down
28 changes: 28 additions & 0 deletions src/omd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ 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 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 p : ?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 blockquote : ?attrs:attributes -> attributes block list -> attributes block
val hr : 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
Expand Down