References / react-native-notion-markdown / document
document
Public API declarations exported by react-native-notion-markdown/document.
./documentBrowse sourceClasses
class NotionConversionError An SDK conversion failure that retains every diagnostic.
constructor
constructorconstructor constructor(diagnostics: unknown): NotionConversionErrorcause
propertyproperty causediagnostics
propertyproperty diagnosticsmessage
propertyproperty messagename
propertyproperty namestack
propertyproperty stackstackTraceLimit
propertyproperty stackTraceLimitThe 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.
captureStackTrace
methodmethod captureStackTrace(targetObject: object, constructorOpt?: Function): voidCreates 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();
prepareStackTrace
methodmethod prepareStackTrace(err: Error, stackTraces: unknown): anyFunctions
appendChildBlock
functionfunction appendChildBlock(store: NotionEditorStore, parentBlockId: string, type: NotionMarkdownBlockType): string Append a new, empty block of the given type as the last child of a block.
appendNotionChild
functionfunction appendNotionChild(document: NotionDocument, parentBlockId: string, newBlock: NotionBlock): NotionDocument Append a new block as the last child of an existing block.
applyFieldEdit
functionfunction 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.
applyMarkdownShortcut
functionfunction 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.
createNotionCommands
functionfunction createNotionCommands(store: NotionEditorStore): NotionCommands Bind the full command surface to one document store.
createNotionEditor
functionfunction createNotionEditor(input: NotionDocumentInput, options: CreateNotionEditorOptions): NotionEditorStore Create the pure TypeScript editor engine.
decodeNotionBlockClipboard
functionfunction decodeNotionBlockClipboard(json: string): unknown Decode a structured block clipboard fragment, rejecting anything malformed or oversized.
decodeNotionFieldClipboard
functionfunction decodeNotionFieldClipboard(json: string): NotionRichText Decode a structured field clipboard fragment, rejecting anything malformed or oversized.
deleteBlock
functionfunction deleteBlock(store: NotionEditorStore, blockId: string): void Delete a block by its stable editor identity.
duplicateBlock
functionfunction 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.
encodeNotionBlockClipboard
functionfunction encodeNotionBlockClipboard(blocks: unknown): string Encode whole blocks for the structured clipboard, used when a selection spans multiple fields.
encodeNotionFieldClipboard
functionfunction encodeNotionFieldClipboard(richText: NotionRichText): string Encode a single field's selected rich text for the structured clipboard.
fieldMarksToRichText
functionfunction 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.
findNotionBlockPath
functionfunction findNotionBlockPath(document: NotionDocument, blockId: string): NotionBlockPath Find the path to a block by its stable editor identity, searching depth-first.
fromNotionBlocks
functionfunction fromNotionBlocks(blocks: unknown, options: FromNotionBlocksOptions): FromNotionBlocksResult Import SDK response/request-shaped blocks without making network requests.
generateNotionBlockId
functionfunction 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.
getNotionBlock
functionfunction getNotionBlock(document: NotionDocument, blockId: string): NotionBlock Find a block by its stable editor identity.
getNotionBlockAtPath
functionfunction getNotionBlockAtPath(document: NotionDocument, path: NotionBlockPath): NotionBlock Read the block at a known path, without searching.
getNotionBlockCaption
functionfunction getNotionBlockCaption(block: NotionBlock): NotionRichText Read a block's own caption payload, for block types that have one.
getNotionBlockCell
functionfunction getNotionBlockCell(block: NotionBlock, index: number): NotionRichText Read one cell's rich text from a table_row block.
getNotionBlockRichText
functionfunction getNotionBlockRichText(block: NotionBlock): NotionRichText Read a block's own rich_text payload, for block types that have one.
getNotionEditableFields
functionfunction getNotionEditableFields(document: NotionDocument): unknown List editable fields in document order, including nested and table-cell fields.
getNotionEditorBlockId
functionfunction getNotionEditorBlockId(block: NotionBlock): string Return the stable editor identity for a block.
handleFieldBoundary
functionfunction handleFieldBoundary(store: NotionEditorStore, event: NotionFieldBoundaryEvent): void Dispatch a structural boundary event a native field could not resolve on its own.
indent
functionfunction indent(store: NotionEditorStore, blockId: string): void Nest a block as the last child of its immediately preceding sibling.
indentNotionBlock
functionfunction 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.
insertBlockOfType
functionfunction 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.
insertMention
functionfunction 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.
insertNotionBlockRelative
functionfunction insertNotionBlockRelative(document: NotionDocument, anchorBlockId: string, newBlock: NotionBlock, position: unknown): NotionDocument Insert a new block immediately before or after an existing one, as its sibling.
insertTextBlockAfter
functionfunction insertTextBlockAfter(store: NotionEditorStore, blockId: string): string Insert a new text block immediately after a block and select its start.
isNotionListBlockType
functionfunction 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.
isNotionTextBearingBlockType
functionfunction 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.
makeNotionBlock
functionfunction makeNotionBlock(type: NotionMarkdownBlockType, id: string): NotionBlock Build a new, empty block of the given type with a fresh editor id.
mapNotionSelectionPoint
functionfunction mapNotionSelectionPoint(document: NotionDocument, selectionPoint: NotionSelectionPoint): NotionSelectionPoint Map an existing endpoint to a replacement document, clamping when its field disappeared.
matchNotionMarkdownShortcut
functionfunction 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.
mergeFieldMarks
functionfunction 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
functionfunction moveBlock(store: NotionEditorStore, blockId: string, direction: unknown): void Swap a block with its previous or next sibling.
moveNotionBlock
functionfunction 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.
notionSelectionPointAt
functionfunction notionSelectionPointAt(document: NotionDocument, position: number): NotionSelectionPoint Map a flattened UTF-16 position to a field endpoint. Separators occupy one unit.
notionSelectionPositionOf
functionfunction notionSelectionPositionOf(document: NotionDocument, selectionPoint: NotionSelectionPoint): number Map a field endpoint to its flattened UTF-16 position.
outdent
functionfunction outdent(store: NotionEditorStore, blockId: string): void Un-nest a block to become the next sibling of its own parent.
outdentNotionBlock
functionfunction 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.
parseNotionMarkdown
functionfunction parseNotionMarkdown(markdownText: string, options: ParseNotionMarkdownOptions): ParseNotionMarkdownResult Parse enhanced Markdown into the versioned Notion document model.
removeNotionBlock
functionfunction removeNotionBlock(document: NotionDocument, blockId: string): NotionDocument Remove one block by its stable editor identity.
richTextToFieldMarks
functionfunction 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.
searchInsertableBlocks
functionfunction searchInsertableBlocks(query: string): unknown Filter the insertable-block catalog for a "/" insert search query. An empty query returns the full catalog.
serializeNotionMarkdown
functionfunction serializeNotionMarkdown(document: NotionDocument): string Serialize a document into canonical enhanced Markdown.
setColor
functionfunction setColor(store: NotionEditorStore, color: NotionMarkdownColor): void Set or clear the text color/background over the current selection, across every field it touches.
setFieldValueMark
functionfunction 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.
setLink
functionfunction setLink(store: NotionEditorStore, url: string): void Set or clear a link over the current selection, across every field it touches.
setNotionBlockCaption
functionfunction setNotionBlockCaption(block: NotionBlock, richText: NotionRichText): NotionBlock Return a copy of a block with its caption payload replaced, for block types that have one.
setNotionBlockCell
functionfunction setNotionBlockCell(block: NotionBlock, index: number, richText: NotionRichText): NotionBlock Return a copy of a table_row block with one cell's rich text replaced.
setNotionBlockRichText
functionfunction setNotionBlockRichText(block: NotionBlock, richText: NotionRichText): NotionBlock Return a copy of a block with its rich_text payload replaced, for block types that have one.
splitFieldMarks
functionfunction 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.
toggleFieldRangeMark
functionfunction 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
functionfunction 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.
toNotionBlocks
functionfunction toNotionBlocks(document: NotionDocument, options: ToNotionBlocksOptions): ToNotionBlocksResult Export SDK request payloads and retain explicit conversion diagnostics.
turnInto
functionfunction turnInto(store: NotionEditorStore, blockId: string, type: NotionMarkdownBlockType): void Convert a block to a different type, carrying its rich_text forward.
turnNotionBlockInto
functionfunction 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.
updateNotionBlock
functionfunction 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
CreateNotionEditorOptions
interfaceinterface CreateNotionEditorOptions Options for creating a document editor store.
historyLimit
propertyproperty historyLimitFieldMarks
interfaceinterface FieldMarks Text and inline marks used to edit one document field.
FromNotionBlocksOptions
interfaceinterface FromNotionBlocksOptions Options for importing blocks from the Notion SDK shape.
idFactory
propertyproperty idFactoryFromNotionBlocksResult
interfaceinterface FromNotionBlocksResult Document and diagnostics returned by a Notion block import.
diagnostics
propertyproperty diagnosticsdocument
propertyproperty documentNotionAutoScrollEvent
interfaceinterface NotionAutoScrollEvent A request from the selection overlay to scroll the host's list while dragging a handle.
NotionBlockClipboardFragment
interfaceinterface NotionBlockClipboardFragment A structured clipboard fragment carrying whole blocks, for cross-field selections.
NotionCommands
interfaceinterface NotionCommands The full command surface, bound to one document store.
appendChildBlock
methodmethod appendChildBlock(parentBlockId: string, type: NotionMarkdownBlockType): stringapplyFieldEdit
methodmethod applyFieldEdit(event: NotionFieldEditEvent): voidapplyMarkdownShortcut
methodmethod applyMarkdownShortcut(blockId: string, match: NotionMarkdownShortcutMatch): voiddeleteBlock
methodmethod deleteBlock(blockId: string): voidduplicateBlock
methodmethod duplicateBlock(blockId: string): stringhandleFieldBoundary
methodmethod handleFieldBoundary(event: NotionFieldBoundaryEvent): voidindent
methodmethod indent(blockId: string): voidinsertBlockOfType
methodmethod insertBlockOfType(afterBlockId: string, type: NotionMarkdownBlockType): stringinsertMention
methodmethod insertMention(point: NotionSelectionPoint, candidate: NotionMentionCandidate, selectionEnd?: number): voidinsertTextBlockAfter
methodmethod insertTextBlockAfter(blockId: string): stringmoveBlock
methodmethod moveBlock(blockId: string, direction: unknown): voidoutdent
methodmethod outdent(blockId: string): voidredo
methodmethod redo(): booleansetColor
methodmethod setColor(color: NotionMarkdownColor): voidsetLink
methodmethod setLink(url: string): voidsetSelection
methodmethod setSelection(selection: NotionSelection): voidtoggleMark
methodmethod toggleMark(kind: NotionFieldRangeMarkKind): voidturnInto
methodmethod turnInto(blockId: string, type: NotionMarkdownBlockType): voidundo
methodmethod undo(): booleanNotionDiagnostic
interfaceinterface NotionDiagnostic A parser or conversion diagnostic.
NotionDocument
interfaceinterface NotionDocument A versioned, recursive document tree.
NotionEditorState
interfaceinterface NotionEditorState The current document, selection, revision, and history availability.
NotionEditorStore
interfaceinterface NotionEditorStore State and transaction operations exposed by the document editor store.
getDocument
methodmethod getDocument(): NotionDocumentgetMarkdown
methodmethod getMarkdown(): stringgetSelection
methodmethod getSelection(): NotionSelectiongetState
methodmethod getState(): NotionEditorStateredo
methodmethod redo(): booleanreplaceDocument
methodmethod replaceDocument(input: NotionDocumentInput, origin?: string): voidsetSelection
methodmethod setSelection(selection: NotionSelection): voidsubscribe
methodmethod subscribe(listener: NotionEditorListener): __typetransact
methodmethod transact(update: __type, origin?: string): voidundo
methodmethod undo(): booleanNotionFieldBoundaryEvent
interfaceinterface NotionFieldBoundaryEvent A boundary event reported by a native field.
NotionFieldClipboardFragment
interfaceinterface NotionFieldClipboardFragment A structured clipboard fragment carrying one field's rich text selection.
NotionFieldCommand
interfaceinterface NotionFieldCommand A uniquely identified command sent to one native field.
NotionFieldDescriptor
interfaceinterface NotionFieldDescriptor The native description of one editable field, supplied by the host document.
NotionFieldEditEvent
interfaceinterface NotionFieldEditEvent A revisioned edit reported by a native field.
blockId
propertyproperty blockIdcomposingEnd
propertyproperty composingEndcomposingStart
propertyproperty composingStartepoch
propertyproperty epochfield
propertyproperty fieldindex
propertyproperty indexmarks
propertyproperty marksrevision
propertyproperty revisionselectionEnd
propertyproperty selectionEndselectionStart
propertyproperty selectionStartsource
propertyproperty sourcetext
propertyproperty textNotionFieldFocusEvent
interfaceinterface NotionFieldFocusEvent A focus/blur signal reported by a native field.
NotionFieldSelection
interfaceinterface NotionFieldSelection An explicit start/end range within one field.
NotionInlineAtomMark
interfaceinterface NotionInlineAtomMark One atomic inline element (mention, citation, custom emoji, or equation).
NotionInlineRangeMark
interfaceinterface NotionInlineRangeMark A non-atomic inline formatting range within a field's flattened text.
NotionInsertableBlockOption
interfaceinterface NotionInsertableBlockOption One entry in the Insert/Turn-into catalog: a block type a host UI can offer to create.
NotionMarkdownMetadata
interfaceinterface NotionMarkdownMetadata Data retained for Markdown-only features and editor identity.
citationUrl
propertyproperty citationUrlcolor
propertyproperty coloreditorId
propertyproperty editorIdStable identity used by the editor, distinct from a remote Notion ID.
emojiName
propertyproperty emojiNameicon
propertyproperty iconinline
propertyproperty inlinemention
propertyproperty mentionreferenceUrl
propertyproperty referenceUrlsource
propertyproperty sourcetable
propertyproperty tabletoggle
propertyproperty toggleunresolved
propertyproperty unresolvedNotionMarkdownParserRule
interfaceinterface NotionMarkdownParserRule An optional structural parser extension evaluated before built-in block rules.
NotionMarkdownShortcutMatch
interfaceinterface NotionMarkdownShortcutMatch A Markdown shortcut match: convert the block and keep the text typed after the trigger.
NotionMentionCandidate
interfaceinterface NotionMentionCandidate A resolved mention candidate ready to insert, typically from a host's "@" search results.
NotionSelection
interfaceinterface NotionSelection The anchor and focus points of a document selection.
NotionSelectionPoint
interfaceinterface NotionSelectionPoint A UTF-16 selection point within a given editable field.
NotionSourceLocation
interfaceinterface NotionSourceLocation A source location in the original Markdown string. Lines and columns are one-based.
NotionTransaction
interfaceinterface NotionTransaction A document change with its corresponding source and revision.
ParseNotionMarkdownOptions
interfaceinterface ParseNotionMarkdownOptions Options for parsing Notion-enhanced Markdown.
ParseNotionMarkdownResult
interfaceinterface ParseNotionMarkdownResult Document and diagnostics returned by the Markdown parser.
diagnostics
propertyproperty diagnosticsdocument
propertyproperty documentToNotionBlocksOptions
interfaceinterface ToNotionBlocksOptions Options for exporting document blocks to the Notion SDK shape.
strict
propertyproperty strictWhen true, throw NotionConversionError if any block cannot be represented.
ToNotionBlocksResult
interfaceinterface ToNotionBlocksResult SDK blocks and diagnostics returned by a Notion block export.
blocks
propertyproperty blocksdiagnostics
propertyproperty diagnosticsTypes
NotionBlock
type aliastype NotionBlock = unknown A recursive document block with a given Notion block type and additive metadata.
NotionBlockPath
type aliastype NotionBlockPath = ReadonlyArray A sequence of child-array indices from the document root down to one block.
NotionCrossFieldSelectionEvent
type aliastype NotionCrossFieldSelectionEvent = NotionSelection A cross-field selection reported by the selection overlay. Structurally a NotionSelection.
NotionDocumentInput
type aliastype NotionDocumentInput = unknown Input accepted by the document parser and editor store.
NotionEditableField
type aliastype NotionEditableField = unknown A field that can be edited on a given document block.
NotionEditorListener
type aliastype NotionEditorListener = __type A listener called with the current editor state and corresponding transaction.
NotionFieldAction
type aliastype NotionFieldAction = unknown Actions understood by a native editable field.
NotionFieldBoundaryKind
type aliastype NotionFieldBoundaryKind = unknown A structural signal a field cannot resolve locally; the command layer decides the outcome.
NotionFieldKind
type aliastype NotionFieldKind = unknown A kind of editable text field within a block.
NotionFieldRangeMarkKind
type aliastype NotionFieldRangeMarkKind = unknown Boolean formatting marks that toggle on/off over a range, as opposed to carrying a value.
NotionInlineMark
type aliastype NotionInlineMark = unknown A formatting or atomic range over a field's flattened text.
NotionMarkdownBlockType
type aliastype NotionMarkdownBlockType = unknown Block names supported by the enhanced Markdown format.
NotionMarkdownColor
type aliastype NotionMarkdownColor = unknown Colors accepted by the enhanced Markdown format.
NotionRichText
type aliastype NotionRichText = unknown Rich text accepted by the document model.
NotionRichTextItem
type aliastype NotionRichTextItem = unknown A rich-text item with an additive, namespaced metadata field.
NotionTransactionOrigin
type aliastype NotionTransactionOrigin = unknown The source label associated with a document transaction.
SdkBlockPayload
type aliastype SdkBlockPayload = unknown The SDK payload for one block type, excluding the envelope and children.
Variables
NOTION_ATOM_PLACEHOLDER
variableconst NOTION_ATOM_PLACEHOLDER: const NOTION_MARKDOWN_METADATA
variableconst NOTION_MARKDOWN_METADATA: const notionInsertableBlockCatalog
variableconst notionInsertableBlockCatalog: ReadonlyArray