Merge pull request #663 from jdemeyer/relative_mathjax

Interpret mathjax_url relative to base_url
This commit is contained in:
Min RK 2015-10-27 13:29:32 +01:00
commit 4578c34b0f
3 changed files with 12 additions and 6 deletions

View File

@ -32,7 +32,7 @@ from ipython_genutils.path import filefind
from ipython_genutils.py3compat import string_types
import notebook
from notebook.utils import is_hidden, url_path_join, url_escape
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape
from notebook.services.security import csp_report_uri
#-----------------------------------------------------------------------------
@ -155,7 +155,10 @@ class IPythonHandler(AuthenticatedHandler):
@property
def mathjax_url(self):
return self.settings.get('mathjax_url', '')
url = self.settings.get('mathjax_url', '')
if not url or url_is_absolute(url):
return url
return url_path_join(self.base_url, url)
@property
def base_url(self):

View File

@ -658,9 +658,7 @@ class NotebookApp(JupyterApp):
def _mathjax_url_default(self):
if not self.enable_mathjax:
return u''
static_url_prefix = self.tornado_settings.get("static_url_prefix",
url_path_join(self.base_url, "static")
)
static_url_prefix = self.tornado_settings.get("static_url_prefix", "static")
return url_path_join(static_url_prefix, 'components', 'MathJax', 'MathJax.js')
def _mathjax_url_changed(self, name, old, new):

View File

@ -13,9 +13,10 @@ import sys
from distutils.version import LooseVersion
try:
from urllib.parse import quote, unquote
from urllib.parse import quote, unquote, urlparse
except ImportError:
from urllib import quote, unquote
from urlparse import urlparse
from ipython_genutils import py3compat
@ -39,6 +40,10 @@ def url_path_join(*pieces):
if result == '//': result = '/'
return result
def url_is_absolute(url):
"""Determine whether a given URL is absolute"""
return urlparse(url).path.startswith("/")
def path2url(path):
"""Convert a local file path to a URL"""
pieces = [ quote(p) for p in path.split(os.sep) ]