Documentation review. (#5)
All checks were successful
build_docker / essential (push) Successful in 0s
build_docker / build_paddle_ocr (push) Successful in 5m28s
build_docker / build_paddle_ocr_gpu (push) Successful in 21m16s
build_docker / build_easyocr (push) Successful in 15m52s
build_docker / build_easyocr_gpu (push) Successful in 18m22s
build_docker / build_doctr (push) Successful in 19m3s
build_docker / build_raytune (push) Successful in 3m34s
build_docker / build_doctr_gpu (push) Successful in 13m56s

This commit was merged in pull request #5.
This commit is contained in:
2026-01-20 14:33:46 +00:00
committed by Sergio Jimenez Jimenez
parent c7ed7b2b9c
commit 9ee2490097
56 changed files with 2182 additions and 945 deletions

View File

@@ -6,10 +6,18 @@ import re
import subprocess
import json
import cairosvg
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DOCS_DIR = os.path.join(BASE_DIR, 'docs')
OUTPUT_DIR = os.path.join(BASE_DIR, 'thesis_output/figures')
MMDC = os.path.join(BASE_DIR, 'node_modules/.bin/mmdc')
CONFIG_FILE = os.path.join(BASE_DIR, 'mermaid.config.json')
# Light blue color for bar charts
BAR_COLOR = '#0098CD'
# Default bar colors that need to be replaced (varies by theme)
DEFAULT_BAR_COLORS = ['#ECECFF', '#FFF4DD', '#ececff', '#fff4dd']
def extract_mermaid_diagrams():
"""Extract all mermaid diagrams from markdown files."""
@@ -35,10 +43,12 @@ def extract_mermaid_diagrams():
matches = re.findall(pattern, content, re.DOTALL)
for i, mermaid_code in enumerate(matches):
# Try to extract title from YAML front matter or inline title
# Try to extract title from YAML front matter
# Match title with quotes: title: "Something" or title: 'Something'
title_match = re.search(r'title:\s*["\']([^"\']+)["\']', mermaid_code)
if not title_match:
title_match = re.search(r'title\s+["\']?([^"\'"\n]+)["\']?', mermaid_code)
# Match title without quotes: title: Something
title_match = re.search(r'title:\s*([^"\'\n]+)', mermaid_code)
title = title_match.group(1).strip() if title_match else f"Diagrama {len(diagrams) + 1}"
diagrams.append({
@@ -61,17 +71,51 @@ def convert_to_png(diagrams):
temp_file = os.path.join(OUTPUT_DIR, f'temp_{diagram["index"]}.mmd')
output_file = os.path.join(OUTPUT_DIR, f'figura_{diagram["index"]}.png')
# Check if this is a bar chart (xychart-beta)
is_bar_chart = 'xychart-beta' in diagram['code']
with open(temp_file, 'w', encoding='utf-8') as f:
f.write(diagram['code'])
# Convert using mmdc with moderate size for page fit
try:
result = subprocess.run(
[MMDC, '-i', temp_file, '-o', output_file, '-b', 'white', '-w', '800', '-s', '1.5'],
capture_output=True,
text=True,
timeout=60
)
if is_bar_chart:
# For bar charts: generate SVG, fix colors, convert to PNG
svg_file = os.path.join(OUTPUT_DIR, f'temp_{diagram["index"]}.svg')
result = subprocess.run(
[MMDC, '-i', temp_file, '-o', svg_file, '-b', 'white', '-w', '1600', '-c', CONFIG_FILE],
capture_output=True,
text=True,
timeout=60
)
if os.path.exists(svg_file):
# Read SVG and replace bar color
with open(svg_file, 'r', encoding='utf-8') as f:
svg_content = f.read()
# Replace default bar colors with light blue (both fill and stroke)
for default_color in DEFAULT_BAR_COLORS:
svg_content = svg_content.replace(f'fill="{default_color}"', f'fill="{BAR_COLOR}"')
svg_content = svg_content.replace(f"fill='{default_color}'", f"fill='{BAR_COLOR}'")
svg_content = svg_content.replace(f'stroke="{default_color}"', f'stroke="{BAR_COLOR}"')
svg_content = svg_content.replace(f"stroke='{default_color}'", f"stroke='{BAR_COLOR}'")
# Convert SVG to PNG using cairosvg (with scale for high resolution)
cairosvg.svg2png(bytestring=svg_content.encode('utf-8'),
write_to=output_file,
scale=3)
# Clean up SVG
os.remove(svg_file)
else:
# For other diagrams: direct PNG generation
result = subprocess.run(
[MMDC, '-i', temp_file, '-o', output_file, '-b', 'white', '-w', '1600', '-s', '3', '-c', CONFIG_FILE],
capture_output=True,
text=True,
timeout=60
)
if os.path.exists(output_file):
print(f"✓ Generated: figura_{diagram['index']}.png - {diagram['title']}")