Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_javascript() & relative_uri() don't support local file url syntax in Sphinx 1.0.3 #513

Closed
shimizukawa opened this issue Jan 2, 2015 · 2 comments

Comments

@shimizukawa
Copy link
Member

In order to easily test the new mathjax extension (https://bitbucket.org/kevindunn/sphinx-extension-mathjax/src/tip/mathjax.py and see discussion at http://groups.google.com/group/sphinx-dev/browse_thread/thread/164db6fd920f3501/) on Windows with local files, I initially tried the following in my conf.py file:

  mathjax_path = '/MathJax/MathJax.js'

but wasn't able to figure out where that directory is on Windows? Putting it directly in the C:\ folder didn't work.

I finally had to specify the following:

  mathjax_path = 'file:///C:/MathJax/MathJax.js'

However, this doesn't work with Sphinx 1.0.3 unless I change add_javascript() in sphinx/application.py from:

    def add_javascript(self, filename):
        from sphinx.builders.html import StandaloneHTMLBuilder
        StandaloneHTMLBuilder.script_files.append(
            posixpath.join('_static', filename))

to:

    def add_javascript(self, filename):
        from sphinx.builders.html import StandaloneHTMLBuilder
        if filename.startswith('file://'):
            StandaloneHTMLBuilder.script_files.append(filename)
        else:
            StandaloneHTMLBuilder.script_files.append(
                posixpath.join('_static', filename))

Looking at basic/layout.html I see:

    {%- for scriptfile in script_files %}
    <script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
    {&#37;- endfor &#37;}

And by looking at pathto() in sphinx\builders\html.py:

    def pathto(otheruri, resource=False,
               baseuri=self.get_target_uri(pagename)):
        if not resource:
            otheruri = self.get_target_uri(otheruri)
        uri = relative_uri(baseuri, otheruri) or '#'
        return uri

I see I also need to change relative_uri in sphinx\util\osutil.py from:

    def relative_uri(base, to):
        """Return a relative URL from ``base`` to ``to``."""
        if to.startswith(SEP):
            return to

to:

    def relative_uri(base, to):
        """Return a relative URL from ``base`` to ``to``."""
        if to.startswith(SEP) or to.startswith("file://"):
            return to

I have a feeling that bad things would also happen if you tried to temporarily use mathjax from some other host while testing local files; i.e. the following probably also won't work?:

  mathjax_path = 'http://www.someotherhost.org/MathJax/MathJax.js'

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2010-08-25 10:30:10+00:00

Should be fixed in <<cset 7e5ff71>>. Thanks for reoprting!

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2011-09-22 10:14:45+00:00

Removing milestone: 1.0 (automated comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant