bootstrap-vz/docs/replace_rtd_links.py
Anders Ingemann 6980dd6517 Add sphinx extension that replaces absolut RTD urls
This makes it possible to add proper links when showing an rst on github,
while also resolving it to relative links on readthedocs
2015-04-12 14:33:04 +02:00

19 lines
519 B
Python

def setup(app):
app.connect('doctree-resolved', replace_rtd_links)
return {'version': '0.1'}
def replace_rtd_links(app, doctree, fromdocname):
from docutils import nodes
import re
rtd_baseurl = 'http://bootstrap-vz.readthedocs.org/en/master/'
search = re.compile('^' + re.escape(rtd_baseurl) + '(.*)$')
for node in doctree.traverse(nodes.reference):
if 'refuri' not in node:
continue
if not node['refuri'].startswith(rtd_baseurl):
continue
node['refuri'] = re.sub(search, r'\1', node['refuri'])