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