Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -216,71 +216,233 @@ def clean_html_content(html_content: str, image_counter: list, images_data: dict
|
|
| 216 |
# Insérer les styles dans une balise <style> dans le corps
|
| 217 |
style_tag = soup.new_tag('style')
|
| 218 |
style_tag.string = """
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
"""
|
| 285 |
if soup.body:
|
| 286 |
soup.body.insert(0, style_tag)
|
|
|
|
| 216 |
# Insérer les styles dans une balise <style> dans le corps
|
| 217 |
style_tag = soup.new_tag('style')
|
| 218 |
style_tag.string = """
|
| 219 |
+
|
| 220 |
+
/* Variables CSS pour une gestion facile des tailles */
|
| 221 |
+
:root {
|
| 222 |
+
--font-size-min: 14px;
|
| 223 |
+
--font-size-base: 1rem; /* 16px par défaut */
|
| 224 |
+
--font-size-large: 2.5rem; /* Ajustable selon les besoins */
|
| 225 |
+
--line-height: 1.5;
|
| 226 |
+
--font-family: Arial, Calibri, Verdana, sans-serif;
|
| 227 |
+
--text-color: #1a1a1a;
|
| 228 |
+
--background-color: #fdfdfd;
|
| 229 |
+
--link-color: #1a1a1a;
|
| 230 |
+
--heading-color-primary: Navy;
|
| 231 |
+
--heading-color-secondary: DarkGreen;
|
| 232 |
+
--heading-color-tertiary: DarkRed;
|
| 233 |
+
--heading-color-quaternary: DarkSlateGray;
|
| 234 |
+
--heading-color-quinary: DarkSlateBlue;
|
| 235 |
+
--heading-color-senary: DarkViolet;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* Styles de base */
|
| 239 |
+
html {
|
| 240 |
+
font-family: var(--font-family);
|
| 241 |
+
font-size: var(--font-size-base);
|
| 242 |
+
line-height: var(--line-height);
|
| 243 |
+
color: var(--text-color);
|
| 244 |
+
background-color: var(--background-color);
|
| 245 |
+
/* Fluid Typography: Ajuste la taille de la police en fonction de la largeur de la fenêtre */
|
| 246 |
+
font-size: clamp(var(--font-size-min), 2vw, 2rem);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
body {
|
| 250 |
+
margin: 20px auto;
|
| 251 |
+
max-width: 36em; /* 36em correspond à environ 576px */
|
| 252 |
+
padding: 2rem;
|
| 253 |
+
hyphens: auto;
|
| 254 |
+
overflow-wrap: break-word;
|
| 255 |
+
text-rendering: optimizeLegibility;
|
| 256 |
+
font-kerning: normal;
|
| 257 |
+
text-align: left;
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
/* Titres réactifs */
|
| 261 |
+
h1 {
|
| 262 |
+
margin-left: 0;
|
| 263 |
+
color: var(--heading-color-primary);
|
| 264 |
+
font-size: clamp(1.5rem, 5vw, 3rem); /* Entre 24px et 48px */
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
h2 {
|
| 268 |
+
margin-left: 1.25rem;
|
| 269 |
+
color: var(--heading-color-secondary);
|
| 270 |
+
font-size: clamp(1.25rem, 4vw, 2.5rem); /* Entre 20px et 40px */
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
h3 {
|
| 274 |
+
margin-left: 2.5rem;
|
| 275 |
+
color: var(--heading-color-tertiary);
|
| 276 |
+
font-size: clamp(1.125rem, 3.5vw, 2.25rem); /* Entre 18px et 36px */
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
h4, h5, h6 {
|
| 280 |
+
margin-left: calc(3.75rem + (hN * 1.25rem)); /* Ajustement dynamique */
|
| 281 |
+
color: var(--heading-color-quaternary);
|
| 282 |
+
font-size: clamp(1rem, 3vw, 2rem); /* Entre 16px et 32px */
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
/* Médias responsive */
|
| 286 |
+
@media (max-width: 600px) {
|
| 287 |
+
html {
|
| 288 |
+
font-size: clamp(var(--font-size-min), 4vw, 1.5rem); /* Ajuste légèrement pour petits écrans */
|
| 289 |
+
}
|
| 290 |
+
body {
|
| 291 |
+
padding: 1rem;
|
| 292 |
+
}
|
| 293 |
+
h1 {
|
| 294 |
+
font-size: clamp(1.5rem, 6vw, 2.5rem);
|
| 295 |
+
}
|
| 296 |
+
h2 {
|
| 297 |
+
font-size: clamp(1.25rem, 5vw, 2rem);
|
| 298 |
+
}
|
| 299 |
+
h3 {
|
| 300 |
+
font-size: clamp(1.125rem, 4.5vw, 1.75rem);
|
| 301 |
+
}
|
| 302 |
+
h4, h5, h6 {
|
| 303 |
+
font-size: clamp(1rem, 4vw, 1.5rem);
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/* Impression */
|
| 308 |
+
@media print {
|
| 309 |
+
body {
|
| 310 |
+
background-color: transparent;
|
| 311 |
+
color: black;
|
| 312 |
+
font-size: 12pt;
|
| 313 |
+
}
|
| 314 |
+
p, h2, h3 {
|
| 315 |
+
orphans: 3;
|
| 316 |
+
widows: 3;
|
| 317 |
+
}
|
| 318 |
+
h2, h3, h4 {
|
| 319 |
+
page-break-after: avoid;
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
/* Paragraphes et liens */
|
| 324 |
+
p {
|
| 325 |
+
margin: 1em 0;
|
| 326 |
+
font-size: 1rem; /* 16px */
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
a {
|
| 330 |
+
color: var(--link-color);
|
| 331 |
+
text-decoration: none;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
a:visited {
|
| 335 |
+
color: var(--link-color);
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
a:hover, a:focus {
|
| 339 |
+
text-decoration: underline; /* Améliore la visibilité au survol */
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
/* Images réactives */
|
| 343 |
+
img {
|
| 344 |
+
max-width: 100%;
|
| 345 |
+
height: auto;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
/* Tables réactives */
|
| 349 |
+
table {
|
| 350 |
+
margin: 1em 0;
|
| 351 |
+
border-collapse: collapse;
|
| 352 |
+
width: 100%;
|
| 353 |
+
overflow-x: auto;
|
| 354 |
+
display: block;
|
| 355 |
+
font-variant-numeric: lining-nums tabular-nums;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
table caption {
|
| 359 |
+
margin-bottom: 0.75em;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
th, td {
|
| 363 |
+
border: 1px solid #000;
|
| 364 |
+
padding: 0.5em;
|
| 365 |
+
text-align: left;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
tbody tr:nth-child(odd) {
|
| 369 |
+
background-color: #f2f2f2;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
tbody tr:nth-child(even) {
|
| 373 |
+
background-color: #ffffff;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
/* Citations */
|
| 377 |
+
blockquote {
|
| 378 |
+
margin: 1em 0 1em 1.7em;
|
| 379 |
+
padding-left: 1em;
|
| 380 |
+
border-left: 2px solid #e6e6e6;
|
| 381 |
+
color: #606060;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/* Code */
|
| 385 |
+
code {
|
| 386 |
+
font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace;
|
| 387 |
+
font-size: 0.85rem;
|
| 388 |
+
margin: 0;
|
| 389 |
+
white-space: pre-wrap;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
pre {
|
| 393 |
+
margin: 1em 0;
|
| 394 |
+
overflow: auto;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
pre code {
|
| 398 |
+
padding: 0;
|
| 399 |
+
overflow: visible;
|
| 400 |
+
overflow-wrap: normal;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
.sourceCode {
|
| 404 |
+
background-color: transparent;
|
| 405 |
+
overflow: visible;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
/* Lignes horizontales */
|
| 409 |
+
hr {
|
| 410 |
+
background-color: #1a1a1a;
|
| 411 |
+
border: none;
|
| 412 |
+
height: 1px;
|
| 413 |
+
margin: 1em 0;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/* Styles supplémentaires */
|
| 417 |
+
span.smallcaps {
|
| 418 |
+
font-variant: small-caps;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
span.underline {
|
| 422 |
+
text-decoration: underline;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
div.column {
|
| 426 |
+
display: inline-block;
|
| 427 |
+
vertical-align: top;
|
| 428 |
+
width: 50%;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
div.hanging-indent {
|
| 432 |
+
margin-left: 1.5em;
|
| 433 |
+
text-indent: -1.5em;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
ul.task-list {
|
| 437 |
+
list-style: none;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
.display.math {
|
| 441 |
+
display: block;
|
| 442 |
+
text-align: center;
|
| 443 |
+
margin: 0.5rem auto;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
"""
|
| 447 |
if soup.body:
|
| 448 |
soup.body.insert(0, style_tag)
|