diff --git a/web-ui/html/accountant-app.html b/web-ui/html/accountant-app.html index 3f124b6..1179ccb 100644 --- a/web-ui/html/accountant-app.html +++ b/web-ui/html/accountant-app.html @@ -450,26 +450,36 @@ function renderMd(text){ .replace(/\*\*(.+?)\*\*/g,'$1') .replace(/\*(.+?)\*/g,'$1') .replace(/^#{1,3}\s+(.+)$/gm,'

$1

') - .replace(/^\|(.+)\|$/gm,row=>{ - const cells=row.slice(1,-1).split('|').map(c=>`${c.trim()}`).join(''); - return `${cells}`; - }) - .replace(/(.*?<\/tr>)/gs, tbl=>{ - const rows=tbl.match(/.*?<\/tr>/gs)||[]; - if(!rows.length)return tbl; - const header=rows[0].replace(//g,'').replace(/<\/td>/g,''); - const body=rows.slice(2).join(''); - return `${header}${body}
`; - }) + .split(/(
[\s\S]*?<\/pre>)/).map((seg,i)=>i%2?seg:mdTables(seg)).join('')
     .replace(/^-{3,}$/gm,'
') .replace(/\n\n/g,'

').replace(/^/,'

').replace(/$/,'

') .replace(/

<\/p>/g,'') .replace(/

(

)/g,'$1').replace(/(<\/h3>)<\/p>/g,'$1') .replace(/

(

)/g,'$1').replace(/(<\/pre>)<\/p>/g,'$1')
-    .replace(/

()/g,'$1').replace(/(<\/table>)<\/p>/g,'$1') + .replace(/

(

)/g,'$1').replace(/(<\/table><\/div>)<\/p>/g,'$1') .replace(/

(


)/g,'$1').replace(/(
)<\/p>/g,'$1'); } +// 마크다운 표: '|'로 시작하는 연속 줄 + 두 번째 줄이 구분선(|---|---|)인 블록만
로 바꾼다. +// 입력은 이미 HTML 이스케이프된 상태. 셀 안의 `코드`·**굵게**는 이후 인라인 변환이 처리한다. +function mdTables(text){ + const cells=l=>l.trim().replace(/^\|/,'').replace(/\|$/,'').split('|').map(c=>c.trim()); + const isSep=l=>/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(l)&&l.includes('-')&&/\|/.test(l); + const lines=text.split('\n'),out=[]; + for(let i=0;i/^:-+:$/.test(c)?'center':/-:$/.test(c)?'right':''); + let j=i+2;const rows=[]; + while(j`<${t}${al[k]?` style="text-align:${al[k]}"`:''}>${c}`; + out.push('
'+head.map((c,k)=>td('th',c,k)).join('')+''+ + rows.map(r=>''+head.map((_,k)=>td('td',r[k]??'',k)).join('')+'').join('')+'
'); + i=j; + }else out.push(lines[i++]); + } + return out.join('\n'); +} + async function sendMessage(){ const input=document.getElementById('chat-input'); const msg=input.value.trim(); diff --git a/web-ui/html/investor-app.html b/web-ui/html/investor-app.html index cdd8445..4f3562f 100644 --- a/web-ui/html/investor-app.html +++ b/web-ui/html/investor-app.html @@ -705,31 +705,8 @@ function addMsg(role,html){ return b; } -function renderMd(text){ - // First extract chart blocks to replace with links - let out=text; - // Replace kstock blocks with a clickable chip - out=out.replace(/```kstock\s*\n([^`]+)\n```/g,(m,body)=>{ - const parts=body.trim().split('|');const code=parts[0].trim().replace(/\D/g,'');const period=(parts[1]||'day').trim(); - if(!code)return m; - return `📈 ${code} ${period} 차트 보기`; - }); - // Replace tradingview blocks with a clickable chip - out=out.replace(/```tradingview\s*\n([^`]+)\n```/g,(m,body)=>{ - const parts=body.trim().split('|');const sym=parts[0].trim().toUpperCase();const iv=(parts[1]||'D').trim(); - if(!sym)return m; - return `📈 ${sym} 차트 보기`; - }); - return out - .replace(/&/g,'&').replace(//g,'>') - // restore already-HTML chart links before further escaping - .replace(/<span class="iv-chart-link"([^&]*)>(.*?)<\/span>/g,(m)=>{ - // this won't work — need to do escaping AFTER substitution - return m; - }) - // Actually process differently below - ; -} +// 대화 기록 복원용 — 실시간 응답과 같은 렌더러를 쓴다(예전 구현은 이스케이프만 하고 끝나 마크다운이 안 먹었다). +function renderMd(text){ return renderMdSafe(text); } function renderMdSafe(text){ // Do chart block substitution BEFORE HTML escaping @@ -753,6 +730,7 @@ function renderMdSafe(text){ out=out .replace(/&/g,'&').replace(//g,'>') .replace(/```[\w]*\n?([\s\S]*?)```/g,'

$1
') + .split(/(
[\s\S]*?<\/pre>)/).map((seg,i)=>i%2?seg:mdTables(seg)).join('')
     .replace(/`([^`]+)`/g,'$1')
     .replace(/\*\*(.+?)\*\*/g,'$1')
     .replace(/\*(.+?)\*/g,'$1')
@@ -762,12 +740,33 @@ function renderMdSafe(text){
     .replace(/\n\n/g,'

').replace(/^/,'

').replace(/$/,'

') .replace(/

<\/p>/g,'').replace(/

(

)/g,'$1').replace(/(<\/h3>)<\/p>/g,'$1') .replace(/

(

)/g,'$1').replace(/(<\/pre>)<\/p>/g,'$1')
-    .replace(/

(

    )/g,'$1').replace(/(<\/ul>)<\/p>/g,'$1'); + .replace(/

    (

      )/g,'$1').replace(/(<\/ul>)<\/p>/g,'$1') + .replace(/

      (

      )/g,'$1').replace(/(<\/table><\/div>)<\/p>/g,'$1'); // Restore chart placeholders charts.forEach((html,i)=>{out=out.replace(new RegExp(`\x00CHART${i}\x00`,'g'),html);}); return out; } +// 마크다운 표: '|'로 시작하는 연속 줄 + 두 번째 줄이 구분선(|---|---|)인 블록만 로 바꾼다. +// 입력은 이미 HTML 이스케이프된 상태. 셀 안의 `코드`·**굵게**는 이후 인라인 변환이 처리한다. +function mdTables(text){ + const cells=l=>l.trim().replace(/^\|/,'').replace(/\|$/,'').split('|').map(c=>c.trim()); + const isSep=l=>/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(l)&&l.includes('-')&&/\|/.test(l); + const lines=text.split('\n'),out=[]; + for(let i=0;i/^:-+:$/.test(c)?'center':/-:$/.test(c)?'right':''); + let j=i+2;const rows=[]; + while(j`<${t}${al[k]?` style="text-align:${al[k]}"`:''}>${c}`; + out.push('
      '+head.map((c,k)=>td('th',c,k)).join('')+''+ + rows.map(r=>''+head.map((_,k)=>td('td',r[k]??'',k)).join('')+'').join('')+'
      '); + i=j; + }else out.push(lines[i++]); + } + return out.join('\n'); +} + async function sendMessage(){ const input=document.getElementById('chat-input'); const msg=input.value.trim(); diff --git a/web-ui/html/mind-app.html b/web-ui/html/mind-app.html index e7cd334..b193665 100644 --- a/web-ui/html/mind-app.html +++ b/web-ui/html/mind-app.html @@ -1231,6 +1231,7 @@ function renderMd(text){ return text .replace(/&/g,'&').replace(//g,'>') .replace(/```[\w]*\n?([\s\S]*?)```/g,'
      $1
      ') + .split(/(
      [\s\S]*?<\/pre>)/).map((seg,i)=>i%2?seg:mdTables(seg)).join('')
           .replace(/`([^`]+)`/g,'$1')
           .replace(/\*\*(.+?)\*\*/g,'$1')
           .replace(/\*(.+?)\*/g,'$1')
      @@ -1239,7 +1240,28 @@ function renderMd(text){
           .replace(/\n\n/g,'

      ').replace(/^/,'

      ').replace(/$/,'

      ') .replace(/

      <\/p>/g,'').replace(/

      (

      )/g,'$1').replace(/(<\/h3>)<\/p>/g,'$1') .replace(/

      (

      )/g,'$1').replace(/(<\/pre>)<\/p>/g,'$1')
      -    .replace(/

      ()<\/p>/g,'$1'); + .replace(/

      ()<\/p>/g,'$1') + .replace(/

      (

      )/g,'$1').replace(/(<\/table><\/div>)<\/p>/g,'$1'); +} + +// 마크다운 표: '|'로 시작하는 연속 줄 + 두 번째 줄이 구분선(|---|---|)인 블록만 로 바꾼다. +// 입력은 이미 HTML 이스케이프된 상태. 셀 안의 `코드`·**굵게**는 이후 인라인 변환이 처리한다. +function mdTables(text){ + const cells=l=>l.trim().replace(/^\|/,'').replace(/\|$/,'').split('|').map(c=>c.trim()); + const isSep=l=>/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(l)&&l.includes('-')&&/\|/.test(l); + const lines=text.split('\n'),out=[]; + for(let i=0;i/^:-+:$/.test(c)?'center':/-:$/.test(c)?'right':''); + let j=i+2;const rows=[]; + while(j`<${t}${al[k]?` style="text-align:${al[k]}"`:''}>${c}`; + out.push('
      '+head.map((c,k)=>td('th',c,k)).join('')+''+ + rows.map(r=>''+head.map((_,k)=>td('td',r[k]??'',k)).join('')+'').join('')+'
      '); + i=j; + }else out.push(lines[i++]); + } + return out.join('\n'); } function sendToChat(message,statusMsg){