feat: 투약지도서 표 형식 출력 지원

- 체중/투여정수 표(─ 문자 포함) 감지
- 표 형식일 때 공백/정렬 유지
- 안텔민 킹정 등 체중별 투여량 표 정상 출력
This commit is contained in:
thug0bin 2026-03-04 19:58:15 +09:00
parent a89dc9b354
commit 5a2ab044ba

View File

@ -6472,11 +6472,25 @@ def api_animal_drug_info_print():
def strip_html(html_text): def strip_html(html_text):
if not html_text: if not html_text:
return '' return ''
# HTML 태그 제거 # HTML 태그 제거 (줄바꿈 보존)
text = re.sub(r'<[^>]+>', '', html_text) # <p>, <br>, </div> 등을 줄바꿈으로 변환
text = re.sub(r'</p>|<br\s*/?>|</div>', '\n', html_text)
text = re.sub(r'<[^>]+>', '', text)
# HTML 엔티티 변환 # HTML 엔티티 변환
text = unescape(text) text = unescape(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() text = re.sub(r'\s+', ' ', text).strip()
return text return text
@ -6554,6 +6568,14 @@ def api_animal_drug_info_print():
{THIN} {THIN}
용법용량 용법용량
""" """
# 표 형식 감지 (─ 문자 포함)
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]) formatted_dosage = format_for_print(dosage[:500])
for para in formatted_dosage.split('\n'): for para in formatted_dosage.split('\n'):
for line in wrap_text(para.strip(), 44): for line in wrap_text(para.strip(), 44):