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:19:27 +09:00
1 parent 98ac206e1f
commit b0557c77a0
1 file changed
+29 -3
+29 -3
View File
@@ -966,10 +966,36 @@ function notesTabsToMd(raw){
function notesRender(raw){
const esc=t=>t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
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>');
.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 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 LI=/^(\s*)([-*•·▪‣◦○●■□→]|\d{1,2}[.)]|\(\d{1,2}\)|[가-힣][.)])\s+(.*)$/;
// 한 줄로 뭉쳐 붙여넣은 번호 목록("1. … 2. … 3. …")을 항목별로 나누고, "항목: - 내용"은 하위 항목으로 내린다.
// 번호가 1,2,3처럼 이어질 때만 나눠서 날짜(2026. 3. 5.) 같은 건 건드리지 않는다.
const expand=arr=>{
const merged=[];
for(let k=0;k<arr.length;k++){
if(/^\s*\d{1,2}[.)]\s*$/.test(arr[k])&&k+1<arr.length&&arr[k+1].trim()){merged.push(arr[k].trim()+' '+arr[k+1].trim());k++;}
else merged.push(arr[k]);
}
const res=[];
for(const ln of merged){
const re=/(^|\s)(\d{1,2})[.)]\s+(?=[가-힣A-Za-z(\[])/g,hits=[];let mm;
while((mm=re.exec(ln)))hits.push({n:+mm[2],at:mm.index+mm[1].length});
let seq=[];
for(const h of hits){if(!seq.length){if(h.n===1)seq.push(h);}else if(h.n===seq[seq.length-1].n+1)seq.push(h);}
if(seq.length<2){res.push(ln);continue;}
if(seq[0].at>0&&ln.slice(0,seq[0].at).trim())res.push(ln.slice(0,seq[0].at).trim());
seq.forEach((h,k)=>{
const piece=ln.slice(h.at,k+1<seq.length?seq[k+1].at:undefined).trim();
const parts=piece.split(/:\s+-\s+/);
if(parts.length>1){res.push(parts[0]+':');for(const sub of parts.slice(1))res.push(' - '+sub.trim());}
else res.push(piece);
});
}
return res;
};
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 pushText=(html,rawLine)=>{