img test
Some checks failed
build_docker / essential (pull_request) Has been cancelled
build_docker / build_cpu (pull_request) Has been cancelled
build_docker / build_gpu (pull_request) Has been cancelled
build_docker / build_easyocr (pull_request) Has been cancelled
build_docker / build_easyocr_gpu (pull_request) Has been cancelled
build_docker / build_doctr (pull_request) Has been cancelled
build_docker / build_doctr_gpu (pull_request) Has been cancelled
build_docker / build_raytune (pull_request) Has been cancelled
Some checks failed
build_docker / essential (pull_request) Has been cancelled
build_docker / build_cpu (pull_request) Has been cancelled
build_docker / build_gpu (pull_request) Has been cancelled
build_docker / build_easyocr (pull_request) Has been cancelled
build_docker / build_easyocr_gpu (pull_request) Has been cancelled
build_docker / build_doctr (pull_request) Has been cancelled
build_docker / build_doctr_gpu (pull_request) Has been cancelled
build_docker / build_raytune (pull_request) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ import os
|
||||
import shutil
|
||||
from bs4 import BeautifulSoup, NavigableString
|
||||
from latex2mathml.converter import convert as latex_to_mathml
|
||||
from PIL import Image
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
TEMPLATE_INPUT = os.path.join(BASE_DIR, 'instructions/plantilla_individual.htm')
|
||||
@@ -144,8 +145,24 @@ def parse_md_to_html_blocks(md_content):
|
||||
html_blocks.append(f'''<a name="{bookmark_id}"></a><p class=MsoCaption style="text-align:center"><b><span lang=ES style="font-size:12.0pt;line-height:150%">Figura <!--[if supportFields]><span style='mso-element:field-begin'></span> SEQ Figura \\* ARABIC <span style='mso-element:field-separator'></span><![endif]-->{figure_counter}<!--[if supportFields]><span style='mso-element:field-end'></span><![endif]-->.</span></b><span lang=ES style="font-size:12.0pt;line-height:150%"> </span><i><span lang=ES style="font-size:12.0pt;line-height:150%">{fig_title}</span></i></p>''')
|
||||
|
||||
if os.path.exists(fig_path):
|
||||
# Use Word-compatible width in cm (A4 text area is ~16cm wide, use ~12cm max)
|
||||
html_blocks.append(f'''<p class=MsoNormal style="text-align:center"><span lang=ES><img width="566" style="width:425.2pt;display:block;margin:0 auto" src="{fig_file}" alt="{fig_title}"/></span></p>''')
|
||||
# Read actual image dimensions and scale to fit page width
|
||||
img = Image.open(fig_path)
|
||||
orig_w, orig_h = img.size
|
||||
|
||||
# Scale to fit max width of 566px (15cm at 96dpi) while preserving aspect ratio
|
||||
max_width = 566
|
||||
if orig_w > max_width:
|
||||
scale = max_width / orig_w
|
||||
new_w = max_width
|
||||
new_h = int(orig_h * scale)
|
||||
else:
|
||||
new_w, new_h = orig_w, orig_h
|
||||
|
||||
# Convert to pt (1px at 96dpi = 0.75pt)
|
||||
w_pt = new_w * 0.75
|
||||
h_pt = new_h * 0.75
|
||||
|
||||
html_blocks.append(f'''<p class=MsoNormal style="text-align:center"><span lang=ES><img width="{new_w}" height="{new_h}" style="width:{w_pt}pt;height:{h_pt}pt;display:block;margin:0 auto" src="{fig_file}" alt="{fig_title}"/></span></p>''')
|
||||
else:
|
||||
# Fallback to placeholder
|
||||
html_blocks.append(f'''<p class=MsoNormal style="text-align:center;border:1px dashed #999;padding:20px;margin:10px 40px;background:#f9f9f9"><span lang=ES style="color:#666">[Insertar diagrama Mermaid aquí]</span></p>''')
|
||||
|
||||
Reference in New Issue
Block a user