LeX-logo op titelpagina en in de voet van elk document
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import markdown
|
||||
|
||||
TOOLS = Path(__file__).resolve().parent
|
||||
LOGO = TOOLS / "logo-ai-netwerk-limburg.png"
|
||||
LOGO_LEX = TOOLS / "logo-lex.png" # kleiner, naast het LAI-logo
|
||||
|
||||
# Licentie en contact, komen als colofon onderaan elk document (HTML, PDF en Word).
|
||||
EIGENAAR = "Guido van Dijk, LeX Consultancy B.V. en AI Netwerk Limburg"
|
||||
@@ -33,7 +34,9 @@ body { font-family: "Noto Sans", "DejaVu Sans", Arial, sans-serif; color: #1a1a1
|
||||
.kop { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5em;
|
||||
margin-bottom: 1em; }
|
||||
.kop-tekst { flex: 1 1 auto; }
|
||||
.kop img { flex: 0 0 auto; width: 3.4cm; height: auto; }
|
||||
.kop .logos { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: .3em; }
|
||||
.kop img { width: 3.4cm; height: auto; }
|
||||
.kop img.lex { width: 2cm; }
|
||||
h1 { font-size: 22pt; margin: 0 0 .3em; line-height: 1.2; }
|
||||
h2 { font-size: 15pt; margin: 1.6em 0 .5em; padding-top: .3em; border-top: 2px solid #1d4ed8;
|
||||
page-break-after: avoid; break-after: avoid; }
|
||||
@@ -73,6 +76,7 @@ ol li { margin: .25em 0; }
|
||||
.voet { margin-top: 3em; padding-top: .6em; border-top: 1px solid #ddd; font-size: .85em; color: #555;
|
||||
display: flex; align-items: center; gap: .8em; }
|
||||
.voet img { width: 1.6cm; height: auto; }
|
||||
.voet img.lex { width: 1.1cm; }
|
||||
"""
|
||||
|
||||
|
||||
@@ -85,16 +89,16 @@ def read_source(src: Path) -> str:
|
||||
return re.sub(r"(\n> [^\n]*\n)\n(?=> )", r"\1\n<!-- -->\n\n", text)
|
||||
|
||||
|
||||
def logo_src(embed: bool) -> str:
|
||||
def logo_src(embed: bool, pad: Path = LOGO) -> str:
|
||||
if embed:
|
||||
return "data:image/png;base64," + base64.b64encode(LOGO.read_bytes()).decode()
|
||||
return LOGO.as_uri()
|
||||
return "data:image/png;base64," + base64.b64encode(pad.read_bytes()).decode()
|
||||
return pad.as_uri()
|
||||
|
||||
|
||||
COMPACT_CSS = """
|
||||
html { font-size: 9.2pt; } h1 { font-size: 17pt; } h2 { margin-top: 1em; } @page { margin: 1.5cm 2cm 1.5cm 2cm; }
|
||||
p { margin: .35em 0; } table { margin: .5em 0; } th, td { padding: .25em .5em; }
|
||||
.colofon { margin-top: .5em; padding: .3em .5em; font-size: .75em; border: 0; border-top: 1px solid #ddd; border-radius: 0; background: none; } .voet { margin-top: .6em; } .voet img { width: 1.1cm; } .kop img { width: 2.8cm; } ul, ol { margin: .3em 0 .3em 1.3em; }
|
||||
.colofon { margin-top: .5em; padding: .3em .5em; font-size: .75em; border: 0; border-top: 1px solid #ddd; border-radius: 0; background: none; } .voet { margin-top: .6em; } .voet img { width: 1.1cm; } .voet img.lex { width: .8cm; } .kop img { width: 2.8cm; } .kop img.lex { width: 1.6cm; } ul, ol { margin: .3em 0 .3em 1.3em; }
|
||||
"""
|
||||
|
||||
|
||||
@@ -102,6 +106,7 @@ def to_html(md_text: str, here: Path, embed_images: bool, compact: bool = False)
|
||||
body = markdown.markdown(md_text, extensions=["tables", "sane_lists", "smarty", "fenced_code"])
|
||||
title = re.search(r"<h1>(.*?)</h1>", body).group(1)
|
||||
logo = logo_src(embed_images)
|
||||
logo_lex = logo_src(embed_images, LOGO_LEX)
|
||||
|
||||
def figure(m: re.Match) -> str:
|
||||
alt, src = m.group(1), m.group(2)
|
||||
@@ -159,13 +164,15 @@ def to_html(md_text: str, here: Path, embed_images: bool, compact: bool = False)
|
||||
lambda m: (f'<table border="0" width="100%"><tr>'
|
||||
f'<td width="78%" valign="top">{m.group(1)}</td>'
|
||||
f'<td width="22%" valign="top" align="right">'
|
||||
f'<img src="{logo}" width="120" alt="AI Netwerk Limburg" /></td></tr></table>'),
|
||||
f'<img src="{logo}" width="120" alt="AI Netwerk Limburg" /><br />'
|
||||
f'<img src="{logo_lex}" width="70" alt="LeX Consultancy" /></td></tr></table>'),
|
||||
body, count=1, flags=re.S)
|
||||
else:
|
||||
body = re.sub(
|
||||
r"^(<h1>.*?</h1>\s*<p>.*?</p>)",
|
||||
lambda m: (f'<div class="kop"><div class="kop-tekst">{m.group(1)}</div>'
|
||||
f'<img src="{logo}" alt="AI Netwerk Limburg" /></div>'),
|
||||
f'<div class="logos"><img src="{logo}" alt="AI Netwerk Limburg" />'
|
||||
f'<img src="{logo_lex}" class="lex" alt="LeX Consultancy" /></div></div>'),
|
||||
body, count=1, flags=re.S)
|
||||
|
||||
colofon = (
|
||||
@@ -188,8 +195,8 @@ def to_html(md_text: str, here: Path, embed_images: bool, compact: bool = False)
|
||||
return (f'<!DOCTYPE html><html lang="nl"><head><meta charset="utf-8">'
|
||||
f"<title>{title}</title><style>{CSS}{COMPACT_CSS}</style></head><body>{body}</body></html>")
|
||||
|
||||
voet = (f'<div class="voet"><img src="{logo}" alt="" />'
|
||||
f'<span>AI Netwerk Limburg · ai-netwerk-limburg.nl · {title}</span></div>')
|
||||
voet = (f'<div class="voet"><img src="{logo}" alt="" /><img src="{logo_lex}" class="lex" alt="" />'
|
||||
f'<span>AI Netwerk Limburg · LeX Consultancy B.V. · {title}</span></div>')
|
||||
|
||||
return (f'<!DOCTYPE html><html lang="nl"><head><meta charset="utf-8">'
|
||||
f"<title>{title}</title><style>{CSS}{COMPACT_CSS if compact else ''}</style></head>"
|
||||
|
||||
Reference in New Issue
Block a user