diff --git a/web-ui/html/detective-app.html b/web-ui/html/detective-app.html index 3ea9c83..23c9253 100644 --- a/web-ui/html/detective-app.html +++ b/web-ui/html/detective-app.html @@ -963,11 +963,23 @@ function notesTabsToMd(raw){ // 메모 보기 화면: md 문서처럼 정리해서 보여준다(표시용일 뿐, 저장된 원문은 그대로). // 제목(#, [제목]), 목록(-, *, •, 1., 1), 가., (1)) 들여쓰기 단계, "항목 : 값", 인용(>), 구분선, 표(| 또는 탭), // 굵게/코드/링크를 처리하고, 하드 개행된 긴 문장(45자↑)은 이어 붙여 화면 폭에 맞춘다. -function notesRender(raw){ +function notesRender(raw,opt){ const esc=t=>t.replace(/&/g,'&').replace(//g,'>'); const inl=t=>t.replace(/`([^`]+)`/g,'$1').replace(/\*\*(.+?)\*\*/g,'$1') .replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'$1') .replace(/(^|[^"=>])(https?:\/\/[^\s<)]+)/g,'$1$2'); + // 전체 폭의 절반을 넘는 문장 뒤에서는 다음 문장을 새 줄에서 시작한다(짧은 문장은 그대로 이어 흐름). + const sb=h=>{ + if(!opt||!opt.measure)return h; + const parts=h.split(/(?<=[.!?。])\s+(?![^<]*>)/); + if(parts.length<2)return h; + let r=parts[0]; + for(let k=1;k]+>/g,'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); + r+=(opt.measure(prev)>opt.maxW/2?'
':' ')+parts[k]; + } + return r; + }; const indentOf=l=>{let n=0;for(const ch of l){if(ch==='\t')n+=4;else if(ch===' ')n++;else break;}return n;}; const LI=/^(\s*)([-*•·▪‣◦○●■□→]|\d{1,2}[.)]|\(\d{1,2}\)|[가-힣][.)])\s+(.*)$/; // 한 줄로 뭉쳐 붙여넣은 번호 목록("1. … 2. … 3. …")을 항목별로 나누고, "항목: - 내용"은 하위 항목으로 내린다. @@ -997,7 +1009,7 @@ function notesRender(raw){ }; const lines=expand(notesTabsToMd(raw).split('\n')); const out=[];let i=0,para=null; - const flush=()=>{if(para){out.push('
'+para.join('
')+'
');para=null;}}; + const flush=()=>{if(para){out.push('
'+para.map(sb).join('
')+'
');para=null;}}; const pushText=(html,rawLine)=>{ if(para&¶.length&&rawLine&¶.prevRaw&¶.prevRaw.trim().length>=45&&!LI.test(rawLine)&&!/^\s*\[/.test(rawLine)&&!/^\s*[^\s:]{1,12}\s*:\s/.test(rawLine)){ para[para.length-1]+=' '+html; @@ -1027,12 +1039,12 @@ function notesRender(raw){ while(i+1indentOf(l)&&!/^\s*[|#>]/.test(lines[i+1])){ i++;html+=(last.trim().length>=45?' ':'
')+inl(esc(lines[i].trim()));last=lines[i]; } - out.push(`
${esc(marker)}${html}
`); + out.push(`
${esc(marker)}${sb(html)}
`); i++;continue; } // "항목 : 값" if((m=l.match(/^(\s*)([^\s:|][^:|]{0,11}?)\s*:\s+(.*)$/))&&!/https?$/.test(m[2])){ - flush();let html=`${esc(m[2].trim())} ${inl(esc(m[3]))}`; + flush();let html=`${esc(m[2].trim())} ${sb(inl(esc(m[3])))}`; while(i+1=4&&!LI.test(lines[i+1])&&!/^\s*[|#>]/.test(lines[i+1])){ i++;html+='
'+inl(esc(lines[i].trim()))+''; } @@ -1040,7 +1052,7 @@ function notesRender(raw){ } // 일반 줄 (들여쓴 줄은 들여쓰기 유지) const ind=indentOf(l); - if(ind>=4){flush();out.push(`
${inl(esc(l.trim()))}
`);i++;continue;} + if(ind>=4){flush();out.push(`
${sb(inl(esc(l.trim())))}
`);i++;continue;} pushText(inl(esc(l.trim())),l);i++; } flush(); @@ -1051,9 +1063,14 @@ function refreshNotesView(){ if(!ta||!view)return; const raw0=ta.value||''; if(!raw0.trim()||document.activeElement===ta){view.style.display='none';ta.style.display='';return;} - view.innerHTML=notesRender(raw0); - ta.style.display='none';view.style.display=''; + ta.style.display='none';view.style.display=''; // 폭을 재려면 먼저 보이게 한다 + const maxW=Math.max(120,view.clientWidth-34); + const ctx=(refreshNotesView._c||(refreshNotesView._c=document.createElement('canvas'))).getContext('2d'); + ctx.font=getComputedStyle(view).font; + view.innerHTML=notesRender(raw0,{maxW,measure:t=>ctx.measureText(t).width}); } +let _nvResizeT=null; +window.addEventListener('resize',()=>{clearTimeout(_nvResizeT);_nvResizeT=setTimeout(()=>{const v=document.getElementById('case-notes-view');if(v&&v.style.display!=='none')refreshNotesView();},200);}); function editNotes(ev){ if(ev&&ev.target&&ev.target.closest&&ev.target.closest('a'))return; // 링크 클릭은 편집 전환 안 함 const ta=document.getElementById('case-notes'),view=document.getElementById('case-notes-view');