fix: 修复 PR 生成页 INLINECODE 显示及复制 Markdown 失败问题
Deploy PR-Helper / deploy (push) Successful in 26s

- 改进 LLM 提示词,明确要求用反引号包裹代码引用,避免输出 INLINECODE 占位符
- 后端新增 fixInlineCode 后处理,将残留 INLINECODE 占位符转为反引号代码
- 前端在 done 回调中从结构化字段组装完整 markdown 文本,修复复制按钮复制空内容
- 复制按钮增加空内容检查和错误提示
- Markdown 预览区域初始隐藏,生成完成后自动显示
This commit is contained in:
2026-06-21 15:37:10 +08:00
parent 2d3e306067
commit 4a8e43e698
2 changed files with 48 additions and 4 deletions
+29 -3
View File
@@ -67,7 +67,7 @@
<p id="pr-impact" class="text-gray-700"></p>
</div>
<div class="mt-6 p-4 bg-gray-50 rounded-md">
<div id="markdown-preview" class="mt-6 p-4 bg-gray-50 rounded-md hidden">
<label class="block text-sm font-medium text-gray-500 mb-2">Markdown 预览</label>
<pre id="pr-markdown" class="whitespace-pre-wrap text-sm text-gray-800 font-mono"></pre>
</div>
@@ -213,6 +213,7 @@
document.getElementById('pr-details').innerHTML = '';
document.getElementById('pr-impact').textContent = '';
document.getElementById('pr-markdown').textContent = '';
document.getElementById('markdown-preview').classList.add('hidden');
markdownContent = '';
// Accumulate streaming content
@@ -252,6 +253,10 @@
document.getElementById('pr-markdown').textContent = markdownContent;
},
done() {
// Assemble full markdown from structured fields for copy
markdownContent = buildMarkdown(fields);
document.getElementById('pr-markdown').textContent = markdownContent;
document.getElementById('markdown-preview').classList.remove('hidden');
streaming.classList.add('hidden');
outputContent.classList.remove('hidden');
btn.disabled = false;
@@ -272,18 +277,39 @@
return Markdown.render(text);
}
function buildMarkdown(f) {
const parts = [];
if (f.title) parts.push(`# ${f.title}`);
if (f.type) parts.push(`**类型**: ${f.type}`);
if (f.summary) parts.push(`## 摘要\n${f.summary}`);
if (f.details) parts.push(`## 详细说明\n${f.details}`);
if (f.impact) parts.push(`## 影响\n${f.impact}`);
return parts.join('\n\n');
}
function copyMarkdown() {
const markdown = markdownContent || document.getElementById('pr-markdown').textContent;
if (!markdown.trim()) {
showToast('没有可复制的内容,请先生成 PR 描述', 'warning');
return;
}
navigator.clipboard.writeText(markdown).then(() => {
showToast('已复制到剪贴板', 'success');
}).catch(() => {
// Fallback for non-HTTPS or permission-denied contexts
const textarea = document.createElement('textarea');
textarea.value = markdown;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
try {
document.execCommand('copy');
showToast('已复制到剪贴板', 'success');
} catch (e) {
showToast('复制失败,请手动选择文本复制', 'error');
}
document.body.removeChild(textarea);
showToast('已复制到剪贴板', 'success');
});
}