v6:HWPX 템플릿 분석·저장·관리_20260128
This commit is contained in:
@@ -34,23 +34,21 @@ def is_long_document(html_content: str) -> bool:
|
||||
|
||||
def convert_image_paths(html_content: str) -> str:
|
||||
"""
|
||||
HTML 내 상대 이미지 경로를 서버 경로로 변환
|
||||
assets/xxx.png → /assets/xxx.png
|
||||
HTML 내 이미지 경로를 서버 경로로 변환
|
||||
- assets/xxx.png → /assets/xxx.png (Flask 서빙용)
|
||||
- 절대 경로나 URL은 그대로 유지
|
||||
"""
|
||||
result = re.sub(r'src="assets/', 'src="/assets/', html_content)
|
||||
return result
|
||||
|
||||
def replace_src(match):
|
||||
original_path = match.group(1)
|
||||
|
||||
# 이미 절대 경로이거나 URL이면 그대로
|
||||
if original_path.startswith(('http://', 'https://', 'file://', 'D:', 'C:')):
|
||||
if original_path.startswith(('http://', 'https://', 'file://', 'D:', 'C:', '/')):
|
||||
return match.group(0)
|
||||
|
||||
# assets/로 시작하면 절대 경로로 변환
|
||||
# assets/로 시작하면 /assets/로 변환 (Flask 서빙)
|
||||
if original_path.startswith('assets/'):
|
||||
filename = original_path.replace('assets/', '')
|
||||
absolute_path = os.path.join(ASSETS_BASE_PATH, filename)
|
||||
return f'src="{absolute_path}"'
|
||||
return f'src="/{original_path}"'
|
||||
|
||||
return match.group(0)
|
||||
|
||||
@@ -80,6 +78,29 @@ def run_short_pipeline(html_content: str, options: dict) -> Dict[str, Any]:
|
||||
'pipeline': 'short'
|
||||
}
|
||||
|
||||
def inject_template_css(html_content: str, template_css: str) -> str:
|
||||
"""
|
||||
HTML에 템플릿 CSS 주입
|
||||
- <style> 태그가 있으면 그 안에 추가
|
||||
- 없으면 <head>에 새로 생성
|
||||
"""
|
||||
if not template_css:
|
||||
return html_content
|
||||
|
||||
css_block = f"\n/* ===== 템플릿 스타일 ===== */\n{template_css}\n"
|
||||
|
||||
# 기존 </style> 태그 앞에 추가
|
||||
if '</style>' in html_content:
|
||||
return html_content.replace('</style>', f'{css_block}</style>', 1)
|
||||
|
||||
# <head> 태그 뒤에 새로 추가
|
||||
elif '<head>' in html_content:
|
||||
return html_content.replace('<head>', f'<head>\n<style>{css_block}</style>', 1)
|
||||
|
||||
# head도 없으면 맨 앞에 추가
|
||||
else:
|
||||
return f'<style>{css_block}</style>\n{html_content}'
|
||||
|
||||
|
||||
def run_long_pipeline(html_content: str, options: dict) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -136,4 +157,9 @@ def process_document(content: str, options: dict = None) -> Dict[str, Any]:
|
||||
result['char_count'] = char_count
|
||||
result['threshold'] = LONG_DOC_THRESHOLD
|
||||
|
||||
# ⭐ 템플릿 CSS 주입
|
||||
template_css = options.get('template_css')
|
||||
if template_css and result.get('success') and result.get('html'):
|
||||
result['html'] = inject_template_css(result['html'], template_css)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user