Module Cmarkit.Doc

Documents (and parser).

Documents

type t

The type for CommonMark documents.

val nl : t -> Layout.string

nl d is the first newline found in the text during parsing or "\n" if there was none.

val block : t -> Block.t

block d is the document's contents as a block.

val defs : t -> Label.defs

defs d are the label definitions resulting from parsing d. The result depends on the label definitions found in the source and the defs and resolver values specified on Doc.of_string.

val make : ?nl:Layout.string -> ?defs:Label.defs -> Block.t -> t

make ~nl ~defs b is a document for block b with newline nl (defaults to "\n"), label definition defs (defaults to Label.Map.empty).

val empty : t

empty is an empty document.

Parsing

val of_string : ?defs:Label.defs -> ?resolver:Label.resolver -> ?nested_links:bool -> ?heading_auto_ids:bool -> ?layout:bool -> ?locs:bool -> ?file:Textloc.fpath -> ?strict:bool -> string -> t

of_string md is a document from the UTF-8 encoded CommonMark document md.

  • If strict is true (default) the CommonMark specification is followed. If false these extensions are enabled.
  • file is the file path from which s is assumed to have been read (defaults to Textloc.file_none), used in the Textloc.t values iff locs is true.
  • If locs is true locations are stored in nodes of the abstract syntax tree in individually identified Meta.t values. If false (default) node meta values are all Meta.none whose text location is Textloc.none.
  • If layout is false (default) layout values cannot be relied upon and do not in general represent source layout, some fields may be normalized. The Block.Blank_line, Block.Link_reference_definition, Block.Ext_footnote_definition, layout block values are present in the result regardless of this parameter.
  • If heading_auto_ids is true (defaults to false) then `Auto heading identifiers are generated during parsing from the header text with Inline.id (at that point no ext argument is needed) and made accessible in Block.Heading.id. Note that the identifiers may not be unique, we leave it to the backends to handle this problem.
  • If nested_links is true (defaults to false) there is no restriction on having links in link text, which is forbidden by CommonMark and HTML. This can be useful for embedding DSLs in link labels or destinations. Note that image links already allow link nesting as per CommonMark specification.
  • If resolver is provided this is used resolve label definitions and references. See here for details. Defaults to Label.default_resolver.
  • If defs adds these label definitions to the document (defaults to Label.Map.empty). Think of them as being prepended to md. If resolver is Label.default_resolver, these take over the same labels defined in md (first definition takes over in CommonMark).

UTF-8 decoding errors and U+0000 are turned into Uchar.rep characters. Inlines of the result should be Inline.normalized. Blocks of the result should be Block.normalized.

Note. For simple renders parsing with layout:false and locs:false is generally faster; having these to true allocates quite a bit.

Versions

val unicode_version : string

unicode_version is the Unicode version known to of_string.

val commonmark_version : string

commonmark_version is the CommonMark version known to of_string.