diff --git a/backend/app.py b/backend/app.py index 4266a04..ed3fa26 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6691,14 +6691,22 @@ def api_animal_drug_info_preview(): except Exception as e: return jsonify({'success': False, 'error': f'DB 오류: {str(e)}'}), 500 - # HTML 태그 제거 + # HTML 태그 제거 (표 형식은 줄바꿈 유지) def strip_html(html_text): if not html_text: return '' - text = re.sub(r'<[^>]+>', '', html_text) + #
, → 줄바꿈 + text = re.sub(r'
|', '\n', html_text) + text = re.sub(r'<[^>]+>', '', text) text = unescape(text) - text = re.sub(r'\s+', ' ', text).strip() - return text + + # 표 형식 감지 + if '─' in text or '━' in text: + lines = [l.strip() for l in text.split('\n') if l.strip()] + return '\n'.join(lines) + else: + text = re.sub(r'\s+', ' ', text).strip() + return text # 항목별 줄바꿈 처리 (가. 나. 다. 라. / 1) 2) 3) 등) def format_items(text): @@ -6710,6 +6718,53 @@ def api_animal_drug_info_preview(): text = re.sub(r'\s+(\d+)\)\s*', r'\n \1) ', text) return text.strip() + # 표 형식을 HTML 테이블로 변환 + def format_table_html(text): + if not text: + return '' + + # 표가 없으면 일반 처리 + if '─' not in text and '━' not in text: + return format_items(text) + + # 표 형식: 체중별 투여량 테이블 생성 + lines = [l.strip() for l in text.split('\n') if l.strip() and '─' not in l and '━' not in l] + + # 체중 행과 투여정수 행 찾기 + header_line = None + data_line = None + other_lines = [] + + for line in lines: + if '체중' in line and 'kg' in line.lower(): + header_line = line + elif '투여' in line and '정수' in line: + data_line = line + else: + other_lines.append(line) + + result = '\n'.join(other_lines) + + # HTML 테이블 생성 + if header_line and data_line: + headers = re.split(r'\s{2,}', header_line) + values = re.split(r'\s{2,}', data_line) + + html = '| {h} | ' + html += '
|---|
| {v} | ' + html += '
${escapeHtml(info.dosage_instructions)}
+