diff --git a/backend/app.py b/backend/app.py index df42722..47dd420 100644 --- a/backend/app.py +++ b/backend/app.py @@ -6472,13 +6472,27 @@ def api_animal_drug_info_print(): def strip_html(html_text): if not html_text: return '' - # HTML 태그 제거 - text = re.sub(r'<[^>]+>', '', html_text) + # HTML 태그 제거 (줄바꿈 보존) + #

,
, 등을 줄바꿈으로 변환 + text = re.sub(r'

||', '\n', html_text) + text = re.sub(r'<[^>]+>', '', text) # HTML 엔티티 변환 text = unescape(text) - # 연속 공백/줄바꿈 정리 - text = re.sub(r'\s+', ' ', text).strip() - return text + + # 표 형식 감지 (─ 문자 포함) + if '─' in text or '━' in text: + # 표 형식: 각 줄의 앞뒤 공백만 정리, 줄 내 공백은 유지 + lines = text.split('\n') + cleaned = [] + for line in lines: + line = line.strip() + if line: + cleaned.append(line) + return '\n'.join(cleaned) + else: + # 일반 텍스트: 연속 공백/줄바꿈 정리 + text = re.sub(r'\s+', ' ', text).strip() + return text # 항목별 줄바꿈 처리 (가. 나. 다. 라. / 1) 2) 3) 등) def format_for_print(text): @@ -6554,10 +6568,18 @@ def api_animal_drug_info_print(): {THIN} ▶ 용법용량 """ - formatted_dosage = format_for_print(dosage[:500]) - for para in formatted_dosage.split('\n'): - for line in wrap_text(para.strip(), 44): - message += f" {line}\n" + # 표 형식 감지 (─ 문자 포함) + if '─' in dosage or '━' in dosage: + # 표 형식: 줄바꿈 유지, 공백 유지 + for line in dosage.split('\n'): + line = line.strip() + if line: + message += f"{line}\n" + else: + formatted_dosage = format_for_print(dosage[:500]) + for para in formatted_dosage.split('\n'): + for line in wrap_text(para.strip(), 44): + message += f" {line}\n" if precautions: message += f"""