paper-body.blade.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. @php
  2. $choiceQuestions = $questions['choice'] ?? [];
  3. $fillQuestions = $questions['fill'] ?? [];
  4. $answerQuestions = $questions['answer'] ?? [];
  5. $gradingMode = $grading ?? false;
  6. // 是否在题干后显示题目ID (Q000123)
  7. $showQuestionId = config('exam.show_question_id_in_pdf', false);
  8. // 格式化题目ID为6位补0格式
  9. $formatQuestionId = function($id) {
  10. if (empty($id)) return '';
  11. return '(Q' . str_pad($id, 6, '0', STR_PAD_LEFT) . ')';
  12. };
  13. // 【新增】动态计算大题号 - 根据有题目的题型分配序号
  14. $sectionNumbers = [
  15. 'choice' => null,
  16. 'fill' => null,
  17. 'answer' => null
  18. ];
  19. $currentSectionNumber = 1;
  20. // 只给有题目的题型分配序号
  21. if (!empty($choiceQuestions)) {
  22. $sectionNumbers['choice'] = $currentSectionNumber++;
  23. }
  24. if (!empty($fillQuestions)) {
  25. $sectionNumbers['fill'] = $currentSectionNumber++;
  26. }
  27. if (!empty($answerQuestions)) {
  28. $sectionNumbers['answer'] = $currentSectionNumber++;
  29. }
  30. // 获取题型名称的辅助函数
  31. $getSectionTitle = function($type, $sectionNumber) {
  32. $typeNames = [
  33. 'choice' => '选择题',
  34. 'fill' => '填空题',
  35. 'answer' => '解答题'
  36. ];
  37. // 将数字转换为中文数字
  38. $chineseNumbers = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
  39. $chineseNumber = $chineseNumbers[$sectionNumber] ?? (string)$sectionNumber;
  40. return $chineseNumber . '、' . $typeNames[$type];
  41. };
  42. // 检查是否有数学公式处理标记,避免重复处理
  43. $mathProcessed = false;
  44. // 检查所有题型中是否有任何题目包含 math_processed 标记
  45. foreach ([$choiceQuestions, $fillQuestions, $answerQuestions] as $questionType) {
  46. foreach ($questionType as $q) {
  47. if (isset($q->math_processed) && $q->math_processed) {
  48. $mathProcessed = true;
  49. break 2; // 找到标记就退出两层循环
  50. }
  51. }
  52. }
  53. // 计算填空空格数量
  54. $countBlanks = function($text) {
  55. $count = 0;
  56. $count += preg_match_all('/_{2,}/u', $text, $m);
  57. $count += preg_match_all('/(\s*)/u', $text, $m);
  58. $count += preg_match_all('/\(\s*\)/', $text, $m);
  59. return max(1, $count);
  60. };
  61. // 计算步骤数量
  62. $countSteps = function($text) {
  63. $matches = [];
  64. $cnt = preg_match_all('/第\s*\d+\s*步/u', $text ?? '', $matches);
  65. return max(1, $cnt);
  66. };
  67. $renderBoxes = function($num) {
  68. // 判卷方框放大 1.2 倍,保持单行布局
  69. if ($num == 2) {
  70. // 两个方框时,使用右对齐布局
  71. return '<div style="display:flex;justify-content:flex-end;gap:4px;">' .
  72. str_repeat('<span style="display:inline-block;width:17px;height:17px;line-height:17px;border:1px solid #333;"></span>', $num) .
  73. '</div>';
  74. }
  75. return str_repeat('<span style="display:inline-block;width:17px;height:17px;line-height:17px;border:1px solid #333;margin-right:4px;vertical-align:middle;"></span>', $num);
  76. };
  77. @endphp
  78. {{-- 【新增】步骤方框CSS样式 --}}
  79. <style>
  80. .solution-step {
  81. display: block;
  82. margin: 8px 0;
  83. padding: 4px 0;
  84. }
  85. .step-box {
  86. display: inline-block;
  87. margin-right: 8px;
  88. vertical-align: middle;
  89. }
  90. .step-label {
  91. white-space: normal;
  92. vertical-align: middle;
  93. }
  94. .solution-section {
  95. margin: 10px 0;
  96. padding: 8px;
  97. background-color: #f9f9f9;
  98. }
  99. </style>
  100. <!-- 动态大题号 - 选择题 -->
  101. @if($sectionNumbers['choice'] !== null)
  102. <div class="section-title">{{ $getSectionTitle('choice', $sectionNumbers['choice']) }}
  103. @if(count($choiceQuestions) > 0)
  104. @php
  105. $choiceTotal = array_sum(array_map(fn($q) => $q->score ?? 5, $choiceQuestions));
  106. @endphp
  107. (本大题共 {{ count($choiceQuestions) }} 小题,共 {{ $choiceTotal }} 分)
  108. @else
  109. (本大题共 0 小题,共 0 分)
  110. @endif
  111. </div>
  112. @if(count($choiceQuestions) > 0)
  113. @foreach($choiceQuestions as $index => $q)
  114. @php
  115. // 【修复】使用question_number字段作为显示序号,确保全局序号一致性
  116. $questionNumber = $q->question_number ?? ($index + 1);
  117. $cleanContent = preg_replace('/^\d+[\.、]\s*/', '', $q->content);
  118. $cleanContent = trim($cleanContent);
  119. $options = $q->options ?? [];
  120. if (empty($options)) {
  121. // 【修复】选项标记必须在行首或空白后,避免误匹配 SVG 注释中的 BD:DC 等内容
  122. $pattern = '/(?:^|\s)([A-D])[\.、:.:]\s*(.+?)(?=(?:^|\s)[A-D][\.、:.:]|$)/su';
  123. if (preg_match_all($pattern, $cleanContent, $matches, PREG_SET_ORDER)) {
  124. foreach ($matches as $match) {
  125. $optionText = trim($match[2]);
  126. if (!empty($optionText)) {
  127. $options[] = $optionText;
  128. }
  129. }
  130. }
  131. }
  132. $stemLine = $cleanContent;
  133. if (!empty($options)) {
  134. // 【修复】只匹配行首或空白后的选项标记,避免误匹配 SVG 注释中的 BD:DC 等内容
  135. if (preg_match('/^(.+?)(?=(?:^|\s)[A-D][\.、:.:])/su', $cleanContent, $stemMatch)) {
  136. $stemLine = trim($stemMatch[1]);
  137. }
  138. }
  139. // 将题干中的空括号/下划线替换为短波浪线;如无占位符,则在末尾追加短波浪线
  140. $blankSpan = '<span style="display:inline-block; min-width:80px; border-bottom:1.2px dashed #444; vertical-align:bottom;">&nbsp;</span>';
  141. // 【修复】扩展下划线转换规则,支持LaTeX格式和多种占位符
  142. $renderedStem = $stemLine;
  143. // 先处理LaTeX格式的underline命令
  144. $renderedStem = preg_replace('/\\\underline\{[^}]*\}/', $blankSpan, $renderedStem);
  145. $renderedStem = preg_replace('/\\\qquad+/', $blankSpan, $renderedStem);
  146. // 【修复】在处理填空占位符时,保护LaTeX公式不被破坏
  147. // 先标记LaTeX公式区域
  148. $latexPlaceholders = [];
  149. $counter = 0;
  150. $renderedStem = preg_replace_callback('/\$[^$]+\$/u', function($matches) use (&$latexPlaceholders, &$counter, $blankSpan) {
  151. $placeholder = '<<<LATEX_' . $counter . '>>>';
  152. $latexPlaceholders[$placeholder] = $matches[0];
  153. $counter++;
  154. return $placeholder;
  155. }, $renderedStem);
  156. // 现在处理普通占位符(不会破坏LaTeX公式)
  157. $renderedStem = preg_replace(['/(\s*)/u', '/\(\s*\)/', '/_{2,}/'], $blankSpan, $renderedStem);
  158. // 恢复LaTeX公式(并进行HTML实体编码防止被浏览器解析)
  159. foreach ($latexPlaceholders as $placeholder => $latexContent) {
  160. $encodedLatex = htmlspecialchars($latexContent, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  161. $renderedStem = str_replace($placeholder, $encodedLatex, $renderedStem);
  162. }
  163. // 如果没有占位符,在末尾添加
  164. if ($renderedStem === $stemLine) {
  165. $renderedStem .= ' ' . $blankSpan;
  166. }
  167. $renderedStem = $mathProcessed ? $renderedStem : \App\Services\MathFormulaProcessor::processFormulas($renderedStem);
  168. @endphp
  169. <div class="question">
  170. <div class="question-grid">
  171. <div class="question-lead">
  172. @if($gradingMode)
  173. <span class="grading-boxes">{!! $renderBoxes(1) !!}</span>
  174. @endif
  175. <span class="question-number">{{ $gradingMode ? '题目 ' : '' }}{{ $questionNumber }}.</span>
  176. </div>
  177. <div class="question-main">
  178. <span class="question-stem">{!! $renderedStem !!}</span>
  179. @if($showQuestionId && !empty($q->id))
  180. <span class="question-id" style="font-size:10px;color:#999;margin-left:4px;">{!! $formatQuestionId($q->id) !!}</span>
  181. @endif
  182. </div>
  183. @if(!empty($options))
  184. @php
  185. // 计算选项长度并动态选择布局
  186. $optCount = count($options);
  187. $maxOptionLength = 0;
  188. foreach ($options as $opt) {
  189. $optText = strip_tags(\App\Services\MathFormulaProcessor::processFormulas($opt));
  190. $maxOptionLength = max($maxOptionLength, mb_strlen($optText, 'UTF-8'));
  191. }
  192. // 根据最长选项长度和选项数量动态选择布局
  193. // 短选项(≤15字符)且选项数≤4:4列布局
  194. // 中等选项(16-30字符)或选项数>4:2列布局
  195. // 长选项(>30字符):1列布局
  196. if ($maxOptionLength <= 15 && $optCount <= 4) {
  197. $optionsClass = 'options-grid-4';
  198. $layoutDesc = '4列布局';
  199. } elseif ($maxOptionLength <= 30) {
  200. $optionsClass = 'options-grid-2';
  201. $layoutDesc = '2列布局';
  202. } else {
  203. $optionsClass = 'options-grid-1';
  204. $layoutDesc = '1列布局';
  205. }
  206. \Illuminate\Support\Facades\Log::debug('选择题布局决策', [
  207. 'question_number' => $questionNumber,
  208. 'opt_count' => $optCount,
  209. 'max_length' => $maxOptionLength,
  210. 'selected_class' => $optionsClass,
  211. 'layout' => $layoutDesc
  212. ]);
  213. @endphp
  214. <div class="question-lead spacer"></div>
  215. <div class="{{ $optionsClass }}">
  216. @foreach($options as $optIndex => $opt)
  217. @php
  218. // 兼容两种格式:数字索引 (0,1,2,3) 或字母键 (A,B,C,D)
  219. if (is_numeric($optIndex)) {
  220. $label = chr(65 + (int)$optIndex);
  221. } else {
  222. $label = strtoupper($optIndex);
  223. }
  224. // 对LaTeX公式中的特殊字符进行HTML实体编码,防止被浏览器当作HTML标签处理
  225. $encodedOpt = htmlspecialchars($opt, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  226. $renderedOpt = $mathProcessed ? $encodedOpt : \App\Services\MathFormulaProcessor::processFormulas($encodedOpt);
  227. @endphp
  228. <div class="option option-compact">
  229. <strong>{{ $label }}.</strong>&nbsp;{!! $renderedOpt !!}
  230. </div>
  231. @endforeach
  232. </div>
  233. @endif
  234. @if($gradingMode)
  235. @php
  236. $solutionText = trim($q->solution ?? '');
  237. // 去掉前置的"解题思路"标签,避免出现"解题思路:【解题思路】"重复
  238. $solutionText = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $solutionText);
  239. $solutionHtml = $solutionText === ''
  240. ? '<span style="color:#999;font-style:italic;">(暂无解题思路)</span>'
  241. : ($mathProcessed ? $solutionText : \App\Services\MathFormulaProcessor::processFormulas($solutionText));
  242. @endphp
  243. <div class="question-lead spacer"></div>
  244. <div class="answer-meta">
  245. <div class="answer-line"><strong>正确答案:</strong><span class="solution-content">{!! $mathProcessed ? ($q->answer ?? '') : \App\Services\MathFormulaProcessor::processFormulas($q->answer ?? '') !!}</span></div>
  246. <div class="answer-line"><strong>解题思路:</strong><span class="solution-content">{!! $solutionHtml !!}</span></div>
  247. </div>
  248. @endif
  249. </div>
  250. </div>
  251. @endforeach
  252. @else
  253. <div class="question">
  254. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  255. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  256. </div>
  257. </div>
  258. @endif
  259. @endif
  260. <!-- 动态大题号 - 填空题 -->
  261. @if($sectionNumbers['fill'] !== null)
  262. <div class="section-title">{{ $getSectionTitle('fill', $sectionNumbers['fill']) }}
  263. @if(count($fillQuestions) > 0)
  264. @php
  265. $fillTotal = array_sum(array_map(fn($q) => $q->score ?? 5, $fillQuestions));
  266. @endphp
  267. (本大题共 {{ count($fillQuestions) }} 小题,共 {{ $fillTotal }} 分)
  268. @else
  269. (本大题共 0 小题,共 0 分)
  270. @endif
  271. </div>
  272. @if(count($fillQuestions) > 0)
  273. @foreach($fillQuestions as $index => $q)
  274. @php
  275. // 【修复】使用question_number字段作为显示序号,确保全局序号一致性
  276. $questionNumber = $q->question_number ?? (count($choiceQuestions) + $index + 1);
  277. $blankSpan = '<span style="display:inline-block; min-width:80px; border-bottom:1.2px dashed #444; vertical-align:bottom;">&nbsp;</span>';
  278. // 【修复】扩展下划线转换规则,支持LaTeX格式和多种占位符
  279. $renderedContent = $q->content;
  280. // 【修复】在处理填空占位符时,保护LaTeX公式不被破坏
  281. // 先标记LaTeX公式区域(支持包含反斜杠和花括号的LaTeX命令)
  282. $latexPlaceholders = [];
  283. $counter = 0;
  284. $renderedContent = preg_replace_callback('/\$(?:[^\$]|\\.)*\$/u', function($matches) use (&$latexPlaceholders, &$counter, $blankSpan) {
  285. $placeholder = '<<<LATEX_FILL_' . $counter . '>>>';
  286. $latexPlaceholders[$placeholder] = $matches[0];
  287. $counter++;
  288. return $placeholder;
  289. }, $renderedContent);
  290. // 现在处理普通占位符(不会破坏LaTeX公式)
  291. $renderedContent = preg_replace(['/(\s*)/u', '/\(\s*\)/', '/_{2,}/'], $blankSpan, $renderedContent);
  292. // 恢复LaTeX公式(并进行HTML实体编码防止被浏览器解析)
  293. foreach ($latexPlaceholders as $placeholder => $latexContent) {
  294. $encodedLatex = htmlspecialchars($latexContent, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  295. $renderedContent = str_replace($placeholder, $encodedLatex, $renderedContent);
  296. }
  297. // 如果没有占位符且内容没有变化,在末尾添加
  298. // 但要检查是否已经有填空占位符(如\underline{\qquad})
  299. if ($renderedContent === $q->content && !preg_match('/\\\\underline|\\\\qquad|(\s*)|\(\s*\)/', $renderedContent)) {
  300. $renderedContent .= ' ' . $blankSpan;
  301. }
  302. $renderedContent = $mathProcessed ? $renderedContent : \App\Services\MathFormulaProcessor::processFormulas($renderedContent);
  303. @endphp
  304. <div class="question">
  305. <div class="question-grid">
  306. <div class="question-lead">
  307. @if($gradingMode)
  308. <span class="grading-boxes">{!! $renderBoxes($countBlanks($q->content ?? '')) !!}</span>
  309. @endif
  310. <span class="question-number">{{ $gradingMode ? '题目 ' : '' }}{{ $questionNumber }}.</span>
  311. </div>
  312. <div class="question-main">
  313. <span class="question-stem">{!! $renderedContent !!}</span>
  314. @if($showQuestionId && !empty($q->id))
  315. <span class="question-id" style="font-size:10px;color:#999;margin-left:4px;">{!! $formatQuestionId($q->id) !!}</span>
  316. @endif
  317. </div>
  318. @if($gradingMode)
  319. @php
  320. $solutionText = trim($q->solution ?? '');
  321. // 去掉前置的"解题思路"标签,避免出现"解题思路:【解题思路】"重复
  322. $solutionText = preg_replace('/^【?\s*解题思路\s*】?\s*[::]?\s*/u', '', $solutionText);
  323. $solutionHtml = $solutionText === ''
  324. ? '<span style="color:#999;font-style:italic;">(暂无解题思路)</span>'
  325. : ($mathProcessed ? $solutionText : \App\Services\MathFormulaProcessor::processFormulas($solutionText));
  326. @endphp
  327. <div class="question-lead spacer"></div>
  328. <div class="answer-meta">
  329. <div class="answer-line"><strong>正确答案:</strong><span class="solution-content">{!! $mathProcessed ? ($q->answer ?? '') : \App\Services\MathFormulaProcessor::processFormulas($q->answer ?? '') !!}</span></div>
  330. <div class="answer-line"><strong>解题思路:</strong><span class="solution-content">{!! $solutionHtml !!}</span></div>
  331. </div>
  332. @endif
  333. </div>
  334. </div>
  335. @endforeach
  336. @else
  337. <div class="question">
  338. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  339. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  340. </div>
  341. </div>
  342. @endif
  343. @endif
  344. <!-- 动态大题号 - 解答题 -->
  345. @if($sectionNumbers['answer'] !== null)
  346. <div class="section-title">{{ $getSectionTitle('answer', $sectionNumbers['answer']) }}
  347. @if(count($answerQuestions) > 0)
  348. (本大题共 {{ count($answerQuestions) }} 小题,共 {{ array_sum(array_column($answerQuestions, 'score')) }} 分。解答应写出文字说明、证明过程或演算步骤)
  349. @else
  350. (本大题共 0 小题,共 0 分)
  351. @endif
  352. </div>
  353. @if(count($answerQuestions) > 0)
  354. @foreach($answerQuestions as $index => $q)
  355. @php
  356. // 【修复】使用question_number字段作为显示序号,确保全局序号一致性
  357. $questionNumber = $q->question_number ?? (count($choiceQuestions) + count($fillQuestions) + $index + 1);
  358. @endphp
  359. <div class="question">
  360. <div class="question-grid">
  361. <div class="question-lead">
  362. <span class="question-number">{{ $gradingMode ? '题目 ' : '' }}{{ $questionNumber }}.</span>
  363. </div>
  364. <div class="question-main">
  365. @unless($gradingMode)
  366. <span class="question-score-inline">(本小题满分 {{ $q->score ?? 10 }} 分)</span>
  367. @endunless
  368. <span class="question-stem">{!! $mathProcessed ? $q->content : \App\Services\MathFormulaProcessor::processFormulas($q->content) !!}</span>
  369. @if($showQuestionId && !empty($q->id))
  370. <span class="question-id" style="font-size:10px;color:#999;margin-left:4px;">{!! $formatQuestionId($q->id) !!}</span>
  371. @endif
  372. </div>
  373. @unless($gradingMode)
  374. <div class="question-lead spacer"></div>
  375. <div class="answer-area boxy">
  376. <span class="answer-label">作答</span>
  377. </div>
  378. @endunless
  379. @if($gradingMode)
  380. @php
  381. $solutionRaw = $q->solution ?? '';
  382. $solutionProcessed = $mathProcessed ? $solutionRaw : \App\Services\MathFormulaProcessor::processFormulas($solutionRaw);
  383. // 去掉分步得分等分值标记
  384. $solutionProcessed = preg_replace('/(\s*\d+\s*分\s*)/u', '', $solutionProcessed);
  385. // 【修复】优化解析分段格式 - 支持两种格式:
  386. // 1. 【解题思路】格式
  387. // 2. 解题过程:格式
  388. // 先处理【】格式
  389. $solutionProcessed = preg_replace('/【(解题思路|详细解答|最终答案)】/u', "\n\n===SECTION_START===\n【$1】\n===SECTION_END===\n\n", $solutionProcessed);
  390. // 【扩展】处理多种"解题过程"格式,包括带括号的内容
  391. $solutionProcessed = preg_replace('/(解题过程\s*[^:\n]*:)/u', "\n\n===SECTION_START===\n【解题过程】\n===SECTION_END===\n\n", $solutionProcessed);
  392. // 按section分割内容
  393. $sections = explode('===SECTION_START===', $solutionProcessed);
  394. $processedSections = [];
  395. foreach ($sections as $section) {
  396. if (empty(trim($section))) continue;
  397. // 去掉结尾标记
  398. $section = str_replace('===SECTION_END===', '', $section);
  399. // 检查是否是解题相关部分
  400. if (preg_match('/【(解题思路|详细解答|最终答案|解题过程)】/u', $section, $matches)) {
  401. $sectionTitle = $matches[0];
  402. $sectionContent = preg_replace('/【(解题思路|详细解答|最终答案|解题过程)】/u', '', $section);
  403. // 【修复】处理步骤 - 在每个"步骤N"或"第N步"前添加方框
  404. // 【优化】使用split分割步骤,为所有步骤添加方框(包括第一个)
  405. if (preg_match('/(步骤\s*\d+|第\s*\d+\s*步)/u', $sectionContent)) {
  406. // 使用前瞻断言分割,保留分隔符
  407. $allSteps = preg_split('/(?=步骤\s*\d+|第\s*\d+\s*步)/u', $sectionContent, -1, PREG_SPLIT_NO_EMPTY);
  408. if (count($allSteps) > 0) {
  409. $processed = '';
  410. // 为每个步骤添加方框(包括第一个)
  411. for ($i = 0; $i < count($allSteps); $i++) {
  412. $stepText = trim($allSteps[$i]);
  413. if (!empty($stepText)) {
  414. // 为每个步骤添加方框和换行(第一个步骤前面不加<br>)
  415. $prefix = ($i > 0) ? '<br>' : '';
  416. $processed .= $prefix . '<span class="solution-step"><span class="step-box">' . $renderBoxes(1) . '</span><span class="step-label">' . $stepText . '</span></span>';
  417. }
  418. }
  419. $sectionContent = $processed;
  420. }
  421. } else {
  422. // 没有明确步骤:在标题后添加一个方框作为开始
  423. $sectionContent = '<span class="solution-step"><span class="step-box">' . $renderBoxes(1) . '</span><span class="step-label">&nbsp;</span></span> ' . trim($sectionContent);
  424. }
  425. // 包装section
  426. $processedSections[] = '<div class="solution-section"><strong>' . $sectionTitle . '</strong><br>' . $sectionContent . '</div>';
  427. } else {
  428. // 非解题部分直接保留
  429. $processedSections[] = $section;
  430. }
  431. }
  432. // 重新组合所有部分
  433. $solutionProcessed = implode('', $processedSections);
  434. // 将多余的换行转换为<br>,但保留合理的段落间距
  435. $solutionProcessed = preg_replace('/\n{3,}/u', "\n\n", $solutionProcessed);
  436. $solutionProcessed = nl2br($solutionProcessed);
  437. @endphp
  438. <div class="question-lead spacer"></div>
  439. <div class="answer-meta">
  440. <div class="answer-line"><strong>正确答案:</strong><span class="solution-content">{!! $mathProcessed ? ($q->answer ?? '') : \App\Services\MathFormulaProcessor::processFormulas($q->answer ?? '') !!}</span></div>
  441. <div class="answer-line solution-parsed">{!! $solutionProcessed !!}</div>
  442. </div>
  443. @endif
  444. </div>
  445. </div>
  446. @endforeach
  447. @else
  448. <div class="question">
  449. <div class="question-content" style="font-style: italic; color: #999; padding: 20px; border: 1px dashed #ccc; background: #f9f9f9;">
  450. 该题型正在生成中或暂无题目,请稍后刷新页面查看
  451. </div>
  452. </div>
  453. @endif
  454. @endif