MCPcopy Create free account
hub / github.com/anus-dev/ANUS / findEnclosingCodeBlockStart

Function findEnclosingCodeBlockStart

packages/cli/src/ui/utils/markdownUtilities.ts:69–92  ·  view source on GitHub ↗
(
  content: string,
  index: number,
)

Source from the content-addressed store, hash-verified

67 * @returns Start index of the enclosing code block or -1.
68 */
69const findEnclosingCodeBlockStart = (
70 content: string,
71 index: number,
72): number => {
73 if (!isIndexInsideCodeBlock(content, index)) {
74 return -1;
75 }
76 let currentSearchPos = 0;
77 while (currentSearchPos < index) {
78 const blockStartIndex = content.indexOf('```', currentSearchPos);
79 if (blockStartIndex === -1 || blockStartIndex >= index) {
80 break;
81 }
82 const blockEndIndex = content.indexOf('```', blockStartIndex + 3);
83 if (blockStartIndex < index) {
84 if (blockEndIndex === -1 || index < blockEndIndex + 3) {
85 return blockStartIndex;
86 }
87 }
88 if (blockEndIndex === -1) break;
89 currentSearchPos = blockEndIndex + 3;
90 }
91 return -1;
92};
93
94export const findLastSafeSplitPoint = (content: string) => {
95 const enclosingBlockStart = findEnclosingCodeBlockStart(

Callers 1

findLastSafeSplitPointFunction · 0.85

Calls 1

isIndexInsideCodeBlockFunction · 0.85

Tested by

no test coverage detected