github ↗
docs menu

Module Quill_markdown.Edit

Typora-style cursor-aware markdown block segmentation.

Parses a markdown source string into top-level blocks with byte ranges. Consumers use this to render inactive blocks formatted and the active block (containing the cursor) as raw text for editing.

Types

#type span = {
  1. #first : int;
    (*

    Inclusive start byte offset in source (zero-based).

    *)
  2. #last : int;
    (*

    Inclusive end byte offset in source (zero-based).

    *)
}

A byte range within the source string.

#type block_kind =
  1. #| Paragraph
  2. #| Heading of int
  3. #| Block_quote
  4. #| List
  5. #| Thematic_break
  6. #| Table
  7. #| Blank
    (*

    The kind of a top-level markdown block.

    *)
#type block = {
  1. #span : span;
  2. #kind : block_kind;
}

A top-level block extracted from a markdown source string.

#type t

A parsed markdown source split into blocks with byte ranges.

Parsing

#val parse : string -> t

parse source parses source into blocks with byte ranges.

#val source : t -> string

source t is the original source string.

#val blocks : t -> block list

blocks t is the list of top-level blocks in document order.

Queries

#val active_block : t -> cursor:int -> block option

active_block t ~cursor is the block containing byte offset cursor, or None if cursor is outside all blocks.

#val block_source : t -> block -> string

block_source t block extracts the raw source substring for block.

Rendering

#val block_to_html : t -> block -> string

block_to_html t block renders block to an HTML fragment.

#val to_html : string -> string

to_html source renders CommonMark source to an HTML fragment.