{
  "version": 3,
  "sources": ["../../../src/api/raw-handling/special-comment-converter.ts"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { remove, replace } from '@wordpress/dom';\n\n/**\n * Looks for `<!--nextpage-->` and `<!--more-->` comments and\n * replaces them with a custom element representing a future block.\n *\n * The custom element is a way to bypass the rest of the `raw-handling`\n * transforms, which would eliminate other kinds of node with which to carry\n * `<!--more-->`'s data: nodes with `data` attributes, empty paragraphs, etc.\n *\n * The custom element is then expected to be recognized by any registered\n * block's `raw` transform.\n *\n * @param node The node to be processed.\n * @param doc  The document of the node.\n */\nexport default function specialCommentConverter(\n\tnode: Node,\n\tdoc: Document\n): void {\n\tif ( node.nodeType !== node.COMMENT_NODE ) {\n\t\treturn;\n\t}\n\n\tif (\n\t\tnode.nodeValue !== 'nextpage' &&\n\t\tnode.nodeValue!.indexOf( 'more' ) !== 0\n\t) {\n\t\treturn;\n\t}\n\n\tconst block = createBlock( node, doc );\n\n\t// If our `<!--more-->` comment is in the middle of a paragraph, we should\n\t// split the paragraph in two and insert the more block in between. If it's\n\t// inside an empty paragraph, we should still move it out of the paragraph\n\t// and remove the paragraph. If there's no paragraph, fall back to simply\n\t// replacing the comment.\n\tif ( ! node.parentNode || node.parentNode.nodeName !== 'P' ) {\n\t\treplace( node as Element, block );\n\t} else {\n\t\tconst childNodes = Array.from( node.parentNode.childNodes );\n\t\tconst nodeIndex = childNodes.indexOf( node as ChildNode );\n\t\tconst wrapperNode = node.parentNode.parentNode || doc.body;\n\n\t\tconst paragraphBuilder = (\n\t\t\tacc: HTMLElement | null,\n\t\t\tchild: Node\n\t\t): HTMLElement => {\n\t\t\tif ( ! acc ) {\n\t\t\t\tacc = doc.createElement( 'p' );\n\t\t\t}\n\n\t\t\tacc.appendChild( child );\n\n\t\t\treturn acc;\n\t\t};\n\n\t\t// Split the original parent node and insert our more block\n\t\t[\n\t\t\tchildNodes.slice( 0, nodeIndex ).reduce( paragraphBuilder, null ),\n\t\t\tblock,\n\t\t\tchildNodes.slice( nodeIndex + 1 ).reduce( paragraphBuilder, null ),\n\t\t].forEach(\n\t\t\t( element ) =>\n\t\t\t\telement && wrapperNode.insertBefore( element, node.parentNode )\n\t\t);\n\n\t\t// Remove the old parent paragraph\n\t\tremove( node.parentNode );\n\t}\n}\n\nfunction createBlock( commentNode: Node, doc: Document ): HTMLElement {\n\tif ( commentNode.nodeValue === 'nextpage' ) {\n\t\treturn createNextpage( doc );\n\t}\n\n\t// Grab any custom text in the comment.\n\tconst customText = commentNode.nodeValue!.slice( 4 ).trim();\n\n\t/*\n\t * When a `<!--more-->` comment is found, we need to look for any\n\t * `<!--noteaser-->` sibling, but it may not be a direct sibling\n\t * (whitespace typically lies in between)\n\t */\n\tlet sibling: Node | null = commentNode;\n\tlet noTeaser = false;\n\twhile ( ( sibling = sibling.nextSibling ) ) {\n\t\tif (\n\t\t\tsibling.nodeType === sibling.COMMENT_NODE &&\n\t\t\tsibling.nodeValue === 'noteaser'\n\t\t) {\n\t\t\tnoTeaser = true;\n\t\t\tremove( sibling );\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn createMore( customText, noTeaser, doc );\n}\n\nfunction createMore(\n\tcustomText: string,\n\tnoTeaser: boolean,\n\tdoc: Document\n): HTMLElement {\n\tconst node = doc.createElement( 'wp-block' );\n\tnode.dataset.block = 'core/more';\n\tif ( customText ) {\n\t\tnode.dataset.customText = customText;\n\t}\n\tif ( noTeaser ) {\n\t\t// \"Boolean\" data attribute.\n\t\tnode.dataset.noTeaser = '';\n\t}\n\treturn node;\n}\n\nfunction createNextpage( doc: Document ): HTMLElement {\n\tconst node = doc.createElement( 'wp-block' );\n\tnode.dataset.block = 'core/nextpage';\n\n\treturn node;\n}\n"],
  "mappings": ";AAGA,SAAS,QAAQ,eAAe;AAgBjB,SAAR,wBACN,MACA,KACO;AACP,MAAK,KAAK,aAAa,KAAK,cAAe;AAC1C;AAAA,EACD;AAEA,MACC,KAAK,cAAc,cACnB,KAAK,UAAW,QAAS,MA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