diff options
Diffstat (limited to 'packages/cli/src/ui/utils/markdownUtilities.ts')
| -rw-r--r-- | packages/cli/src/ui/utils/markdownUtilities.ts | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/packages/cli/src/ui/utils/markdownUtilities.ts b/packages/cli/src/ui/utils/markdownUtilities.ts index 4ddb2285..c328c12a 100644 --- a/packages/cli/src/ui/utils/markdownUtilities.ts +++ b/packages/cli/src/ui/utils/markdownUtilities.ts @@ -90,101 +90,6 @@ const findEnclosingCodeBlockStart = ( return -1; }; -export const findSafeSplitPoint = ( - content: string, - idealMaxLength: number = 500, -): number => { - if (content.length <= idealMaxLength) { - return content.length; - } - - const enclosingBlockStartForIdealMax = findEnclosingCodeBlockStart( - content, - idealMaxLength, - ); - - if (enclosingBlockStartForIdealMax !== -1) { - // idealMaxLength is inside a code block. Try to split *before* this block. - const textToSearchForNewline = content.substring( - 0, - enclosingBlockStartForIdealMax, - ); - - // Iteratively search for the last safe \n\n before enclosingBlockStartForIdealMax - let currentSearchFromIndex = textToSearchForNewline.length; - while (currentSearchFromIndex > 0) { - // searchEndIndex refers to character count to search within - const dnlIndex = textToSearchForNewline.lastIndexOf( - '\n\n', - currentSearchFromIndex - 1, - ); // fromIndex for lastIndexOf is 0-based - if (dnlIndex === -1) break; - - const potentialSplit = dnlIndex + 2; - // The split must be strictly before the block idealMaxLength was in. - // This is implicitly true if dnlIndex is found within textToSearchForNewline. - if (!isIndexInsideCodeBlock(content, potentialSplit)) { - // Condition: (potentialSplit > 0) OR (it's 0 AND the problematic block also started at 0) - if ( - potentialSplit > 0 || - (enclosingBlockStartForIdealMax === 0 && potentialSplit === 0) - ) { - return potentialSplit; - } - } - currentSearchFromIndex = dnlIndex; // Continue search before the start of this found \n\n - // (dnlIndex is start of \n\n, so next search is before it) - } - - // Iteratively search for the last safe \n - currentSearchFromIndex = textToSearchForNewline.length; - while (currentSearchFromIndex >= 0) { - // Can be 0 if textToSearchForNewline has length 1 and it's \n - const snlIndex = textToSearchForNewline.lastIndexOf( - '\n', - currentSearchFromIndex - 1, - ); - if (snlIndex === -1) break; - - const potentialSplit = snlIndex + 1; - if (!isIndexInsideCodeBlock(content, potentialSplit)) { - if ( - potentialSplit > 0 || - (enclosingBlockStartForIdealMax === 0 && potentialSplit === 0) - ) { - return potentialSplit; - } - } - currentSearchFromIndex = snlIndex; - } - - // Fallback: split right before this code block - return enclosingBlockStartForIdealMax; - } - - // idealMaxLength is NOT inside a code block. - // Search forwards from idealMaxLength for the next double newline (\n\n) not in a code block. - let searchStartIndex = idealMaxLength; - while (searchStartIndex < content.length) { - const dnlIndex = content.indexOf('\n\n', searchStartIndex); - if (dnlIndex === -1) { - // No more double newlines found after idealMaxLength - break; - } - - const potentialSplitPoint = dnlIndex + 2; - if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) { - return potentialSplitPoint; - } - - searchStartIndex = potentialSplitPoint; // Continue search after the found \n\n - } - - // If no safe double newline found after idealMaxLength, return content.length - // to keep the entire content as one piece. - return content.length; -}; - export const findLastSafeSplitPoint = (content: string) => { const enclosingBlockStart = findEnclosingCodeBlockStart( content, |
