Commits

Georg Brandl committed f03bf97

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

  • Participants
  • Parent commits 45f2780

Comments (0)

Files changed (6)

 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.
 
 

doc/ext/appapi.rst

 
    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
 

sphinx/application.py

 
     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

sphinx/builders/html.py

 
         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

tests/root/conf.py

     app.add_directive('clsdir', ClassDirective)
     app.add_object_type('userdesc', 'userdescrole', '%s (userdesc)',
                         userdesc_parse, objname='user desc')
+    app.add_javascript('file://moo.js')

tests/test_build_html.py

         (".//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"),