Skip to content
This repository was archived by the owner on Apr 18, 2018. It is now read-only.

Commit 483cab2

Browse files
committed
allow explicit titles for filelinks
1 parent e720e29 commit 483cab2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

doc/_extensions/mitgcm.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
from docutils import nodes
1+
from docutils import nodes, utils
2+
3+
from sphinx.util.nodes import split_explicit_title
4+
25

36
def setup(app):
4-
app.add_role('filelink', autolink('https://github.com/altMITgcm/MITgcm/blob/master/%s'))
7+
app.add_role('filelink', filelink('https://github.com/altMITgcm/MITgcm/blob/master/%s'))
58
app.add_role('varlink', autolink('http://mitgcm.org/lxr/ident/MITgcm?_i=%s'))
69

10+
def filelink(pattern):
11+
def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
12+
text = utils.unescape(text)
13+
has_explicit_title, title, part = split_explicit_title(text)
14+
if not has_explicit_title and part[:1] == '~':
15+
part = part[1:]
16+
title = part.split('/')[-1]
17+
url = pattern % (part,)
18+
node = nodes.reference(rawtext, title, refuri=url, **options)
19+
return [node], []
20+
return role
21+
722
def autolink(pattern):
823
def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
924
url = pattern % (text,)

0 commit comments

Comments
 (0)