@mermaid-editor-sdk/headless


@mermaid-editor-sdk/headless / SourceDocument

Class: SourceDocument

Defined in: source/source-document.ts:91

Constructors

Constructor

new SourceDocument(source, diagramType): SourceDocument

Defined in: source/source-document.ts:103

Analyzes source regions for safe mutations of the specified diagram type.

Parameters

ParameterTypeDescription
sourcestringMermaid source to inspect.
diagramTypeDiagramTypeDiagram type used to classify source regions.

Returns

SourceDocument

Properties

diagramType

readonly diagramType: DiagramType

Defined in: source/source-document.ts:95

Diagram type used to classify source regions.


regions

readonly regions: readonly SourceRegion[]

Defined in: source/source-document.ts:97

Source spans, including statements, comments, metadata, and opaque text.


source

readonly source: string

Defined in: source/source-document.ts:93

Original Mermaid source.

Methods

findUniqueEditableStatement()

findUniqueEditableStatement(statement): SourceRegion

Defined in: source/source-document.ts:137

Finds an editable statement and requires exactly one match.

Parameters

ParameterTypeDescription
statementstringExact statement text to find.

Returns

SourceRegion


replaceStatement()

replaceStatement(start, end, replacement): string

Defined in: source/source-document.ts:116

Replaces one safe flowchart node statement at the given source offsets.

Parameters

ParameterTypeDescription
startnumberInclusive start offset of the statement.
endnumberExclusive end offset of the statement.
replacementstringReplacement statement text.

Returns

string


serializeMutation()

serializeMutation(candidate): string

Defined in: source/source-document.ts:148

Serializes a candidate mutation while preserving protected source regions.

Parameters

ParameterTypeDescription
candidatestringCandidate Mermaid source after a mutation.

Returns

string