⚠️ Oops! This page doesn't appear to define a type called _.
Edit

A markdown parser in OCaml, with no extra dependencies.

This module represents this entire Markdown library written in OCaml only.

Its main purpose is to allow you to use the Markdown library while keeping you away from the other modules.

If you want to extend the Markdown parser, you can do it without accessing any module of this library but this one, and by doing so, you are free from having to maintain a fork of this library.

N.B. This module is supposed to be reentrant, if it's not then please report the bug.

other items defined

Representation of Markdown documents

type t = list(element)

Representation of a Markdown document.

type ref_container = < add_ref : string -> string -> string -> unit; get_all : (string * (string * string)) list; get_ref : string -> (string * string) option >

type element = | H1(t) | H2(t) | H3(t) | H4(t) | H5(t) | H6(t) | Paragraph(t) | Text(string) | Emph(t) | Bold(t) | Ul(list(t)) | Ol(list(t)) | Ulp(list(t)) | Olp(list(t)) | Code(name, string) | Code_block(name, string) | Br | Hr | NL | Url(href, t, title) | Ref(ref_container, name, string, fallback) | Img_ref(ref_container, name, alt, fallback) | Html(name, list((string, option(string))), t) | Html_block(name, list((string, option(string))), t) | Html_comment(string) | Raw(string) | Raw_block(string) | Blockquote(t) | Img(alt, src, title) | X( < name : string; to_html : ?indent:int -> (t -> string) -> t -> string option; to_sexpr : (t -> string) -> t -> string option; to_t : t -> t option > ) = element

A element of a Markdown document.

type fallback = < to_string : string; to_t : t >

Fallback for references in case they refer to non-existant references

type name = string

Markdown reference name.

type alt = string

HTML img tag attribute.

type src = string

HTML attribute.

type href = string

HTML attribute.

type title = string

HTML attribute.

type code_stylist = (~lang: string, string) => string

Function that takes a language name and some code and returns that code with style.

Input and Output

let of_string: ( ~?extensions: option(extensions), ~?default_lang: option(name), string ) => t

of_string s returns the Markdown representation of the string s.

Param: lang

language for blocks of code where it was not specified. Default: "".

If you want to use a custom lexer or parser, use lex and parse.

let of_bigarray: ( ~?extensions: option(extensions), ~?default_lang: option(name), bigstring ) => t

As of_string, but read input from a bigarray rather than from a string.

let set_default_lang: (name, t) => t

set_default_lang lang md return a copy of md where the language of all Code or Code_block with an empty language is set to lang.

let to_html: ( ~?override: option(element => option(string)), ~?pindent: option(bool), ~?nl2br: option(bool), ~?cs: option(code_stylist), t ) => string

Translate markdown representation into raw HTML. If you need a full HTML representation, you mainly have to figure out how to convert Html of string and Html_block of string into your HTML representation.

let to_markdown: t => string

Translate markdown representation into textual markdown.

let to_text: t => string

Translate markdown representation into raw text.

Tansforming Markdown documents

let toc: ( ~?start: option(list(int)), ~?depth: option(int), t ) => t

toc md returns toc a table of contents for md.

Param: start

gives the section for which the TOC must be built. For example ~start:[2;3] will build the TOC for subsections of the second H1 header, and within that section, the third h2 header. If a number is 0, it means to look for the first section at that level but stop if one encounters any other subsection. If no subsection exists, an empty TOC [] will be returned. Default: [] i.e. list all sections, starting with the first H1.

Param: depth

the table of contents. Default: 2.