summaryrefslogtreecommitdiff
path: root/sphinx/ext/extlinks.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-01-02 20:51:22 +0100
committerGeorg Brandl <georg@python.org>2010-01-02 20:51:22 +0100
commit6b13a28c1152b014a4e7d0ac27f8f5b960be3d75 (patch)
tree0b1e5d935f0f9daa0b97e75ad6a5647bbd01da69 /sphinx/ext/extlinks.py
parent32437e45bd3c0b47349c7eee582ec61e693cf243 (diff)
downloadsphinx-git-6b13a28c1152b014a4e7d0ac27f8f5b960be3d75.tar.gz
Make extlinks more flexible: use string substitution to build the full URL.
Diffstat (limited to 'sphinx/ext/extlinks.py')
-rw-r--r--sphinx/ext/extlinks.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py
index 7a1c32f73..423b6447e 100644
--- a/sphinx/ext/extlinks.py
+++ b/sphinx/ext/extlinks.py
@@ -8,10 +8,10 @@
This adds a new config value called ``extlinks`` that is created like this::
- extlinks = {'exmpl': ('http://example.com/', prefix), ...}
+ extlinks = {'exmpl': ('http://example.com/%s.html', prefix), ...}
Now you can use e.g. :exmpl:`foo` in your documents. This will create a
- link to ``http://example.com/foo``. The link caption depends on the
+ link to ``http://example.com/foo.html``. The link caption depends on the
*prefix* value given:
- If it is ``None``, the caption will be the full URL.
@@ -32,15 +32,20 @@ from sphinx.util import split_explicit_title
def make_link_role(base_url, prefix):
def role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
text = utils.unescape(text)
- has_explicit_title, title, url = split_explicit_title(text)
- # NOTE: not using urlparse.urljoin() here, to allow something like
- # base_url = 'bugs.python.org/issue' and url = '1024'
- full_url = base_url + url
+ has_explicit_title, title, part = split_explicit_title(text)
+ try:
+ full_url = base_url % part
+ except (TypeError, ValueError):
+ env = inliner.document.settings.env
+ env.warn(env.docname, 'unable to expand %s extlink with base '
+ 'URL %r, please make sure the base contains \'%%s\' '
+ 'exactly once' % (typ, base_url))
+ full_url = base_url + part
if not has_explicit_title:
if prefix is None:
title = full_url
else:
- title = prefix + url
+ title = prefix + part
pnode = nodes.reference(title, title, refuri=full_url)
return [pnode], []
return role