Skip to content

Commit 73d5718

Browse files
committed
Fix accessibly ebooks
1 parent 14b4b36 commit 73d5718

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/server/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def get_ebook_methodology(lang, year):
277277
)
278278
# Remove lazy-loading attributes
279279
methodology_maincontent = re.sub(' loading="lazy"', "", methodology_maincontent)
280+
# Remove lazy-loading attributes
281+
methodology_maincontent = re.sub('<div class="table-wrap">', "<div>", methodology_maincontent)
282+
methodology_maincontent = re.sub('<div class="table-wrap-container">', "<div>", methodology_maincontent)
280283
return methodology_maincontent
281284

282285

src/static/css/ebook.css

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,21 @@
6969
margin: 0;
7070
}
7171

72+
table {
73+
border-radius: 16px;
74+
border-radius: 1rem;
75+
box-shadow: 0 0 16px 0 rgb(78, 85, 100, 0.2);
76+
box-shadow: 0 0 1rem 0 rgb(78, 85, 100, 0.2);
77+
}
78+
7279
.table-wrap {
7380
padding: 0;
7481
}
7582

83+
table caption {
84+
caption-side: bottom;
85+
}
86+
7687
.large-table td {
7788
padding: 0.2rem;
7889
line-height: 1.5em;
@@ -360,9 +371,9 @@ section.chapter {
360371
/** We have some big tables that can't be force to break
361372
* So we cheat and make them small enough to fit on a page
362373
*/
363-
figure table td,
364-
figure table td li,
365-
figure table td p {
374+
div table td,
375+
div table td li,
376+
div table td p {
366377
font-size: 12px;
367378
font-size: 0.85rem;
368379
}
@@ -412,6 +423,8 @@ section.chapter {
412423
figure a,
413424
figure div,
414425
figure img,
426+
div.table,
427+
p.table-caption,
415428
figcaption {
416429
max-width: 100%;
417430
text-align: center;
@@ -426,7 +439,8 @@ section.chapter {
426439
text-decoration: none;
427440
}
428441

429-
figcaption {
442+
figcaption,
443+
p.table-caption {
430444
width: 1000px;
431445
}
432446

src/static/css/page.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ figure .anchor-link {
505505
background-color: #e5e5e5;
506506
}
507507

508-
figure {
508+
figure,
509+
div.table {
509510
position: relative;
510511
display: flex;
511512
flex-direction: column;
@@ -551,7 +552,8 @@ figure .code-block {
551552
margin: 0.625rem auto;
552553
}
553554

554-
figcaption {
555+
figcaption,
556+
p.table-caption {
555557
margin: 8px auto 0;
556558
margin: 0.5rem auto 0;
557559
text-align: center;

src/tools/generate/generate_ebooks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const update_links = (chapter, chapter_config) => {
1414
body = body.replace(/figure_link\(/g,'figure_link(ebook=true,');
1515
// Remove figure_drodowns as not needed
1616
body = body.replace(/{{\s*figure_dropdown.*?}}/gsm,'');
17+
// For PDFs tables cannot be in figures
18+
body = body.replace(/<figure (id="[^"]*?")><div class="table-wrap"><div class="table-wrap-container"><table>/gs,'<table $1>');
19+
body = body.replace(/(<\/table><\/div><\/div>\n *)<figcaption>(.*?)<\/figcaption>(\n *)<\/figure>/gs,'</table><p class="table-caption">$2</p>');
1720
// Replace current chapter header ids to full id (e.g. <h2 id="introduction"> -> <h2 id="javascript-introduction">)
1821
body = body.replace(/<h([0-6]) id="/g,'<h$1 id="' + chapter.metadata.chapter + '-');
1922
// Replace other chapter references with hash to anchor link (e.g. ./javascript#fig-1 -> #javascript-fig-1)

0 commit comments

Comments
 (0)