import{Ast}from"@markdoc/markdoc";import{isString}from"@redocly/theme";export function saveTextBeforeHeading(r){if(!r)return"";if(!isString(r))return(null==r?void 0:r.result)?{result:modifyNodeByHeading(Ast.fromJSON(JSON.stringify(r.result)))||"",raw:saveTextBeforeHeading(r.raw)}:r;const e=new RegExp("^#{1,6}?\\s+","m"),i=r.search(e);return i>-1?r.substring(0,i):r}function modifyNodeByHeading(r){if(Array.isArray(r)){const e=r.findIndex((r=>"heading"===r.type));return-1===e?r:r.slice(0,e)}if(!r.children||!Array.isArray(r.children))return;const e=r.children.findIndex((r=>"heading"===r.type));return-1===e||(r.children=r.children.slice(0,e)),r}
//# sourceMappingURL=saveTextBeforeHeading.js.map