/**
 * A Remark plugin to serialize nodes that represent Markdown
 * parse errors or other unrecognized document fragments that
 * arise during the mdast -> prosemirror parsing process.
 *
 * During parsing, the raw Markdown source of these regions
 * is preserved as part of the document in a special error block.
 * When serializing, this plugin copies the contents of these
 * error blocks verbatim to the output.
 */ import * as Uni from "unist" ; import { Context } from "mdast-util-to-markdown" ; import { Handle , Options as ToMarkdownOptions } from 'mdast-util-to-markdown' ; export function remarkErrorPlugin ( this , opts = { } ) { const data = this . data ( ) ; function add ( field , value ) { if ( data [ field ] ) data [ field ] . push ( value ) ; else data [ field ] = [ value ] ; } add ( 'toMarkdownExtensions' , errorToMarkdown ( ) ) ; } /**
 * Represents a parse error or otherwise unrecognized content
 * whose string value should be reproduced verbatim in the output.
 * No escaping is performed when serializing this node.
 */ export interface MdError extends Uni . Node { type : "error" ; value : string ; } export function errorToMarkdown ( ) { function handler ( node , _ , context ) { const exit = context . enter ( 'error' ) ; exit ( ) ; return node . value ; } return { unsafe : [ ] , handlers : { error : handler as unknown as Handle } } ; }