MCPcopy Create free account
hub / github.com/Icecubesaad/OpenLLM-Studio / closeOpenSyntax

Function closeOpenSyntax

src/lib/markdown.ts:72–102  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

70}
71
72function closeOpenSyntax(content: string): string {
73 let result = content;
74
75 // Detect open fence by counting fence-opening lines vs fence-closing lines.
76 // A line that starts with ``` is a fence marker. Odd count = still open.
77 const fenceLines = result.split('\n').filter(l => l.trim().startsWith('```'));
78 const inFence = fenceLines.length % 2 === 1;
79
80 // If we're inside a fence, close it so the parser renders what's there
81 if (inFence) {
82 result += '\n```';
83 return result; // Don't mess with inline markers inside a code block
84 }
85
86 // Close open inline backtick (single `)
87 // Count single backticks that are NOT part of triple backticks
88 const withoutFences = result.replace(/```[\s\S]*?```/g, '').replace(/```/g, '');
89 const singleTicks = (withoutFences.match(/(?<!\\)`/g) ?? []).length;
90 if (singleTicks % 2 === 1) result += '`';
91
92 // Close open bold **
93 const boldCount = (result.match(/\*\*/g) ?? []).length;
94 if (boldCount % 2 === 1) result += '**';
95
96 // Close open italic * (excluding ** pairs)
97 const withoutBold = result.replace(/\*\*/g, '');
98 const italicCount = (withoutBold.match(/\*/g) ?? []).length;
99 if (italicCount % 2 === 1) result += '*';
100
101 return result;
102}

Callers 1

splitStreamingMarkdownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected