detective-app: 메모 보기 화면을 md 문서처럼 렌더링 (제목·목록·들여쓰기·번호·항목:값·인용·링크·표)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e77d5f8673
commit
98ac206e1f
1 file changed
+78
-18
@@ -93,12 +93,25 @@ body{background:var(--bg);color:var(--text);font-family:system-ui,sans-serif;dis
|
||||
.dt-notes-textarea{flex:1;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:12px 14px;font-size:12px;color:var(--text);font-family:inherit;resize:none;outline:none;line-height:1.7;transition:.15s;}
|
||||
.dt-notes-textarea:focus{border-color:#3b82f6;}
|
||||
.dt-notes-textarea::placeholder{color:var(--muted);}
|
||||
.dt-notes-view{flex:1;min-height:0;overflow:auto;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:12px 14px;font-size:12px;color:var(--text);line-height:1.7;white-space:pre-wrap;word-break:keep-all;overflow-wrap:anywhere;cursor:text;}
|
||||
.dt-notes-view{flex:1;min-height:0;overflow:auto;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:12px 16px;font-size:12.5px;color:var(--text);line-height:1.75;word-break:keep-all;overflow-wrap:anywhere;cursor:text;}
|
||||
.dt-notes-view:hover{border-color:#3b82f6;}
|
||||
.dt-notes-view table{border-collapse:collapse;font-size:11px;margin:6px 0;white-space:normal;width:100%;table-layout:auto;}
|
||||
.dt-notes-view .nv-p{margin:0 0 8px;}
|
||||
.dt-notes-view .nv-h{font-weight:700;margin:14px 0 6px;line-height:1.4;}
|
||||
.dt-notes-view .nv-h1{font-size:16px;border-bottom:1px solid var(--line);padding-bottom:4px;}
|
||||
.dt-notes-view .nv-h2{font-size:14px;color:#3b82f6;}
|
||||
.dt-notes-view .nv-h3,.dt-notes-view .nv-h4{font-size:13px;}
|
||||
.dt-notes-view .nv-li{display:flex;gap:7px;margin-bottom:3px;}
|
||||
.dt-notes-view .nv-mk{flex:none;min-width:1.2em;text-align:right;color:var(--muted);}
|
||||
.dt-notes-view .nv-kv{margin-bottom:3px;}
|
||||
.dt-notes-view .nv-k{font-weight:700;color:var(--muted);margin-right:4px;}
|
||||
.dt-notes-view .nv-cont{display:inline-block;margin-left:1.5em;}
|
||||
.dt-notes-view .nv-q{border-left:3px solid var(--line);padding-left:10px;color:var(--muted);margin:4px 0;}
|
||||
.dt-notes-view hr{border:none;border-top:1px solid var(--line);margin:12px 0;}
|
||||
.dt-notes-view a{color:#3b82f6;}
|
||||
.dt-notes-view table{border-collapse:collapse;font-size:11.5px;margin:8px 0;width:100%;table-layout:auto;}
|
||||
.dt-notes-view th,.dt-notes-view td{border:1px solid var(--line);padding:4px 8px;text-align:left;vertical-align:top;line-height:1.55;word-break:keep-all;overflow-wrap:anywhere;}
|
||||
.dt-notes-view td:first-child{white-space:nowrap;}
|
||||
.dt-notes-view th{background:var(--panel-2);font-weight:700;}
|
||||
.dt-notes-view td:first-child{white-space:nowrap;}
|
||||
.dt-notes-view code{background:var(--panel-2);padding:0 4px;border-radius:3px;}
|
||||
.dt-notes-hint{font-size:10px;color:var(--muted);margin-left:8px;font-weight:400;}
|
||||
|
||||
@@ -377,7 +390,7 @@ body{background:var(--bg);color:var(--text);font-family:system-ui,sans-serif;dis
|
||||
- 확인된 사실: 2024년 법인 설립, 주소지 ○○동
|
||||
- 의심 정황: SNS에서 확인되지 않은 수익 주장
|
||||
- 수집 단서: 사업자등록증 번호, 전화번호 ○○○" oninput="onNotesChange()" onblur="saveCases();refreshNotesView()" onkeydown="handleNotesTab(event)"></textarea>
|
||||
<div class="dt-notes-view" id="case-notes-view" style="display:none" onclick="editNotes()" title="클릭하면 편집"></div>
|
||||
<div class="dt-notes-view" id="case-notes-view" style="display:none" onclick="editNotes(event)" title="클릭하면 편집"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -947,29 +960,76 @@ function notesTabsToMd(raw){
|
||||
}
|
||||
return out.join('\n');
|
||||
}
|
||||
// 복사해 온 글은 일정 폭에서 줄이 하드 개행돼 있어, 화면이 좁으면 둘째 줄이 짧게 남는다.
|
||||
// 보기 화면에서만: 긴 줄(45자↑) 뒤에 이어지는 일반 문장 줄은 한 줄로 이어 붙여 화면 폭에 맞게 다시 흘린다.
|
||||
function notesReflow(text){
|
||||
const lines=text.split('\n'),out=[];
|
||||
const special=l=>/^\s*(\||[-*•·▪]\s|\d+[.)]\s|\[|#|>|[가-힣A-Za-z0-9 ]{1,12}\s*:\s)/.test(l);
|
||||
for(const l of lines){
|
||||
const prev=out.length?out[out.length-1]:null;
|
||||
if(prev!==null&&prev.trim()&&l.trim()&&prev.trim().length>=45&&!special(prev)&&!special(l))out[out.length-1]=prev.replace(/\s+$/,'')+' '+l.trim();
|
||||
else out.push(l);
|
||||
// 메모 보기 화면: md 문서처럼 정리해서 보여준다(표시용일 뿐, 저장된 원문은 그대로).
|
||||
// 제목(#, [제목]), 목록(-, *, •, 1., 1), 가., (1)) 들여쓰기 단계, "항목 : 값", 인용(>), 구분선, 표(| 또는 탭),
|
||||
// 굵게/코드/링크를 처리하고, 하드 개행된 긴 문장(45자↑)은 이어 붙여 화면 폭에 맞춘다.
|
||||
function notesRender(raw){
|
||||
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="$1" target="_blank" rel="noopener">$1</a>');
|
||||
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+[.)]|\(\d+\)|[가-힣][.)])\s+(.*)$/;
|
||||
const lines=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 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;
|
||||
}else{(para=para||[]).push(html);}
|
||||
para.prevRaw=rawLine;
|
||||
};
|
||||
while(i<lines.length){
|
||||
const l=lines[i];
|
||||
if(!l.trim()){flush();i++;continue;}
|
||||
// 표
|
||||
if(/^\s*\|/.test(l)&&i+1<lines.length&&/^\s*\|?\s*:?-{2,}/.test(lines[i+1])){
|
||||
flush();let j=i;while(j<lines.length&&/^\s*\|/.test(lines[j]))j++;
|
||||
out.push(mdTables(esc(lines.slice(i,j).join('\n'))).replace(/`([^`]+)`/g,'<code>$1</code>').replace(/\*\*(.+?)\*\*/g,'<strong>$1</strong>'));
|
||||
i=j;continue;
|
||||
}
|
||||
let m;
|
||||
if(/^\s*(-{3,}|={3,}|_{3,}|─{3,})\s*$/.test(l)){flush();out.push('<hr>');i++;continue;}
|
||||
if((m=l.match(/^\s*(#{1,4})\s+(.+)$/))){flush();out.push(`<div class="nv-h nv-h${m[1].length}">${inl(esc(m[2]))}</div>`);i++;continue;}
|
||||
if((m=l.match(/^\s*\[([^\]]{1,40})\]\s*$/))){flush();out.push(`<div class="nv-h nv-h2">${esc(m[1])}</div>`);i++;continue;}
|
||||
if((m=l.match(/^\s*>\s?(.*)$/))){flush();out.push(`<div class="nv-q">${inl(esc(m[1]))}</div>`);i++;continue;}
|
||||
if((m=l.match(LI))){
|
||||
flush();const lvl=Math.min(Math.floor(indentOf(m[1])/2),6);
|
||||
let marker=m[2],body=m[3];
|
||||
if(/^[-*·▪‣◦○●■□→]$/.test(marker))marker=lvl%2?'◦':'•';
|
||||
let html=inl(esc(body)),last=l;
|
||||
// 목록 항목 바로 아래 더 깊게 들여쓴 일반 줄 = 같은 항목의 이어지는 내용
|
||||
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>`);
|
||||
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]))}`;
|
||||
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>';
|
||||
}
|
||||
out.push(`<div class="nv-kv">${html}</div>`);i++;continue;
|
||||
}
|
||||
// 일반 줄 (들여쓴 줄은 들여쓰기 유지)
|
||||
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;}
|
||||
pushText(inl(esc(l.trim())),l);i++;
|
||||
}
|
||||
return out.join('\n');
|
||||
flush();
|
||||
return out.join('');
|
||||
}
|
||||
function refreshNotesView(){
|
||||
const ta=document.getElementById('case-notes'),view=document.getElementById('case-notes-view');
|
||||
if(!ta||!view)return;
|
||||
const raw0=ta.value||'';
|
||||
if(!raw0.trim()||document.activeElement===ta){view.style.display='none';ta.style.display='';return;}
|
||||
const raw=notesReflow(notesTabsToMd(raw0));
|
||||
const esc=raw.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
view.innerHTML=mdTables(esc).replace(/`([^`]+)`/g,'<code>$1</code>').replace(/\*\*(.+?)\*\*/g,'<strong>$1</strong>').replace(/(<\/table><\/div>)\n/g,'$1');
|
||||
view.innerHTML=notesRender(raw0);
|
||||
ta.style.display='none';view.style.display='';
|
||||
}
|
||||
function editNotes(){
|
||||
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');
|
||||
if(window.getSelection&&String(window.getSelection()))return; // 드래그 선택(복사) 중이면 편집 전환 안 함
|
||||
view.style.display='none';ta.style.display='';ta.focus();
|
||||
|
||||
Reference in new issue
Block a user