[7f9fb8]: / tools / dev / gen_css_for_mne.py

Download this file

58 lines (43 with data), 1.6 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
"""
Generate a bootstrap-icons CSS file with embedded font.
- Install rcssmin (for CSS minification)
- Download and extract bootstrap-icons
- Copy to this directory:
- bootstrap-icons.css
- bootstrap-icons.woff2
- Run this script. It will generate bootstrap-icons.mne.css and
bootstrap-icons.mne.min.css
"""
# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import base64
from pathlib import Path
import rcssmin
import mne
base_dir = Path(mne.__file__).parent / "report" / "js_and_css" / "bootstrap-icons"
css_path_in = base_dir / "bootstrap-icons.css"
css_path_out = base_dir / "bootstrap-icons.mne.css"
css_minified_path_out = base_dir / "bootstrap-icons.mne.min.css"
font_path = base_dir / "bootstrap-icons.woff2"
def main():
"""Start the CSS modification."""
css_in = css_path_in.read_text(encoding="utf-8")
font_binary = font_path.read_bytes()
font_b64 = base64.b64encode(font_binary).decode("utf-8")
css_out = []
for css in css_in.split("\n"):
if "src: url(" in css:
css = (
f" src: url(data:font/woff2;charset=utf-8;"
f'base64,{font_b64}) format("woff2");'
)
elif "url(" in css:
continue
css_out.append(css)
css_out = "\n".join(css_out)
css_minified_out = rcssmin.cssmin(style=css_out)
css_path_out.write_text(data=css_out, encoding="utf-8")
css_minified_path_out.write_text(data=css_minified_out, encoding="utf-8")
if __name__ == "__main__":
main()