fix: 작업실 채팅 renderMd에 마크다운 표 지원 추가
모델 출력의 표는 세션에 줄바꿈까지 정상이었는데 renderMd에 표 처리가 없어 파이프 문자열이 평문 <p>로 뭉개져(HTML 줄바꿈 접힘) 한 줄로 합쳐 보였다 (09-24 실측: 카메라 모듈 스펙 표가 파이프soup로 복사됨). 구분행 |---| 있는 연속 파이프 라인만 <table>로 변환, 없으면 무사통과. 셀 안 굵게 유지, 단락 분기의 블록태그 검사에 table 추가. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1337,13 +1337,27 @@ function renderMd(text){
|
||||
const items=grp.split('\n').map(line=>'<li>'+line.replace(/^[-*]\s+/,'')+'</li>').join('');
|
||||
return lead+'<ul style="padding-left:16px;margin:3px 0">'+items+'</ul>';
|
||||
});
|
||||
// 표 — 연속하는 파이프 라인(구분행 |---| 포함)을 <table>로. 표 지원이 없어 파이프 문자열이
|
||||
// 평문으로 뭉개져 한 줄에 다 붙어 보였다(09-24 실측: 카메라 모듈 스펙 표가 그대로 복사됨).
|
||||
// 구분행이 없으면 표가 아니라고 보고 그대로 둔다.
|
||||
s=s.replace(/(?:\|.*\n?)+/g, grp=>{
|
||||
const lines=grp.replace(/\n$/,'').split('\n').filter(l=>l.trim());
|
||||
if(lines.length<2 || !/^\|[\s:|-]+$/.test(lines[1])) return grp;
|
||||
const mkRow=(line,tag)=>{
|
||||
const cs=line.replace(/^\s*\||\|\s*$/g,'').split('|')
|
||||
.map(c=>'<'+tag+' style="border:1px solid var(--rb-border,#d5d0c8);padding:2px 8px;text-align:left;font-weight:'+(tag==='th'?'600':'400')+'">'+c.trim()+'</'+tag+'>').join('');
|
||||
return '<tr>'+cs+'</tr>';
|
||||
};
|
||||
return '<table style="border-collapse:collapse;margin:6px 0;font-size:12px">'
|
||||
+mkRow(lines[0],'th')+lines.slice(2).map(l=>mkRow(l,'td')).join('')+'</table>';
|
||||
});
|
||||
// 단락 — 빈 줄 단위로 split. 이미 블록 태그(<h3>/<ul>/코드 자리표시자)로 시작하면
|
||||
// <p>로 감싸지 않는다.
|
||||
s=s.split(/\n{2,}/).map(chunk=>{
|
||||
const t=chunk.trim();
|
||||
if(!t)return '';
|
||||
if(/^\u0000B\d+\u0000$/.test(t))return t;
|
||||
if(/^<(h3|ul|pre)\b/.test(t))return t;
|
||||
if(/^<(h3|ul|pre|table)\b/.test(t))return t;
|
||||
return '<p>'+t+'</p>';
|
||||
}).join('');
|
||||
s=s.replace(/\u0000B(\d+)\u0000/g,(m,i)=>blocks[+i]||'');
|
||||
|
||||
Reference in New Issue
Block a user