|
|
@@ -74,6 +74,46 @@
|
|
|
return ltrim($text, '<br>');
|
|
|
};
|
|
|
|
|
|
+ $renderAnswerSolutionWithStepBoxes = function (string $solutionHtml): string {
|
|
|
+ $solution = trim($solutionHtml);
|
|
|
+ if ($solution === '' || $solution === '(无详解)') {
|
|
|
+ return $solutionHtml;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 去掉分步得分等分值标记,与判卷页一致
|
|
|
+ $solution = preg_replace('/(\s*\d+\s*分\s*)/u', '', $solution) ?? $solution;
|
|
|
+
|
|
|
+ // 与判卷页一致:优先识别“步骤X / 第X步”
|
|
|
+ if (preg_match('/(步骤\s*\d+|第\s*\d+\s*步)/u', $solution)) {
|
|
|
+ $parts = preg_split('/(?=步骤\s*\d+|第\s*\d+\s*步)/u', $solution, -1, PREG_SPLIT_NO_EMPTY) ?: [];
|
|
|
+ $processed = '';
|
|
|
+ foreach ($parts as $index => $part) {
|
|
|
+ $stepText = trim((string) $part);
|
|
|
+ if ($stepText === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $prefix = $index > 0 ? '<br>' : '';
|
|
|
+ $isStep = preg_match('/^(步骤\s*\d+|第\s*\d+\s*步)/u', $stepText);
|
|
|
+ if ($isStep) {
|
|
|
+ $processed .= $prefix
|
|
|
+ . '<span class="solution-step"><span class="step-box"><span class="detail-grade-box"></span></span><span class="step-label">'
|
|
|
+ . $stepText
|
|
|
+ . '</span></span>';
|
|
|
+ } else {
|
|
|
+ // 与判卷页保持一致:步骤前引导语不加方框
|
|
|
+ $processed .= $prefix . '<span class="step-label">' . $stepText . '</span>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $processed !== '' ? $processed : $solution;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 无步骤关键词:与判卷页一致,在解析开头加一个判分框
|
|
|
+ return '<span class="solution-step"><span class="step-box"><span class="detail-grade-box"></span></span><span class="step-label">'
|
|
|
+ . $solution
|
|
|
+ . '</span></span>';
|
|
|
+ };
|
|
|
+
|
|
|
@endphp
|
|
|
|
|
|
<div class="answer-detail-page">
|
|
|
@@ -92,6 +132,8 @@
|
|
|
@foreach($allQuestions as $q)
|
|
|
@php
|
|
|
$no = (int) ($q->question_number ?? 0);
|
|
|
+ $questionType = strtolower((string) ($q->question_type ?? ''));
|
|
|
+ $isAnswerType = $questionType === 'answer';
|
|
|
$rawAnswer = trim((string) ($q->answer ?? ''));
|
|
|
$rawSolution = $normalizeDetailHtml($q->solution ?? '');
|
|
|
$isSeeSolutionAnswer = (bool) preg_match('/^见\s*解析[。\.]?$|^详见解析/u', $rawAnswer);
|
|
|
@@ -102,6 +144,9 @@
|
|
|
$renderSolution = $rawSolution !== ''
|
|
|
? \App\Services\MathFormulaProcessor::processFormulas($formatDetailForReadability($rawSolution))
|
|
|
: '(无详解)';
|
|
|
+ if ($isAnswerType) {
|
|
|
+ $renderSolution = $renderAnswerSolutionWithStepBoxes($renderSolution);
|
|
|
+ }
|
|
|
@endphp
|
|
|
<div class="answer-detail-item">
|
|
|
<div class="entry-line">
|