123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109moduleRenderAttrs=structmoduleC=Cmarkit_renderer.ContextopenCmarkitletadd_attrc(key,value)=matchvaluewith|Somevalue->C.stringc(" "^key^"="^value)|None->C.stringc(" "^key)letadd_attrsc?(include_id=true)attrs=letkv_attrs=letkv_attrs=Cmarkit.Attributes.kv_attributesattrsinList.map(fun((k,_),v)->letv=matchvwithNone->None|Some(v,_)->Somevin(k,v))kv_attrsinletclass'=letclass'=Cmarkit.Attributes.class'attrsinletclass'=List.map(fun(c,_)->c)class'inmatchclass'with|[]->[]|_->[("class",Some("\""^String.concat" "class'^"\""))]inletid=letid=Cmarkit.Attributes.idattrsinmatchidwith|Some(id,_)wheninclude_id->[("id",Some("\""^id^"\""))]|_->[]inletattrs=id@class'@kv_attrsinList.iter(add_attrc)attrsletopen_block?(with_newline=true)ctagattrs=C.stringc"<";C.stringctag;add_attrscattrs;C.stringc">";ifwith_newlinethenC.stringc"\n"letclose_block?(with_newline=true)ctag=C.stringc"</";C.stringctag;C.stringc">";ifwith_newlinethenC.stringc"\n"letin_blockc?(with_newline=true)tagattrsf=open_block~with_newlinectagattrs;f();close_block~with_newlinectagletwith_attrsc?(with_newline=true)attrsf=ifAttributes.is_emptyattrsthenf()elsein_blockc~with_newline"div"attrsfletwith_attrs_spanc?(with_newline=true)attrsf=ifAttributes.is_emptyattrsthenf()elsein_blockc~with_newline"span"attrsfletblock_linesc=function(* newlines only between lines *)|[]->()|(l,_)::ls->letlinec(l,_)=C.bytec'\n';C.stringclinC.stringcl;List.iter(linec)lsendletcustom_html_renderer=letopenCmarkit_rendererinletopenCmarkitinletopenCmarkit_htmlinletdefault=renderer~safe:false()inletcustom_html=letinlinec=function|Inline.Text((t,(attrs,_)),_)->(* Put text inside spans to be able to apply styles on them *)Context.stringc"<span";add_attrscattrs;Context.bytec'>';html_escaped_stringct;Context.stringc"</span>";true(* | Inline.Ext_attrs (attrs_span, _) -> Context.string c "yooooo"; let (attrs, _) = Inline.Attributes_span.attrs attrs_span and i = Inline.Attributes_span.content attrs_span in RenderAttrs.with_attrs_span c attrs (fun () -> Context.inline c i); *)(* true *)|_->false(* let the default HTML renderer handle that *)inletblockc=function|Ast.Div((b,(attrs,_)),_)->RenderAttrs.with_attrscattrs(fun()->Context.blockcb);true|Ast.SlipScript((cb,(attrs,_)),_)->letattrs=Attributes.add("type",Meta.none)(Some("slip-script",Meta.none))attrsinRenderAttrs.in_blockc"script"attrs(fun()->RenderAttrs.block_linesc(Block.Code_block.codecb));true|_->falseinmake~inline~block()incomposedefaultcustom_html