detective-app: 메모 보기에서 폭 절반을 넘는 문장 뒤는 다음 문장을 새 줄에서 시작
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0557c77a0
commit
fdc5951f3c
1 file changed
+24
-7
@@ -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,'<').replace(/>/g,'>');
|
||||
const inl=t=>t.replace(/`([^`]+)`/g,'<code>$1</code>').replace(/\*\*(.+?)\*\*/g,'<strong>$1</strong>')
|
||||
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'<a href="$2" target="_blank" rel="noopener">$1</a>')
|
||||
.replace(/(^|[^"=>])(https?:\/\/[^\s<)]+)/g,'$1<a href="$2" target="_blank" rel="noopener">$2</a>');
|
||||
// 전체 폭의 절반을 넘는 문장 뒤에서는 다음 문장을 새 줄에서 시작한다(짧은 문장은 그대로 이어 흐름).
|
||||
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<parts.length;k++){
|
||||
const prev=parts[k-1].replace(/<[^>]+>/g,'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
r+=(opt.measure(prev)>opt.maxW/2?'<br>':' ')+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('<div class="nv-p">'+para.join('<br>')+'</div>');para=null;}};
|
||||
const flush=()=>{if(para){out.push('<div class="nv-p">'+para.map(sb).join('<br>')+'</div>');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+1<lines.length&&lines[i+1].trim()&&!LI.test(lines[i+1])&&indentOf(lines[i+1])>indentOf(l)&&!/^\s*[|#>]/.test(lines[i+1])){
|
||||
i++;html+=(last.trim().length>=45?' ':'<br>')+inl(esc(lines[i].trim()));last=lines[i];
|
||||
}
|
||||
out.push(`<div class="nv-li" style="margin-left:${lvl*1.2}em"><span class="nv-mk">${esc(marker)}</span><span>${html}</span></div>`);
|
||||
out.push(`<div class="nv-li" style="margin-left:${lvl*1.2}em"><span class="nv-mk">${esc(marker)}</span><span>${sb(html)}</span></div>`);
|
||||
i++;continue;
|
||||
}
|
||||
// "항목 : 값"
|
||||
if((m=l.match(/^(\s*)([^\s:|][^:|]{0,11}?)\s*:\s+(.*)$/))&&!/https?$/.test(m[2])){
|
||||
flush();let html=`<span class="nv-k">${esc(m[2].trim())}</span> ${inl(esc(m[3]))}`;
|
||||
flush();let html=`<span class="nv-k">${esc(m[2].trim())}</span> ${sb(inl(esc(m[3])))}`;
|
||||
while(i+1<lines.length&&lines[i+1].trim()&&indentOf(lines[i+1])>=4&&!LI.test(lines[i+1])&&!/^\s*[|#>]/.test(lines[i+1])){
|
||||
i++;html+='<br><span class="nv-cont">'+inl(esc(lines[i].trim()))+'</span>';
|
||||
}
|
||||
@@ -1040,7 +1052,7 @@ function notesRender(raw){
|
||||
}
|
||||
// 일반 줄 (들여쓴 줄은 들여쓰기 유지)
|
||||
const ind=indentOf(l);
|
||||
if(ind>=4){flush();out.push(`<div class="nv-p" style="margin-left:${Math.min(ind/2,12)*0.6}em">${inl(esc(l.trim()))}</div>`);i++;continue;}
|
||||
if(ind>=4){flush();out.push(`<div class="nv-p" style="margin-left:${Math.min(ind/2,12)*0.6}em">${sb(inl(esc(l.trim())))}</div>`);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');
|
||||
|
||||
Reference in new issue
Block a user