forked from FH-Cloud-Computing/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf-theme-handler.py
More file actions
102 lines (84 loc) · 2.01 KB
/
pdf-theme-handler.py
File metadata and controls
102 lines (84 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from bs4 import BeautifulSoup
def get_stylesheet() -> str:
return """
h1, h2, h3 {
string-set: chapter content();
}
.md-container {
display: block;
padding-top: 0;
}
.md-main {
display: block;
height: inherit;
}
.md-main__inner {
height: inherit;
padding-top: 0;
}
.md-typeset .codehilitetable .linenos {
display: none;
}
.md-typeset .footnote-ref {
display: inline-block;
}
.md-typeset a.footnote-backref {
transform: translateX(0);
opacity: 1;
}
.md-typeset .admonition {
display: block;
border-top: .1rem solid rgba(0,0,0,.07);
border-right: .1rem solid rgba(0,0,0,.07);
border-bottom: .1rem solid rgba(0,0,0,.07);
page-break-inside: avoid;
}
.md-typeset a::after {
color: inherit;
content: none;
}
.md-typeset table:not([class]) th {
min-width: 0;
}
.md-typeset table {
border: .1rem solid rgba(0,0,0,.07);
}
body > .container {
margin-top: -100px;
}
@page {
@bottom-left {
content: counter(__pgnum__);
}
size: a4;
}
@media print {
.noprint {
display: none;
}
}
img {
max-width:100%;
image-resolution: 300dpi;
}
ul li img, ol li img {
width:80% !important;
}
.md-content aside {
float:none !important;
margin-left:none !important;
}
body {
font-size: 10px;
}
"""
def modify_html(html: str, href: str) -> str:
soup = BeautifulSoup(html, 'html.parser')
downloads = soup.findAll("div", {"class": "download"})
if len(downloads) > 0:
a = soup.new_tag('a', href=href, download=None)
button = soup.new_tag('button')
button.string = 'Download PDF 🖨️'
a.append(button)
downloads[0].insert(0, a)
return str(soup)