freelance-dashboard/md_to_html.py
StillHammer 21ebf32e4f Dashboard avec graphiques, TCD, slicers et checkboxes fonctionnels
- KPIs complets (CA, Heures, Taux, Stats, Objectifs)
- Graphiques CA par client + Heures par client
- TCD Heures x Client x Projet avec Slicer interactif
- Checkboxes dynamiques bien positionnes (E3:E7)
- Documentation technique et guides MCP

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 17:05:25 +07:00

234 lines
6.4 KiB
Python

#!/usr/bin/env python3
"""
Convert Markdown to styled HTML that can be printed to PDF from browser
"""
import markdown
import os
def convert_md_to_html(input_file, output_file):
"""Convert markdown file to HTML"""
# Read markdown file
with open(input_file, 'r', encoding='utf-8') as f:
md_content = f.read()
# Convert markdown to HTML
html = markdown.markdown(md_content, extensions=['tables', 'fenced_code', 'codehilite'])
# Add CSS styling
html_with_style = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Freelance Dashboard - Technical Reference</title>
<style>
@page {{
size: A4;
margin: 2cm;
}}
@media print {{
body {{
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}}
}}
body {{
font-family: Arial, Helvetica, sans-serif;
font-size: 11pt;
line-height: 1.6;
color: #333;
max-width: 210mm;
margin: 0 auto;
padding: 20px;
background: white;
}}
h1 {{
color: #2C3E50;
font-size: 24pt;
text-align: center;
margin-bottom: 30px;
border-bottom: 3px solid #27AE60;
padding-bottom: 15px;
page-break-after: avoid;
}}
h2 {{
color: #2C3E50;
font-size: 18pt;
margin-top: 25px;
margin-bottom: 15px;
border-bottom: 2px solid #ECF0F1;
padding-bottom: 8px;
page-break-after: avoid;
}}
h3 {{
color: #27AE60;
font-size: 14pt;
margin-top: 20px;
margin-bottom: 10px;
page-break-after: avoid;
}}
h4 {{
color: #2C3E50;
font-size: 12pt;
margin-top: 15px;
margin-bottom: 8px;
page-break-after: avoid;
}}
p {{
margin: 10px 0;
text-align: justify;
orphans: 3;
widows: 3;
}}
code {{
background-color: #F5F5F5;
padding: 2px 6px;
font-family: 'Courier New', Consolas, monospace;
font-size: 9pt;
color: #C0392B;
border: 1px solid #DDDDDD;
border-radius: 3px;
}}
pre {{
background-color: #F5F5F5;
color: #2C3E50;
padding: 15px;
border: 1px solid #DDDDDD;
border-radius: 5px;
overflow-x: auto;
font-family: 'Courier New', Consolas, monospace;
font-size: 9pt;
line-height: 1.5;
page-break-inside: avoid;
}}
pre code {{
background-color: transparent;
color: #2C3E50;
padding: 0;
border: none;
}}
table {{
border-collapse: collapse;
width: 100%;
margin: 20px 0;
font-size: 10pt;
page-break-inside: avoid;
}}
th {{
background-color: #2C3E50;
color: white;
padding: 10px;
text-align: left;
border: 1px solid #ddd;
font-weight: bold;
}}
td {{
padding: 8px;
border: 1px solid #ddd;
}}
tr:nth-child(even) {{
background-color: #f9f9f9;
}}
blockquote {{
border-left: 4px solid #27AE60;
padding-left: 15px;
margin: 20px 0;
font-style: italic;
color: #555;
background-color: #f9f9f9;
padding: 10px 15px;
}}
ul, ol {{
margin: 10px 0;
padding-left: 30px;
}}
li {{
margin: 5px 0;
}}
hr {{
border: none;
border-top: 2px solid #ECF0F1;
margin: 30px 0;
}}
.print-button {{
position: fixed;
top: 20px;
right: 20px;
background-color: #27AE60;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 14pt;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}}
.print-button:hover {{
background-color: #229954;
}}
@media print {{
.print-button {{
display: none;
}}
}}
</style>
<script>
function printPDF() {{
window.print();
}}
</script>
</head>
<body>
<button class="print-button" onclick="printPDF()">Print to PDF</button>
{html}
</body>
</html>
"""
# Save HTML
with open(output_file, 'w', encoding='utf-8') as f:
f.write(html_with_style)
print(f"HTML created successfully: {output_file}")
print(f"\nTo create PDF:")
print(f"1. Open the HTML file in your browser")
print(f"2. Click 'Print to PDF' button or use Ctrl+P")
print(f"3. Select 'Save as PDF' as destination")
print(f"4. Save the file")
if __name__ == '__main__':
input_file = r'C:\Users\alexi\Documents\projects\freelance-dashboard\TECHNICAL_REFERENCE_EN.md'
output_file = r'C:\Users\alexi\Documents\projects\freelance-dashboard\TECHNICAL_REFERENCE_EN.html'
if os.path.exists(input_file):
convert_md_to_html(input_file, output_file)
# Open in default browser
import webbrowser
webbrowser.open(f'file:///{output_file}')
else:
print(f"Input file not found: {input_file}")