Commit 55830813 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(captain): an answer lost everything after its chart

The "drop an unclosed code block" cleanup matched a chart's closing fence
whenever no backtick followed it, and deleted that fence and the rest of the
answer — the table note, the «ملحوظة» line. It now cuts only when the number of
fences is odd, and never a chart that is still being written. Found on the
first live end-to-end answer.
Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
parent 354d0675
......@@ -85,8 +85,14 @@ final class AnswerParser
$md = (string) preg_replace_callback('/```([\w-]*)[^\n]*\n(.*?)```/su', function (array $m): string {
return strtolower($m[1]) === 'mermaid' ? $m[0] : '';
}, $md);
// An unclosed fence that is not a chart (a reply cut mid-block).
$md = (string) preg_replace('/```(?!mermaid)[\w-]*\n[^`]*$/su', '', $md);
// A reply cut mid-block leaves one fence open. Only then — an odd number of
// fences — drop the open block, and never a chart still being written.
if (preg_match_all('/^```/m', $md) % 2 === 1) {
$open = strrpos($md, '```');
if (!preg_match('/^```mermaid\b/i', substr($md, $open))) {
$md = substr($md, 0, $open);
}
}
// Server paths, source paths and file names.
$md = (string) preg_replace('~(?:/config|/var/www|/opt|/etc|/proc|/home|/root|/usr|/tmp)(?:/[\w.\-]+)+~u', '', $md);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment