Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.
Merged

fx #278

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 18 additions & 35 deletions src/app/_common/components/chatParser/ChatParserCite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,28 @@ export const processInlineMarkdownWithCitations = (

// Citation을 찾기 위한 더 안전한 접근법 - 단순화
const findCitations = (inputText: string): Array<{ start: number, end: number, content: string }> => {

// LaTeX가 포함된 텍스트에서는 Citation 전처리를 최소화
let preprocessedText = inputText;

// LaTeX 영역이 아닌 곳에서만 전처리 수행
if (!hasLatex(inputText)) {
// 이중 중괄호를 단일 중괄호로 변환
preprocessedText = preprocessedText.replace(/\{\{/g, '{').replace(/\}\}/g, '}');
// }}}] 같은 패턴을 }}] 로 정리
preprocessedText = preprocessedText.replace(/\}\}\}/g, '}}');
// 숫자 필드 뒤의 잘못된 따옴표 제거
preprocessedText = preprocessedText.replace(/(\d)"\s*([,}])/g, '$1$2');
// 문자열 필드에서 중복 따옴표 정리
preprocessedText = preprocessedText.replace(/"""([^"]*?)"/g, '"$1"'); // 3개 따옴표 -> 1개
preprocessedText = preprocessedText.replace(/""([^"]*?)"/g, '"$1"'); // 2개 따옴표 -> 1개
}

const citations: Array<{ start: number, end: number, content: string }> = [];
let i = 0;
let searchIndex = 0;

while (i < preprocessedText.length) {
while (searchIndex < inputText.length) {
// [Cite. 패턴 찾기
const citeStart = preprocessedText.indexOf('[Cite.', i);
const citeStart = inputText.indexOf('[Cite.', searchIndex);
if (citeStart === -1) break;

// { 또는 {{ 찾기
let braceStart = -1;
for (let j = citeStart + 6; j < preprocessedText.length; j++) {
if (preprocessedText[j] === '{') {
for (let j = citeStart + 6; j < inputText.length; j++) {
if (inputText[j] === '{') {
braceStart = j;
break;
} else if (preprocessedText[j] !== ' ' && preprocessedText[j] !== '\t') {
} else if (inputText[j] !== ' ' && inputText[j] !== '\t') {
// 공백이 아닌 다른 문자가 나오면 유효하지 않은 citation
break;
}
}

if (braceStart === -1) {
i = citeStart + 6;
searchIndex = citeStart + 6;
continue;
}

Expand All @@ -107,8 +90,8 @@ export const processInlineMarkdownWithCitations = (
let inString = false;
let escaped = false;

for (let j = braceStart + 1; j < preprocessedText.length; j++) {
const char = preprocessedText[j];
for (let j = braceStart + 1; j < inputText.length; j++) {
const char = inputText[j];

// 이전 문자가 백슬래시인 경우 현재 문자는 이스케이프됨
if (escaped) {
Expand Down Expand Up @@ -145,33 +128,33 @@ export const processInlineMarkdownWithCitations = (
if (braceEnd !== -1) {
// 닫는 ] 찾기 (선택적) - 백슬래시는 텍스트 끝까지 포함
let finalEnd = braceEnd + 1;
while (finalEnd < preprocessedText.length &&
(preprocessedText[finalEnd] === ' ' || preprocessedText[finalEnd] === '\t' ||
preprocessedText[finalEnd] === ']' || preprocessedText[finalEnd] === '.' ||
preprocessedText[finalEnd] === '\\')) {
if (preprocessedText[finalEnd] === ']') {
while (finalEnd < inputText.length &&
(inputText[finalEnd] === ' ' || inputText[finalEnd] === '\t' ||
inputText[finalEnd] === ']' || inputText[finalEnd] === '.' ||
inputText[finalEnd] === '\\')) {
if (inputText[finalEnd] === ']') {
finalEnd++;
break;
}
finalEnd++;
}

// 텍스트 끝에 백슬래시가 있는 경우 포함
if (finalEnd === preprocessedText.length && preprocessedText.endsWith('\\')) {
if (finalEnd === inputText.length && inputText.endsWith('\\')) {
// 백슬래시까지 포함
}

const citationContent = preprocessedText.slice(citeStart, finalEnd);
const citationContent = inputText.slice(citeStart, finalEnd);

citations.push({
start: citeStart,
end: finalEnd,
content: citationContent
});

i = finalEnd;
searchIndex = finalEnd;
} else {
i = citeStart + 6;
searchIndex = citeStart + 6;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Container
.container {
margin: 0 auto;
width: 100%;
}

// Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,8 @@ const DocumentDetailSection: React.FC<DocumentDetailSectionProps> = ({
</div>
) : (
<button
onClick={() => {
if (!needsRemake) {
handleEditClick(chunk.chunk_id, chunk.chunk_text || '');
}
}}
disabled={needsRemake}
className={`${styles.button} ${styles.edit} ${needsRemake ? styles.disabled : ''}`}
data-tooltip={needsRemake ? '컬렉션 임베딩이 일치하지 않아 Remake를 먼저 수행해야 합니다.' : ''}
style={{
cursor: needsRemake ? 'not-allowed' : 'pointer',
opacity: needsRemake ? 0.6 : 1
}}
onClick={() => handleEditClick(chunk.chunk_id, chunk.chunk_text || '')}
className={`${styles.button} ${styles.edit}`}
>
업데이트
</button>
Expand Down