]+>/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');