generation test

This commit is contained in:
2025-12-16 00:25:16 +01:00
parent 8a587e4620
commit 34a1cb4766
8 changed files with 54 additions and 54 deletions

View File

@@ -32,7 +32,7 @@ def md_to_html_para(text):
# Italic
text = re.sub(r'\*([^*]+)\*', r'<i>\1</i>', text)
# Inline code
text = re.sub(r'`([^`]+)`', r'<span style="font-family:Consolas;font-size:10pt;background:#f5f5f5">\1</span>', text)
text = re.sub(r'`([^`]+)`', r'<span style="font-family:Consolas;font-size:10pt">\1</span>', text)
return text
def extract_table_title(lines, current_index):
@@ -104,9 +104,10 @@ def parse_md_to_html_blocks(md_content):
fig_file = f'figures/figura_{figure_counter}.png'
fig_path = os.path.join(BASE_DIR, 'thesis_output', fig_file)
# Create figure with MsoCaption class and bookmark for Word cross-reference
# Create figure with MsoCaption class and proper Word SEQ field for cross-reference
# Format: "Figura X." in bold, title in italic (per UNIR guidelines)
bookmark_id = f"_TocFigura{figure_counter}"
html_blocks.append(f'''<p class=MsoCaption style="text-align:center"><a name="{bookmark_id}"><span lang=ES style="font-size:12.0pt;line-height:150%">Figura {figure_counter}. </span></a><i><span lang=ES style="font-size:12.0pt;line-height:150%;font-weight:normal">{fig_title}</span></i></p>''')
html_blocks.append(f'''<p class=MsoCaption style="text-align:center"><a name="{bookmark_id}"><b><span lang=ES style="font-size:12.0pt;line-height:150%">Figura </span></b></a><!--[if supportFields]><span style='mso-element:field-begin'></span> SEQ Figura \\* ARABIC <span style='mso-element:field-separator'></span><![endif]--><b><span lang=ES style="font-size:12.0pt;line-height:150%">{figure_counter}</span></b><!--[if supportFields]><span style='mso-element:field-end'></span><![endif]--><b><span lang=ES style="font-size:12.0pt;line-height:150%">.</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%;font-weight:normal">{fig_title}</span></i></p>''')
if os.path.exists(fig_path):
# Use actual image with proper Word-compatible format (max 400px width, 500px height to fit page)
@@ -131,7 +132,7 @@ def parse_md_to_html_blocks(md_content):
code = '\n'.join(code_lines)
# Escape HTML entities in code
code = code.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
html_blocks.append(f'<p class=MsoNormal style="margin-left:1cm;background:#F5F5F5;padding:10px"><span style="font-family:Consolas;font-size:9pt"><pre>{code}</pre></span></p>')
html_blocks.append(f'<p class=MsoNormal style="margin-left:1cm"><span style="font-family:Consolas;font-size:9pt"><pre>{code}</pre></span></p>')
i += 1
continue
@@ -186,25 +187,30 @@ def parse_md_to_html_blocks(md_content):
table_source = lines[i].replace('*', '').replace('Fuente:', '').strip()
i += 1
# Add table title with MsoCaption class and bookmark for Word cross-reference
# Add table title with MsoCaption class and proper Word SEQ field for cross-reference
# Format: "Tabla X." in bold, title in italic (per UNIR guidelines)
bookmark_id = f"_TocTabla{table_counter}"
if table_title:
clean_title = table_title.replace(f"Tabla {table_counter}.", "").strip()
html_blocks.append(f'<p class=MsoCaption><a name="{bookmark_id}"><span lang=ES style="font-size:12.0pt;line-height:150%">Tabla {table_counter}. </span></a><i><span lang=ES style="font-size:12.0pt;line-height:150%;font-weight:normal">{clean_title}</span></i></p>')
else:
html_blocks.append(f'<p class=MsoCaption><a name="{bookmark_id}"><span lang=ES style="font-size:12.0pt;line-height:150%">Tabla {table_counter}. </span></a><i><span lang=ES style="font-size:12.0pt;line-height:150%;font-weight:normal">Tabla de datos.</span></i></p>')
clean_title = "Tabla de datos."
html_blocks.append(f'''<p class=MsoCaption><a name="{bookmark_id}"><b><span lang=ES style="font-size:12.0pt;line-height:150%">Tabla </span></b></a><!--[if supportFields]><span style='mso-element:field-begin'></span> SEQ Tabla \\* ARABIC <span style='mso-element:field-separator'></span><![endif]--><b><span lang=ES style="font-size:12.0pt;line-height:150%">{table_counter}</span></b><!--[if supportFields]><span style='mso-element:field-end'></span><![endif]--><b><span lang=ES style="font-size:12.0pt;line-height:150%">.</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%;font-weight:normal">{clean_title}</span></i></p>''')
# Build table HTML
table_html = '<table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt">'
# Build table HTML with APA style (horizontal lines only, no vertical)
table_html = '<table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0 style="border-collapse:collapse;border:none">'
for j, tline in enumerate(table_lines):
cells = [c.strip() for c in tline.split('|')[1:-1]]
table_html += '<tr>'
for cell in cells:
if j == 0:
# Header row
table_html += f'<td style="border:solid windowtext 1.0pt;padding:5px;background:#F0F0F0"><p class=MsoNormal style="margin:0"><b><span lang=ES>{md_to_html_para(cell)}</span></b></p></td>'
# Header row: top and bottom border, bold text
table_html += f'<td style="border-top:solid windowtext 1.0pt;border-bottom:solid windowtext 1.0pt;border-left:none;border-right:none;padding:5px"><p class=MsoNormal style="margin:0"><b><span lang=ES>{md_to_html_para(cell)}</span></b></p></td>'
elif j == len(table_lines) - 1:
# Last row: bottom border only
table_html += f'<td style="border-top:none;border-bottom:solid windowtext 1.0pt;border-left:none;border-right:none;padding:5px"><p class=MsoNormal style="margin:0"><span lang=ES>{md_to_html_para(cell)}</span></p></td>'
else:
table_html += f'<td style="border:solid windowtext 1.0pt;padding:5px"><p class=MsoNormal style="margin:0"><span lang=ES>{md_to_html_para(cell)}</span></p></td>'
# Middle rows: no borders
table_html += f'<td style="border:none;padding:5px"><p class=MsoNormal style="margin:0"><span lang=ES>{md_to_html_para(cell)}</span></p></td>'
table_html += '</tr>'
table_html += '</table>'
html_blocks.append(table_html)