//#region ../@intlayer/cli/dist/esm/utils/fixChunkStartEndChars.mjs
const CHAR_TO_CHECK_FORMATTING = [
	"```",
	"\n\n",
	"\n",
	"---",
	"{{",
	"}}"
];
const escapeForRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\n/g, "\\n");
const FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join("|")})+`;
const LEADING_FORMATTING_REGEX = /* @__PURE__ */ new RegExp(`^${FORMATTING_REGEX_SOURCE}`);
const TRAILING_FORMATTING_REGEX = /* @__PURE__ */ new RegExp(`${FORMATTING_REGEX_SOURCE}$`);
const fixChunkStartEndChars = (reviewedChunkResult, baseChunkContext) => {
	let result = reviewedChunkResult;
	const baseLeading = baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
	const baseTrailing = baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
	const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
	const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
	if (baseLeading !== resultLeading) result = baseLeading + result.slice(resultLeading.length);
	if (baseTrailing !== resultTrailing) result = result.slice(0, result.length - resultTrailing.length) + baseTrailing;
	return result;
};

//#endregion
export { fixChunkStartEndChars };
//# sourceMappingURL=fixChunkStartEndChars.mjs.map