"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveTextBeforeHeading=void 0;const markdoc_1=require("@markdoc/markdoc"),theme_1=require("@redocly/theme"),utils_1=require("../services/utils");function saveTextBeforeHeading(e){if(!(0,theme_1.isString)(e)&&(null==e?void 0:e.result)){const r=(0,utils_1.deepClone)(e),i=markdoc_1.Ast.fromJSON(JSON.stringify(null==r?void 0:r.result));if(Array.isArray(i))for(const e of i)modifyNodeByHeading(e);else modifyNodeByHeading(i);return r.result=JSON.stringify(i),r.raw=saveTextBeforeHeading(r.raw),r}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.children))return;const r=e.children.findIndex((e=>"heading"===e.type));return-1===r||(e.children=e.children.slice(0,r)),e}exports.saveTextBeforeHeading=saveTextBeforeHeading;
//# sourceMappingURL=saveTextBeforeHeading.js.map