Skip to content
react-native-notion-markdown

References / react-native-notion-markdown / document

document

Public API declarations exported by react-native-notion-markdown/document.

./documentBrowse source

Classes

class NotionConversionError

An SDK conversion failure that retains every diagnostic.

constructor

constructor
constructor constructor(diagnostics: unknown): NotionConversionError

cause

property
property cause

diagnostics

property
property diagnostics

message

property
property message

name

property
property name

stack

property
property stack
property stackTraceLimit

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

method captureStackTrace(targetObject: object, constructorOpt?: Function): void

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
method prepareStackTrace(err: Error, stackTraces: unknown): any

Functions

function appendChildBlock(store: NotionEditorStore, parentBlockId: string, type: NotionMarkdownBlockType): string

Append a new, empty block of the given type as the last child of a block.

function appendNotionChild(document: NotionDocument, parentBlockId: string, newBlock: NotionBlock): NotionDocument

Append a new block as the last child of an existing block.

function applyFieldEdit(store: NotionEditorStore, event: NotionFieldEditEvent): void

Write a native field's current (text, marks) back into the document as real rich text, and sync the store's selection to the field's reported caret. This is the point where a NotionFieldEditEvent from NotionTextField becomes a real document transaction.

function applyMarkdownShortcut(store: NotionEditorStore, blockId: string, match: NotionMarkdownShortcutMatch): void

Apply a matched Markdown shortcut: convert the block and replace its text with the remainder typed after the trigger, selecting the end of that remainder.

function createNotionCommands(store: NotionEditorStore): NotionCommands

Bind the full command surface to one document store.

function createNotionEditor(input: NotionDocumentInput, options: CreateNotionEditorOptions): NotionEditorStore

Create the pure TypeScript editor engine.

function decodeNotionBlockClipboard(json: string): unknown

Decode a structured block clipboard fragment, rejecting anything malformed or oversized.

function decodeNotionFieldClipboard(json: string): NotionRichText

Decode a structured field clipboard fragment, rejecting anything malformed or oversized.

deleteBlock

function
function deleteBlock(store: NotionEditorStore, blockId: string): void

Delete a block by its stable editor identity.

function duplicateBlock(store: NotionEditorStore, blockId: string): string

Duplicate a block (and its descendants) as the next sibling, with freshly generated editor ids throughout so the copy is independently editable.

function encodeNotionBlockClipboard(blocks: unknown): string

Encode whole blocks for the structured clipboard, used when a selection spans multiple fields.

function encodeNotionFieldClipboard(richText: NotionRichText): string

Encode a single field's selected rich text for the structured clipboard.

function fieldMarksToRichText(text: string, marks: unknown): NotionRichText

Reconstruct rich text from a field's current (text, marks) state. Untouched atoms splice their original item back in unchanged; overlapping range marks are flattened into runs so each emitted item carries one consistent annotation set.

function findNotionBlockPath(document: NotionDocument, blockId: string): NotionBlockPath

Find the path to a block by its stable editor identity, searching depth-first.

function fromNotionBlocks(blocks: unknown, options: FromNotionBlocksOptions): FromNotionBlocksResult

Import SDK response/request-shaped blocks without making network requests.

function generateNotionBlockId(): string

A fresh, unique editor id for a block created at runtime by a command, distinct from the parser's and adapters' path-derived default ids.

function getNotionBlock(document: NotionDocument, blockId: string): NotionBlock

Find a block by its stable editor identity.

function getNotionBlockAtPath(document: NotionDocument, path: NotionBlockPath): NotionBlock

Read the block at a known path, without searching.

function getNotionBlockCaption(block: NotionBlock): NotionRichText

Read a block's own caption payload, for block types that have one.

function getNotionBlockCell(block: NotionBlock, index: number): NotionRichText

Read one cell's rich text from a table_row block.

function getNotionBlockRichText(block: NotionBlock): NotionRichText

Read a block's own rich_text payload, for block types that have one.

function getNotionEditableFields(document: NotionDocument): unknown

List editable fields in document order, including nested and table-cell fields.

function getNotionEditorBlockId(block: NotionBlock): string

Return the stable editor identity for a block.

function handleFieldBoundary(store: NotionEditorStore, event: NotionFieldBoundaryEvent): void

Dispatch a structural boundary event a native field could not resolve on its own.

indent

function
function indent(store: NotionEditorStore, blockId: string): void

Nest a block as the last child of its immediately preceding sibling.

function indentNotionBlock(document: NotionDocument, blockId: string): NotionDocument

Nest a block as the last child of its immediately preceding sibling. A no-op when the block is already first in its container, since there is no preceding sibling to become its parent.

function insertBlockOfType(store: NotionEditorStore, afterBlockId: string, type: NotionMarkdownBlockType): string

Insert a new, empty block of the given type immediately after another block, and select its start.

function insertMention(store: NotionEditorStore, point: NotionSelectionPoint, candidate: NotionMentionCandidate, selectionEnd: number): void

Insert a resolved mention at a field position, replacing any selected text there. The command layer's entry point for a host's "@" mention search -- resolving candidates from a query is the host's own responsibility, this only splices the chosen one in.

function insertNotionBlockRelative(document: NotionDocument, anchorBlockId: string, newBlock: NotionBlock, position: unknown): NotionDocument

Insert a new block immediately before or after an existing one, as its sibling.

function insertTextBlockAfter(store: NotionEditorStore, blockId: string): string

Insert a new text block immediately after a block and select its start.

function isNotionListBlockType(type: NotionMarkdownBlockType): boolean

Whether a block type is a list item that continues the list on Enter and outdents on Backspace-at-start, rather than merging with the previous block.

function isNotionTextBearingBlockType(type: NotionMarkdownBlockType): boolean

Whether a block type has its own editable rich_text field, as opposed to carrying text only through children or table cells.

function makeNotionBlock(type: NotionMarkdownBlockType, id: string): NotionBlock

Build a new, empty block of the given type with a fresh editor id.

function mapNotionSelectionPoint(document: NotionDocument, selectionPoint: NotionSelectionPoint): NotionSelectionPoint

Map an existing endpoint to a replacement document, clamping when its field disappeared.

function matchNotionMarkdownShortcut(plainText: string): NotionMarkdownShortcutMatch

Test a field's current plain text against the Markdown shortcut patterns, longest trigger first (headings before a bare "#", for example) so the most specific match wins.

function mergeFieldMarks(first: FieldMarks, second: FieldMarks): FieldMarks

Concatenate two field states, shifting the second's marks past the first's text. The inverse of splitFieldMarks for a split made at first.text.length.

moveBlock

function
function moveBlock(store: NotionEditorStore, blockId: string, direction: unknown): void

Swap a block with its previous or next sibling.

function moveNotionBlock(document: NotionDocument, blockId: string, direction: unknown): NotionDocument

Swap a block with its previous or next sibling. A no-op at either end of the sibling list.

function notionSelectionPointAt(document: NotionDocument, position: number): NotionSelectionPoint

Map a flattened UTF-16 position to a field endpoint. Separators occupy one unit.

function notionSelectionPositionOf(document: NotionDocument, selectionPoint: NotionSelectionPoint): number

Map a field endpoint to its flattened UTF-16 position.

outdent

function
function outdent(store: NotionEditorStore, blockId: string): void

Un-nest a block to become the next sibling of its own parent.

function outdentNotionBlock(document: NotionDocument, blockId: string): NotionDocument

Un-nest a block to become the next sibling of its own parent. A no-op for a top-level block, since it has no parent to become a sibling of.

function parseNotionMarkdown(markdownText: string, options: ParseNotionMarkdownOptions): ParseNotionMarkdownResult

Parse enhanced Markdown into the versioned Notion document model.

function removeNotionBlock(document: NotionDocument, blockId: string): NotionDocument

Remove one block by its stable editor identity.

function richTextToFieldMarks(richText: NotionRichText): FieldMarks

Flatten a block's rich text into plain text plus formatting/atom marks for a native field. Each atomic element occupies exactly one NOTION_ATOM_PLACEHOLDER character.

function searchInsertableBlocks(query: string): unknown

Filter the insertable-block catalog for a "/" insert search query. An empty query returns the full catalog.

function serializeNotionMarkdown(document: NotionDocument): string

Serialize a document into canonical enhanced Markdown.

setColor

function
function setColor(store: NotionEditorStore, color: NotionMarkdownColor): void

Set or clear the text color/background over the current selection, across every field it touches.

function setFieldValueMark(marks: unknown, kind: unknown, start: number, end: number, value: string): unknown

Set or clear a value-carrying mark (color or link) over [start, end). Existing marks of the same kind are clipped out of the range first; passing undefined simply clears it.

function setNotionBlockCaption(block: NotionBlock, richText: NotionRichText): NotionBlock

Return a copy of a block with its caption payload replaced, for block types that have one.

function setNotionBlockCell(block: NotionBlock, index: number, richText: NotionRichText): NotionBlock

Return a copy of a table_row block with one cell's rich text replaced.

function setNotionBlockRichText(block: NotionBlock, richText: NotionRichText): NotionBlock

Return a copy of a block with its rich_text payload replaced, for block types that have one.

function splitFieldMarks(text: string, marks: unknown, offset: number): unknown

Split (text, marks) at a UTF-16 offset into two independent field states. A range mark straddling the offset is clipped into two pieces; an atom cannot straddle a split point since it occupies exactly one unit, so a split always lands on an atom's own boundary.

function toggleFieldRangeMark(marks: unknown, kind: NotionFieldRangeMarkKind, start: number, end: number): unknown

Toggle a boolean formatting mark over [start, end). When the range is already fully covered by that mark, it is removed from the range; otherwise it is added, merging with any adjacent or overlapping run of the same kind.

toggleMark

function
function toggleMark(store: NotionEditorStore, kind: NotionFieldRangeMarkKind): void

Toggle a boolean formatting mark over the current selection, across every field it touches. A no-op when the selection is collapsed or absent -- formatting a caret with no range applies to the host's own pending-mark state, not the document, and belongs to the UI layer.

function toNotionBlocks(document: NotionDocument, options: ToNotionBlocksOptions): ToNotionBlocksResult

Export SDK request payloads and retain explicit conversion diagnostics.

turnInto

function
function turnInto(store: NotionEditorStore, blockId: string, type: NotionMarkdownBlockType): void

Convert a block to a different type, carrying its rich_text forward.

function turnNotionBlockInto(block: NotionBlock, type: NotionMarkdownBlockType): NotionBlock

Convert a block to a different type, carrying its rich_text forward and discarding the old type's payload. Children, id, and metadata are preserved untouched.

function updateNotionBlock(document: NotionDocument, blockId: string, updater: __type): NotionDocument

Replace or remove one block by its stable editor identity. Returning undefined from updater removes the block; any other document with no matching block is returned unchanged.

Interfaces

interface CreateNotionEditorOptions

Options for creating a document editor store.

historyLimit

property
property historyLimit

FieldMarks

interface
interface FieldMarks

Text and inline marks used to edit one document field.

marks

property
property marks

text

property
property text
interface FromNotionBlocksOptions

Options for importing blocks from the Notion SDK shape.

idFactory

property
property idFactory
interface FromNotionBlocksResult

Document and diagnostics returned by a Notion block import.

diagnostics

property
property diagnostics

document

property
property document
interface NotionAutoScrollEvent

A request from the selection overlay to scroll the host's list while dragging a handle.

direction

property
property direction

proximity

property
property proximity
interface NotionBlockClipboardFragment

A structured clipboard fragment carrying whole blocks, for cross-field selections.

blocks

property
property blocks

kind

property
property kind

version

property
property version
interface NotionCommands

The full command surface, bound to one document store.

method appendChildBlock(parentBlockId: string, type: NotionMarkdownBlockType): string
method applyFieldEdit(event: NotionFieldEditEvent): void
method applyMarkdownShortcut(blockId: string, match: NotionMarkdownShortcutMatch): void
method deleteBlock(blockId: string): void
method duplicateBlock(blockId: string): string
method handleFieldBoundary(event: NotionFieldBoundaryEvent): void

indent

method
method indent(blockId: string): void
method insertBlockOfType(afterBlockId: string, type: NotionMarkdownBlockType): string
method insertMention(point: NotionSelectionPoint, candidate: NotionMentionCandidate, selectionEnd?: number): void
method insertTextBlockAfter(blockId: string): string

moveBlock

method
method moveBlock(blockId: string, direction: unknown): void

outdent

method
method outdent(blockId: string): void

redo

method
method redo(): boolean

setColor

method
method setColor(color: NotionMarkdownColor): void
method setSelection(selection: NotionSelection): void
method toggleMark(kind: NotionFieldRangeMarkKind): void

turnInto

method
method turnInto(blockId: string, type: NotionMarkdownBlockType): void

undo

method
method undo(): boolean
interface NotionDiagnostic

A parser or conversion diagnostic.

code

property
property code

details

property
property details

message

property
property message

severity

property
property severity

source

property
property source
interface NotionDocument

A versioned, recursive document tree.

blocks

property
property blocks

version

property
property version
interface NotionEditorState

The current document, selection, revision, and history availability.

canRedo

property
property canRedo

canUndo

property
property canUndo

document

property
property document

revision

property
property revision

selection

property
property selection
interface NotionEditorStore

State and transaction operations exposed by the document editor store.

method getDocument(): NotionDocument
method getMarkdown(): string
method getSelection(): NotionSelection

getState

method
method getState(): NotionEditorState

redo

method
method redo(): boolean
method replaceDocument(input: NotionDocumentInput, origin?: string): void
method setSelection(selection: NotionSelection): void

subscribe

method
method subscribe(listener: NotionEditorListener): __type

transact

method
method transact(update: __type, origin?: string): void

undo

method
method undo(): boolean
interface NotionFieldBoundaryEvent

A boundary event reported by a native field.

blockId

property
property blockId

epoch

property
property epoch

field

property
property field

hasSelection

property
property hasSelection

index

property
property index

kind

property
property kind

offset

property
property offset

UTF-16 offset within the selected field.

interface NotionFieldClipboardFragment

A structured clipboard fragment carrying one field's rich text selection.

kind

property
property kind

marks

property
property marks

text

property
property text

version

property
property version
interface NotionFieldCommand

A uniquely identified command sent to one native field.

action

property
property action

epoch

property
property epoch

id

property
property id

selection

property
property selection
interface NotionFieldDescriptor

The native description of one editable field, supplied by the host document.

blockId

property
property blockId

epoch

property
property epoch

field

property
property field

index

property
property index

marks

property
property marks

order

property
property order

placeholder

property
property placeholder

revision

property
property revision

sessionId

property
property sessionId

text

property
property text
interface NotionFieldEditEvent

A revisioned edit reported by a native field.

blockId

property
property blockId

composingEnd

property
property composingEnd
property composingStart

epoch

property
property epoch

field

property
property field

index

property
property index

marks

property
property marks

revision

property
property revision

selectionEnd

property
property selectionEnd
property selectionStart

source

property
property source

text

property
property text
interface NotionFieldFocusEvent

A focus/blur signal reported by a native field.

blockId

property
property blockId

field

property
property field

index

property
property index
interface NotionFieldSelection

An explicit start/end range within one field.

end

property
property end

start

property
property start
interface NotionInlineAtomMark

One atomic inline element (mention, citation, custom emoji, or equation).

atomKind

property
property atomKind

end

property
property end

item

property
property item

kind

property
property kind

label

property
property label

start

property
property start
interface NotionInlineRangeMark

A non-atomic inline formatting range within a field's flattened text.

color

property
property color

end

property
property end

kind

property
property kind

start

property
property start

url

property
property url
interface NotionInsertableBlockOption

One entry in the Insert/Turn-into catalog: a block type a host UI can offer to create.

category

property
property category

keywords

property
property keywords

label

property
property label

type

property
property type
interface NotionMarkdownMetadata

Data retained for Markdown-only features and editor identity.

citationUrl

property
property citationUrl

color

property
property color

editorId

property
property editorId

Stable identity used by the editor, distinct from a remote Notion ID.

emojiName

property
property emojiName

icon

property
property icon

inline

property
property inline

mention

property
property mention

notionId

property
property notionId

A remote Notion ID supplied during import.

referenceUrl

property
property referenceUrl

source

property
property source

table

property
property table

toggle

property
property toggle

unresolved

property
property unresolved
interface NotionMarkdownParserRule

An optional structural parser extension evaluated before built-in block rules.

name

property
property name

parse

property
property parse

test

property
property test
interface NotionMarkdownShortcutMatch

A Markdown shortcut match: convert the block and keep the text typed after the trigger.

remainder

property
property remainder

type

property
property type
interface NotionMentionCandidate

A resolved mention candidate ready to insert, typically from a host's "@" search results.

id

property
property id

kind

property
property kind

label

property
property label

url

property
property url
interface NotionSelection

The anchor and focus points of a document selection.

anchor

property
property anchor

focus

property
property focus
interface NotionSelectionPoint

A UTF-16 selection point within a given editable field.

blockId

property
property blockId

field

property
property field

index

property
property index

offset

property
property offset

UTF-16 offset within the selected field.

interface NotionSourceLocation

A source location in the original Markdown string. Lines and columns are one-based.

column

property
property column

line

property
property line

offset

property
property offset
interface NotionTransaction

A document change with its corresponding source and revision.

after

property
property after

before

property
property before

origin

property
property origin

revision

property
property revision
interface ParseNotionMarkdownOptions

Options for parsing Notion-enhanced Markdown.

idFactory

property
property idFactory

rules

property
property rules
interface ParseNotionMarkdownResult

Document and diagnostics returned by the Markdown parser.

diagnostics

property
property diagnostics

document

property
property document
interface ToNotionBlocksOptions

Options for exporting document blocks to the Notion SDK shape.

strict

property
property strict

When true, throw NotionConversionError if any block cannot be represented.

interface ToNotionBlocksResult

SDK blocks and diagnostics returned by a Notion block export.

blocks

property
property blocks

diagnostics

property
property diagnostics

Types

NotionBlock

type alias
type NotionBlock = unknown

A recursive document block with a given Notion block type and additive metadata.

NotionBlockPath

type alias
type NotionBlockPath = ReadonlyArray

A sequence of child-array indices from the document root down to one block.

type NotionCrossFieldSelectionEvent = NotionSelection

A cross-field selection reported by the selection overlay. Structurally a NotionSelection.

type NotionDocumentInput = unknown

Input accepted by the document parser and editor store.

type NotionEditableField = unknown

A field that can be edited on a given document block.

type NotionEditorListener = __type

A listener called with the current editor state and corresponding transaction.

type NotionFieldAction = unknown

Actions understood by a native editable field.

type NotionFieldBoundaryKind = unknown

A structural signal a field cannot resolve locally; the command layer decides the outcome.

NotionFieldKind

type alias
type NotionFieldKind = unknown

A kind of editable text field within a block.

type NotionFieldRangeMarkKind = unknown

Boolean formatting marks that toggle on/off over a range, as opposed to carrying a value.

type NotionInlineMark = unknown

A formatting or atomic range over a field's flattened text.

type NotionMarkdownBlockType = unknown

Block names supported by the enhanced Markdown format.

type NotionMarkdownColor = unknown

Colors accepted by the enhanced Markdown format.

NotionRichText

type alias
type NotionRichText = unknown

Rich text accepted by the document model.

type NotionRichTextItem = unknown

A rich-text item with an additive, namespaced metadata field.

type NotionTransactionOrigin = unknown

The source label associated with a document transaction.

SdkBlockPayload

type alias
type SdkBlockPayload = unknown

The SDK payload for one block type, excluding the envelope and children.

Variables

const NOTION_ATOM_PLACEHOLDER: const
const NOTION_MARKDOWN_METADATA: const
const notionInsertableBlockCatalog: ReadonlyArray