Module Inline.Link

Links.

type inline := t
type reference_layout = [
  1. | `Collapsed
  2. | `Full
  3. | `Shortcut
]

The type for reference link layouts.

type reference = [
  1. | `Inline of Link_definition.t node
  2. | `Ref of reference_layout * Label.t * Label.t
    (*

    Reference links. First label is the label of the reference, second label is the label of the referenced definition.

    *)
]

The type for references.

type t

The type for links and images.

val make : inline -> reference -> t

make i ref is a link for text i and link reference ref.

If you plan to render to CommonMark and this is not an inline reference you should include a Block.Link_reference_definition (or Block.Ext_footnote_definition) for ref somewhere in the document, otherwise the reference will not parse back.

val text : t -> inline

text l is the text of the link.

val reference : t -> reference

reference l is the reference of the link.

val referenced_label : t -> Label.t option

referenced_label l is the label referenced by the label of l. This is the second label of `Ref _ or None on inline references.

val reference_definition : Label.defs -> t -> Label.def option

reference_definition defs l is the definition of l's reference. If l is an `Inline reference this returns its link definition wrapped in a Link_definition.Def. If l is `Ref this looks up the referenced_label in defs.

val is_unsafe : string -> bool

is_unsafe url is true if url is deemed unsafe. This is the case if url starts with a caseless match of javascript:, vbscript:, file: or data: except if data:image/{gif,png,jpeg,webp}. These rules were taken from cmark, the C reference implementation of CommonMark and are likely incomplete. If you are trying to prevent XSS you should post-process rendering outputs with a dedicated HTML sanitizer.