summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-01-20 16:11:20 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-01-20 16:11:20 +0100
commit38d91ef3494d97479d3d796ac54ae86c48b4be42 (patch)
treed55eac8ac7e284a04aea4b664a274afe337acc40
parent288602cc2bedd17731dbc44d70711b8942c23164 (diff)
downloaddocs-38d91ef3494d97479d3d796ac54ae86c48b4be42.tar.gz
docs-38d91ef3494d97479d3d796ac54ae86c48b4be42.tar.bz2
docs-38d91ef3494d97479d3d796ac54ae86c48b4be42.zip
Allow separate target/caption for in-comment links
-rw-r--r--exts/tsref.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/exts/tsref.py b/exts/tsref.py
index c8a114d7..da575d7a 100644
--- a/exts/tsref.py
+++ b/exts/tsref.py
@@ -56,8 +56,10 @@ class LinkingHtmlFormatter(HtmlFormatter):
def _fmt(self, value, tok):
cls = self._get_css_class(tok)
href = tok_getprop(tok, "href")
+ caption = tok_getprop(tok, "caption")
+ content = caption if caption is not None else value
if href:
- value = '<a style="color:inherit;text-decoration:underline" href="%s">%s</a>' % (href, value)
+ value = '<a style="color:inherit;text-decoration:underline" href="%s">%s</a>' % (href, content)
if cls is None or cls == "":
return value
return '<span class="%s">%s</span>' % (cls, value)
@@ -149,7 +151,7 @@ def tok_getprop(tok, key):
return kv.get(key)
-link_reg = re.compile(r"`([^`]+)`_")
+link_reg = re.compile(r"`([^`<]+)\s*(?:<([^>]+)>)?\s*`_")
# Map from token id to props.
# Properties can't be added to tokens
@@ -184,11 +186,18 @@ class LinkFilter(Filter):
if pre:
yield ttype, pre
t = copy_token(ttype)
- id = make_id(m.group(1))
+ x1, x2 = m.groups()
+ if x2 is None:
+ caption = x1.strip()
+ id = make_id(x1)
+ else:
+ caption = x1.strip()
+ id = make_id(x2)
if id in id_to_doc:
docname = id_to_doc[id]
href = self.app.builder.get_target_uri(docname) + "#" + id
tok_setprop(t, "href", href)
+ tok_setprop(t, "caption", caption)
else:
self.app.builder.warn("unresolved link target in comment: " + id)
yield t, m.group(1)