Module Cmarkit.Inline


Note. Document data in inline nodes is always stored unescaped and with entity and character references resolved.


type t = ..

The type for inlines.


module Break : sig ... end

Hard and soft breaks

module Code_span : sig ... end

Code spans.

module Emphasis : sig ... end

Emphasis and strong emphasis.


module Raw_html : sig ... end


module Text : sig ... end


The CommonMark inlines.

val empty : t

empty is Inlines ([], Meta.none).


See the description of extensions.

module Strikethrough : sig ... end


module Math_span : sig ... end

Math span.

type t +=
  1. | Ext_strikethrough of Strikethrough.t node
  2. | Ext_math_span of Math_span.t node

The supported inline extensions. These inlines are only parsed when Doc.of_string is called with strict:false.


val is_empty : t -> bool

is_empty i is true if i is Inline ([], _) or Text ("", _).

val meta : ?ext:(t -> Meta.t) -> t -> Meta.t

meta ~ext i is the metadata of i.

ext is called on cases not defined in this module. The default raises Invalid_argument.

val normalize : ?ext:(t -> t) -> t -> t

normalize i has the same content as i but is such that for any occurence of Inlines (is, _) in i the list of inlines is:

  1. is is not a singleton list.
  2. Has no two consecutive Text _ cases. If that occurs the texts are concatenated, the meta of the first one is kept and its text location extended to include the second one.
  3. Has no Inlines _ case. The meta is dropped and the nested inlines are spliced in is where the case occurs.

ext is called on cases not defined in this module. The default raises Invalid_argument.

val to_plain_text : ?ext:(break_on_soft:bool -> t -> t) -> break_on_soft:bool -> t -> string list list

to_plain_text ~ext ~break_on_soft i has the plain text of i as a sequence of lines represented by a list of strings to be concatenated. If break_on_soft is true soft line breaks are turned into hard line breaks. To turn the result r in a single string apply:

String.concat "\n" ( (String.concat "") r) 

ext is called on cases not defined in this module, it should compile extensions to one of these cases. The default raises Invalid_argument.

val id : ?buf:Stdlib.Buffer.t -> ?ext:(break_on_soft:bool -> t -> t) -> t -> string

id ?buf i derives an identifier for inline i using buf as scratch space (one is created if unspecified).

This converts i to plain text using Inline.to_plain_text, then applies the same normalization performed on labels, maps spaces to character - (U+002D), drops Unicode punctuation characters except - (U+002D) and _ (U+005F).

ext is given to Inline.to_plain_text.