)/u', '$1', $solution) ?? $solution;
$solution = $markComplexDisplayMath($solution);
// 将「分析/详解」转换为可分页语义块:标题 + 内容。
// 仅短小纯文本节绑定;含图/display 公式的节允许自然分页,减少整块推页空白。
$caseSectionClass = static function (string $body, bool $hasTitle = true): string {
$plainLength = mb_strlen(trim(strip_tags($body)), 'UTF-8');
$containsImage = str_contains($body, '
![]()
(.*?)<\/div>/u', $solution, -1, PREG_SPLIT_DELIM_CAPTURE);
if (is_array($chunks) && count($chunks) > 1) {
$sectionHtml = '';
$lead = trim((string) ($chunks[0] ?? ''));
if ($lead !== '') {
$leadClass = $caseSectionClass($lead, false);
$sectionHtml .= '
';
}
for ($i = 1; $i < count($chunks); $i += 2) {
$title = trim((string) ($chunks[$i] ?? ''));
$body = trim((string) ($chunks[$i + 1] ?? ''));
if ($title === '' && $body === '') {
continue;
}
$sectionClass = $caseSectionClass($body, true);
$sectionHtml .= '
' . $title . '
' . $body . '
';
}
if ($sectionHtml !== '') {
$solution = $sectionHtml;
}
} else {
$plainClass = $caseSectionClass($solution, false);
$solution = '
';
}
return $solution;
};
@endphp
案例分析
@foreach($point['cases'] as $case)
@php
$sourceText = '';
if (!empty($case['child_kp_name'])) {
// 只展示子知识点来源,不展示父知识点名称
$sourceText = trim((string) $case['child_kp_name']);
$parentName = trim((string) ($point['kp_name'] ?? ''));
if ($parentName !== '') {
$escapedParent = preg_quote($parentName, '/');
$sourceText = preg_replace('/^' . $escapedParent . '\s*[-—-\/]\s*/u', '', $sourceText) ?? $sourceText;
}
if (preg_match('/[-—-\/]/u', $sourceText)) {
$parts = preg_split('/\s*[-—-\/]\s*/u', $sourceText);
if (is_array($parts) && !empty($parts)) {
$sourceText = trim((string) end($parts));
}
}
} elseif (!empty($case['is_wrong_case'])) {
$sourceText = '错题讲解';
} elseif (($case['source_type'] ?? '') === 'reviewed') {
$sourceText = '已做题';
} elseif (($case['source_type'] ?? '') === 'fallback') {
$sourceText = '补充题';
}
@endphp
@php
$stemLine = trim((string) ($case['stem'] ?? ''));
if ($stemLine === '') {
$renderedStemHtml = '—';
} else {
[$renderedStemHtml] = \App\Support\BlankPlaceholderRenderer::replaceToBlankSpan($stemLine, null, true, false);
$renderedStemHtml = \App\Support\BlankPlaceholderRenderer::normalizeTerminalPunctuation($renderedStemHtml, 'remove');
$renderedStemHtml = $formatStemLikePaper($renderedStemHtml);
$renderedStemHtml = \App\Services\MathFormulaProcessor::processFormulas($renderedStemHtml);
$renderedStemHtml = $markComplexDisplayMath($renderedStemHtml);
}
@endphp
例{{ $loop->iteration }}.
@if($sourceText !== '')
({{ $sourceText }})
@endif
{!! $renderedStemHtml !!}
@php
$options = (array) ($case['options'] ?? []);
@endphp
@if(!empty($options))
@include('pdf.partials.exam-choice-options', [
'options' => $options,
'gradingMode' => false,
'mathProcessed' => false,
'logQuestionNumber' => 'kp-' . ($case['question_id'] ?? $loop->iteration),
'showLeadSpacer' => false,
])
@endif
@endforeach
@endif
@endforeach