Merge lp:~khorn/pydoctor/sphinxext into lp:~mwhudson/pydoctor/dev

Proposed by Kevin Horn
Status: Merged
Merged at revision: 571
Proposed branch: lp:~khorn/pydoctor/sphinxext
Merge into: lp:~mwhudson/pydoctor/dev
Diff against target: 54 lines (+49/-0)
1 file modified
apilinks_sphinxext.py (+49/-0)
To merge this branch: bzr merge lp:~khorn/pydoctor/sphinxext
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Pending
Review via email: mp+53362@code.launchpad.net

Description of the change

Because links to api docs are good.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'apilinks_sphinxext.py'
--- apilinks_sphinxext.py 1970-01-01 00:00:00 +0000
+++ apilinks_sphinxext.py 2011-03-15 03:30:35 +0000
@@ -0,0 +1,49 @@
1'''
2Sphinx/docutils extension to create links to pyDoctor documentation using
3a RestructuredText interpreted text role that looks like this:
4
5 :api:`python_object_to_link_to <label>`
6
7for example:
8
9 :api:`twisted.internet.defer.Deferred <Deferred>`
10'''
11
12
13
14def make_api_link(name, rawtext, text, lineno, inliner,
15 options={}, content=[]):
16
17 from docutils import nodes, utils
18
19 # quick, dirty, and ugly...
20 if '<' in text and '>' in text:
21 full_name, label = text.split('<')
22 full_name = full_name.strip()
23 label = label.strip('>').strip()
24 else:
25 full_name = text
26
27 #get the base url for api links from the config file
28 env = inliner.document.settings.env
29 base_url = env.config.apilinks_base_url
30
31 # not really sufficient, but just testing...
32 # ...hmmm, maybe this is good enough after all
33 ref = ''.join((base_url, full_name, '.html'))
34
35 node = nodes.reference(rawtext, utils.unescape(label), refuri=ref,
36 **options)
37
38 nodes = [node]
39 sys_msgs = []
40 return nodes, sys_msgs
41
42
43# setup function to register the extension
44
45def setup(app):
46 app.add_config_value('apilinks_base_url',
47 'http://twistedmatrix.com/documents/current/api/',
48 'env')
49 app.add_role('api', make_api_link)
0\ No newline at end of file50\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: