#513: Allow giving non-local URIs for JavaScript files, e.g. in the JSMath extension.

This commit is contained in:
Georg Brandl
2010-08-25 10:26:15 +00:00
parent d7e37da324
commit 7e5ff71c40
6 changed files with 17 additions and 4 deletions

View File

@@ -1,6 +1,9 @@
Release 1.0.4 (in development)
==============================
* #513: Allow giving non-local URIs for JavaScript files, e.g.
in the JSMath extension.
* #512: Fix traceback when ``intersphinx_mapping`` is empty.

View File

@@ -246,7 +246,8 @@ the following public API:
Add *filename* to the list of JavaScript files that the default HTML template
will include. The filename must be relative to the HTML static path, see
:confval:`the docs for the config value <html_static_path>`.
:confval:`the docs for the config value <html_static_path>`. A full URI with
scheme, like ``http://example.org/foo.js``, is also supported.
.. versionadded:: 0.5

View File

@@ -456,8 +456,11 @@ class Sphinx(object):
def add_javascript(self, filename):
from sphinx.builders.html import StandaloneHTMLBuilder
StandaloneHTMLBuilder.script_files.append(
posixpath.join('_static', filename))
if '://' in filename:
StandaloneHTMLBuilder.script_files.append(filename)
else:
StandaloneHTMLBuilder.script_files.append(
posixpath.join('_static', filename))
def add_stylesheet(self, filename):
from sphinx.builders.html import StandaloneHTMLBuilder

View File

@@ -678,7 +678,10 @@ class StandaloneHTMLBuilder(Builder):
def pathto(otheruri, resource=False,
baseuri=self.get_target_uri(pagename)):
if not resource:
if resource and '://' in otheruri:
# allow non-local resources given by scheme
return otheruri
elif not resource:
otheruri = self.get_target_uri(otheruri)
uri = relative_uri(baseuri, otheruri) or '#'
return uri

View File

@@ -91,3 +91,4 @@ def setup(app):
app.add_directive('clsdir', ClassDirective)
app.add_object_type('userdesc', 'userdescrole', '%s (userdesc)',
userdesc_parse, objname='user desc')
app.add_javascript('file://moo.js')

View File

@@ -205,6 +205,8 @@ HTML_XPATH = {
(".//li/a[@href='search.html']/em", 'Search Page'),
# custom sidebar only for contents
(".//h4", 'Contents sidebar'),
# custom JavaScript
(".//script[@src='file://moo.js']", ''),
],
'bom.html': [
(".//title", " File with UTF-8 BOM"),