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

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: