1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586moduletypeBlockContent=sigtype'atendmoduleStringContent=structtype'attrt=stringendmoduleInlineContent=structtype'attrt='attrAst_inline.inlineendmoduleList_types=structtypelist_type=|Orderedofint*char|Bulletofchartypelist_spacing=|Loose|TightendmoduleTable_alignments=structtypecell_alignment=|Default|Left|Centre|RightendopenList_typesopenTable_alignmentsmoduleMake(C:BlockContent)=structtype'attrdef_elt={term:'attrC.t;defs:'attrC.tlist}(* A value of type 'attr is present in all variants of this type. We use it to associate
extra information to each node in the AST. Cn the common case, the attributes type defined
above is used. We might eventually have an alternative function to parse blocks while keeping
concrete information such as source location and we'll use it for that as well. *)type'attrblock=|Paragraphof'attr*'attrC.t|Listof'attr*list_type*list_spacing*'attrblocklistlist|Blockquoteof'attr*'attrblocklist|Thematic_breakof'attr|Headingof'attr*int*'attrC.t|Code_blockof'attr*string*string|Html_blockof'attr*string|Definition_listof'attr*'attrdef_eltlist|Tableof'attr*('attrC.t*cell_alignment)list*'attrC.tlistlist(** A table is represented by a header row, which is a list of pairs of
header cells and alignments, and a list of rows *)endmoduleMakeMapper(Src:BlockContent)(Dst:BlockContent)=structmoduleSrcBlock=Make(Src)moduleDstBlock=Make(Dst)letrecmap(f:'attrSrc.t->'attrDst.t):'attrSrcBlock.block->'attrDstBlock.block=function|SrcBlock.Paragraph(attr,x)->DstBlock.Paragraph(attr,fx)|List(attr,ty,sp,bl)->List(attr,ty,sp,List.map(List.map(mapf))bl)|Blockquote(attr,xs)->Blockquote(attr,List.map(mapf)xs)|Thematic_breakattr->Thematic_breakattr|Heading(attr,level,text)->Heading(attr,level,ftext)|Definition_list(attr,l)->letf{SrcBlock.term;defs}={DstBlock.term=fterm;defs=List.mapfdefs}inDefinition_list(attr,List.mapfl)|Code_block(attr,label,code)->Code_block(attr,label,code)|Html_block(attr,x)->Html_block(attr,x)|Table(attr,headers,rows)->Table(attr,List.map(fun(header,alignment)->(fheader,alignment))headers,List.map(List.mapf)rows)endmoduleMapper=MakeMapper(StringContent)(InlineContent)moduleRaw=Make(StringContent)moduleWithInline=Make(InlineContent)