package quill

  1. Overview
  2. Docs

Module Quill_markdown.EditSource

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

Sourcetype 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.

Sourcetype 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.

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

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

Sourcetype t

A parsed markdown source split into blocks with byte ranges.

Parsing

Sourceval parse : string -> t

parse source parses source into blocks with byte ranges.

Sourceval source : t -> string

source t is the original source string.

Sourceval blocks : t -> block list

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

Queries

Sourceval 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.

Sourceval block_source : t -> block -> string

block_source t block extracts the raw source substring for block.

Rendering

Sourceval block_to_html : t -> block -> string

block_to_html t block renders block to an HTML fragment.

Sourceval to_html : string -> string

to_html source renders CommonMark source to an HTML fragment.