Skip to content

Commit 700be73

Browse files
committed
Added :issue: role to link github issues
1 parent 9b04e05 commit 700be73

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

docs/_ext/github.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Sphinx helper for github issue references
2+
from docutils import nodes
3+
from docutils.parsers.rst.roles import set_classes
4+
5+
ISSUE_URL = 'https://github.com/{owner}/{repo}/issues/{num}'
6+
7+
def github_issue_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
8+
try:
9+
issuenum = int(text)
10+
if issuenum <= 0:
11+
raise ValueError()
12+
except ValueError:
13+
msg = inliner.reporter.error(
14+
'Issuse number must be a strictly positive integer. Number "%s" '
15+
'is invalid.' % text, line=lineno)
16+
prb = inliner.problematic(rawtext, rawtext, msg)
17+
return [prb], [msg]
18+
19+
ref = ISSUE_URL.format(
20+
owner = inliner.document.settings.env.config['github_owner'],
21+
repo = inliner.document.settings.env.config['github_repo'],
22+
num = issuenum,
23+
)
24+
set_classes(options)
25+
node = nodes.reference(rawtext, '#%d' % issuenum, refuri=ref, **options)
26+
return [node], []
27+
28+
def setup(app):
29+
app.add_config_value('github_owner', None, 'html')
30+
app.add_config_value('github_repo', None, 'html')
31+
app.add_role('issue', github_issue_role)

docs/conf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
# If extensions (or modules to document with autodoc) are in another directory,
1717
# add these directories to sys.path here. If the directory is relative to the
1818
# documentation root, use os.path.abspath to make it absolute, like shown here.
19-
#sys.path.insert(0, os.path.abspath('.'))
19+
20+
sys.path.extend((
21+
os.path.abspath(os.path.join(os.path.dirname(__file__), '_ext')),
22+
))
2023

2124
# -- General configuration -----------------------------------------------------
2225

@@ -25,7 +28,7 @@
2528

2629
# Add any Sphinx extension module names here, as strings. They can be extensions
2730
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
28-
extensions = ['sphinx.ext.intersphinx']
31+
extensions = ['sphinx.ext.intersphinx', 'github']
2932
intersphinx_mapping = {
3033
'python': ('http://docs.python.org/2.6', None),
3134
'django': ('http://readthedocs.org/docs/django/en/latest/', None),
@@ -218,3 +221,9 @@
218221
('index', 'project', u'Django Hvad Documentation',
219222
[u'Kristian Øllegaard, Jonas Obrist & contributors'], 1)
220223
]
224+
225+
# -- Options for local extensions ----------------------------------------------
226+
227+
github_owner = 'KristianOellegaard'
228+
github_repo = 'django-hvad'
229+

0 commit comments

Comments
 (0)