|
18 | 18 |
|
19 | 19 | import jinja2 |
20 | 20 |
|
| 21 | +from nbconvert.exporters.html import find_lab_theme |
| 22 | + |
| 23 | +from jupyterlab_server.themes_handler import ThemesHandler |
| 24 | + |
21 | 25 | from .static_file_handler import TemplateStaticFileHandler |
22 | 26 |
|
23 | 27 |
|
@@ -125,9 +129,24 @@ def include_url(template_name, base_url, name): |
125 | 129 | return jinja2.Markup(make_url(template_name, base_url, name)) |
126 | 130 |
|
127 | 131 |
|
| 132 | +def include_lab_theme(base_url, name): |
| 133 | + # Try to find the theme with the given name, looking through the labextensions |
| 134 | + theme_name, _ = find_lab_theme(name) |
| 135 | + |
| 136 | + settings = { |
| 137 | + 'static_url_prefix': f'{base_url}voila/themes/', |
| 138 | + 'static_path': None # not used in TemplateStaticFileHandler.get_absolute_path |
| 139 | + } |
| 140 | + url = ThemesHandler.make_static_url(settings, f'{theme_name}/index.css') |
| 141 | + |
| 142 | + code = f'<link rel="stylesheet" type="text/css" href="{url}">' |
| 143 | + return jinja2.Markup(code) |
| 144 | + |
| 145 | + |
128 | 146 | def create_include_assets_functions(template_name, base_url): |
129 | 147 | return { |
130 | 148 | "include_css": partial(include_css, template_name, base_url), |
131 | 149 | "include_js": partial(include_js, template_name, base_url), |
132 | | - "include_url": partial(include_url, template_name, base_url) |
| 150 | + "include_url": partial(include_url, template_name, base_url), |
| 151 | + "include_lab_theme": partial(include_lab_theme, base_url) |
133 | 152 | } |
0 commit comments