exportAsMarkdown

Serializes the document to markdown.

Safe to call from any thread. The whole document (text and rich spans) is read once, up front, as a single immutable snapshot, so a concurrent edit can neither interrupt the walk nor tear the output across two revisions: edits commit their text and their span re-anchoring together, so the snapshot is always a fully applied revision. It does not wait for the user to stop typing, though; an edit made after the snapshot is taken simply isn't in the result.