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 = '' + html += '' + for h in headers: + html += f'' + html += '' + html += '' + for v in values: + html += f'' + html += '' + html += '
{h}
{v}
' + + result = result + '\n' + html if result else html + + return result + # 투약주기 조합 dosing_interval = None if row.dosing_interval_adult: @@ -6728,7 +6783,8 @@ def api_animal_drug_info_preview(): 'company_name': row.company_name, 'main_ingredient': row.main_ingredient if row.main_ingredient != 'NaN' else None, 'efficacy_effect': format_items(strip_html(row.efficacy_effect)), - 'dosage_instructions': format_items(strip_html(row.dosage_instructions)), + 'dosage_instructions': format_table_html(strip_html(row.dosage_instructions)), + 'dosage_has_table': '─' in (row.dosage_instructions or ''), 'precautions': format_items(strip_html(row.precautions)), # 성분 가이드 (component_guide JOIN) 'component_code': row.component_code, diff --git a/backend/templates/admin_products.html b/backend/templates/admin_products.html index 73b11eb..b405240 100644 --- a/backend/templates/admin_products.html +++ b/backend/templates/admin_products.html @@ -1156,7 +1156,7 @@ ${info.dosage_instructions ? `
▶ 용법용량
-

${escapeHtml(info.dosage_instructions)}

+
${info.dosage_has_table ? info.dosage_instructions : escapeHtml(info.dosage_instructions)}
` : ''} ${info.dosing_interval ? `