123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223openAst.ImplmoduletypeIntf=sig(** Functions to help constructing the elements of a {!doc}.
E.g.,
{[
let open Omd.Ctor in
let para =
p ~attrs:[ ("class", "my-para") ] [ txt "Content of"; em "this"; txt "paragraph" ]
in
[ blockquote [ para; hr; p [ txt "Content of second paragraph" ] ] ]
]}
Produces
{v
<blockquote>
<p class="my-para">Content of<em>this</em>paragraph</p>
<hr />
<p>Content of second paragraph</p>
</blockquote>
v}
The optional [attrs] argument always defaults to an empty list, and can
generally be omitted. *)(** {3 Constructors for inline elements} *)valempty:attributesinline(** [empty] is an empty inline element. *)valtxt:?attrs:attributes->string->attributesinline(** [txt ~attrs s] is {{!Text} [Text (attrs, s)]}. *)valem:?attrs:attributes->string->attributesinline(** [em ~attrs s] is {{!Emph} [Emph (attrs, txt s)]}. See {!txt}. *)valstrong:?attrs:attributes->string->attributesinline(** [strong ~attrs s] is {{!Strong} [Strong (attrs, txt s)]}. See {!txt}. *)valcode:?attrs:attributes->string->attributesinline(** [code ~attrs s] is {{!Code} [Code (attrs, s)]}. *)valbr:attributesinline(** [br] is {{!Hard_break}[Hard_break []]}. *)valnl:attributesinline(** [nl] is {{!Soft_break}[Soft_break []]}. *)vala:?attrs:attributes->?title:string->url:string->string->attributesinline(** [a ~attrs ~title ~url label] is a link around the text of [label],
pointing to the [url], with the optional title [title] and additional [attrs].
See {!Link}. *)valimg:?attrs:attributes->?title:string->alt:string->string->attributesinline(** [img ~attrs ~title ~alt src] is an image from the given [src] that has the
[alt] text as a fallback, with the optional title [title] and additional
[attrs]. See {!Image}. *)valhtml:string->attributesinline(** [html s] is an inline HTML string. See {!Html}. *)(** {3 Constructors for block-level elements} *)valp:?attrs:attributes->attributesinlinelist->attributesblock(** [p ~attrs inlines] is a pragraph block holding the given [inline]
elements. See {!Paragraph}. *)valul:?attrs:attributes->?spacing:list_spacing->attributesblocklistlist->attributesblock(** [ul ~attrs ~spacing items] is an unordered list with the specified [spacing], listing
the given [items]. Each item is a list of block elements.
- [spacing] defaults to {!Loose}.
E.g.,
{[
ul ~spacing:Tight
[ [ p [ txt "Item 1" ] ]
; [ p [ txt "Item 2" ] ]
; [ p [ txt "Item 3" ] ]
]
]}
See {!List} and {!Bullet}. *)valol:?attrs:attributes->?start:int->?char:[`Dot|`Paren]->?spacing:list_spacing->attributesblocklistlist->attributesblock(** [ol ~attrs ~start ~char ~spacing items] is like {!ul}, but constructs an ordered list,
where [start] is the number to start enumerating from, and [char] indicates the
character following the number in the enumeration.
- [char] can be either [`Dot] indicating ['.'] or [`Paren] indicating [')'], and
defaults to [`Dot].
- [start] defaults to [1].
See {!List} and {!Ordered}. *)valblockquote:?attrs:attributes->attributesblocklist->attributesblock(** [blockquote ~attrs blocks] is a blockquote element containing the given
[blocks]. See {!Blockquote}. *)valhr:attributesblock(** [hr] is {{!Thematic_break} [Thematic_break []]}. *)valh:?attrs:attributes->int->attributesinlinelist->attributesblock(** [h ~attrs level inlines] is a heading of the given [level] comprised of
the [inlines]. See {!Heading}. *)valcode_bl:?attrs:attributes->?lang:string->string->attributesblock(** [code_bl ~attrs ~lang code] is a code block labeled with language [lang].
- [lang] defaults to being absent.
See {!Code_block} *)valhtml_bl:?attrs:attributes->string->attributesblock(** [html_bl ~attrs html] is a block-level element of raw HTML. See {!Html_block}. *)type'attrctor_def_elt={term:'attrinlinelist;defs:'attrinlinelistlist}(** Type for the items given to {!dl} definition lists. It is isomorphic to {!def_elt}. *)valdl:?attrs:attributes->attributesctor_def_eltlist->attributesblock(** [dl ~attrs elements] is a definition list of the given [elements]. See
{!Definition_list}.
E.g.,
{[
dl
[ { term = [ txt "def term 1" ]
; defs =
[ [ txt "definition 1.1" ]
; [ txt "definition 1.2" ]
; [ txt "definition 1.3" ]
]
}
; { term = [ txt "def term 2" ]
; defs =
[ [ txt "definition 2.1" ]
; [ txt "definition 2.2" ]
; [ txt "definition 2.3" ]
]
}
]
]} *)endmoduleImpl:Intf=structletconcatelems=Concat([],elems)letempty=concat[]lettxt?(attrs=[])s=Text(attrs,s)letem?(attrs=[])s=Emph(attrs,txts)letstrong?(attrs=[])s=Strong(attrs,txts)letcode?(attrs=[])s=Code(attrs,s)letbr=Hard_break[]letnl=Soft_break[]leta?(attrs=[])?title~urllabel=Link(attrs,{label=txtlabel;destination=url;title})letimg?(attrs=[])?title~altsrc=Image(attrs,{label=txtalt;destination=src;title})(* Note that attributes are not actually supported Html nodes currently. *)lethtmls=Html([],s)(* Block constructors *)letp?(attrs=[])inlines=Paragraph(attrs,concatinlines)letul?(attrs=[])?(spacing=Loose)items=List(attrs,Bullet'-',spacing,items)letol?(attrs=[])?(start=1)?(char=`Dot)?(spacing=Loose)items=letc=matchcharwith`Dot->'.'|`Paren->')'inList(attrs,Ordered(start,c),spacing,items)letblockquote?(attrs=[])blocks=Blockquote(attrs,blocks)lethr=Thematic_break[]leth?(attrs=[])levelinlines=Heading(attrs,level,concatinlines)letcode_bl?(attrs=[])?(lang="")s=Code_block(attrs,lang,s)lethtml_bl?(attrs=[])s=Html_block(attrs,s)type'attrctor_def_elt={term:'attrinlinelist;defs:'attrinlinelistlist}letdl?(attrs=[])(items:'attrctor_def_eltlist)=letdef_elt_of_pair{term;defs}:'attrdef_elt=letterm=concatterminletdefs=List.mapconcatdefsin{term;defs}inletdef_elts=List.mapdef_elt_of_pairitemsinDefinition_list(attrs,def_elts)end