-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
__init__.py
60 lines (47 loc) · 1.67 KB
/
__init__.py
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
""" JupyterLab LaTex : live LaTeX editing for JupyterLab """
from ._version import __version__, __js__
__all__ = [
"__js__",
"__version__",
"_jupyter_labextension_paths",
"_jupyter_server_extension_paths",
"_jupyter_server_extension_points",
"_load_jupyter_server_extension",
"load_jupyter_server_extension",
]
path_regex = r'(?P<path>(?:(?:/[^/]+)+|/?))'
def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": __js__["name"]
}]
def _jupyter_server_extension_points():
return [{
'module': 'jupyterlab_latex'
}]
_jupyter_server_extension_paths = _jupyter_server_extension_points
def load_jupyter_server_extension(nb_server_app):
"""
Called when the extension is loaded.
Args:
nb_server_app (NotebookApp): handle to the Notebook webserver instance.
"""
from notebook.utils import url_path_join
from .build import LatexBuildHandler
from .synctex import LatexSynctexHandler
web_app = nb_server_app.web_app
# Prepend the base_url so that it works in a jupyterhub setting
base_url = web_app.settings['base_url']
latex = url_path_join(base_url, 'latex')
build = url_path_join(latex, 'build')
synctex = url_path_join(latex, 'synctex')
handlers = [(f'{build}{path_regex}',
LatexBuildHandler,
{"notebook_dir": nb_server_app.notebook_dir}
),
(f'{synctex}{path_regex}',
LatexSynctexHandler,
{"notebook_dir": nb_server_app.notebook_dir}
)]
web_app.add_handlers('.*$', handlers)
_load_jupyter_server_extension = load_jupyter_server_extension