detective-app: 메모의 탭 구분 표(웹/엑셀 복사본)도 표로 렌더링

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-16 14:13:26 +09:00
1 parent 447120c530
commit a601c229e6
1 file changed
+18 -1
+18 -1
View File
@@ -929,10 +929,27 @@ function onPriChange(){
function onNotesChange(){/* auto-save on blur */}
// 메모에 마크다운 표가 있으면, 편집 중이 아닐 때 표를 렌더링해서 보여준다(클릭하면 다시 편집).
// 저장되는 값은 항상 textarea의 원문 그대로다. 표가 없는 메모는 지금처럼 textarea만 쓴다.
// 웹/엑셀에서 표를 복사하면 탭으로 구분된 줄이 붙는다. 탭이 든 줄이 2줄 이상 연속이면 첫 줄을 머리글로 한
// 마크다운 표로 바꿔서 보여준다(표시용 변환일 뿐, 저장된 원문은 그대로).
function notesTabsToMd(raw){
const lines=raw.split('\n'),out=[];
const isTab=l=>l.replace(/^[\t ]+|[\t ]+$/g,'').includes('\t');
const row=l=>'| '+l.replace(/^[\t ]+|[\t ]+$/g,'').split('\t').map(c=>c.trim().replace(/\|/g,'\\|')).join(' | ')+' |';
for(let i=0;i<lines.length;){
let j=i;while(j<lines.length&&isTab(lines[j]))j++;
if(j-i>=2){
const n=lines[i].replace(/^[\t ]+|[\t ]+$/g,'').split('\t').length;
out.push(row(lines[i]),'|'+Array(n).fill('---').join('|')+'|');
for(let k=i+1;k<j;k++)out.push(row(lines[k]));
i=j;
}else out.push(lines[i++]);
}
return out.join('\n');
}
function refreshNotesView(){
const ta=document.getElementById('case-notes'),view=document.getElementById('case-notes-view');
if(!ta||!view)return;
const raw=ta.value||'';
const raw=notesTabsToMd(ta.value||'');
const hasTable=/^\s*\|.*\|\s*\n\s*\|?\s*:?-{2,}/m.test(raw);
if(!hasTable||document.activeElement===ta){view.style.display='none';ta.style.display='';return;}
const esc=raw.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');