feat: 투약지도서 표 형식 출력 지원
- 체중/투여정수 표(─ 문자 포함) 감지 - 표 형식일 때 공백/정렬 유지 - 안텔민 킹정 등 체중별 투여량 표 정상 출력
This commit is contained in:
parent
a89dc9b354
commit
5a2ab044ba
@ -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 태그 제거 (줄바꿈 보존)
|
||||
# <p>, <br>, </div> 등을 줄바꿈으로 변환
|
||||
text = re.sub(r'</p>|<br\s*/?>|</div>', '\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"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user