Added "link outside" and "link inside" classes to reference nodes.

Distinguishes hyperlinks that are outside of current sphinx hierarchy.
This commit is contained in:
tpowers 2010-04-26 20:33:06 -07:00
parent 482720cf65
commit a4fee15556
2 changed files with 58 additions and 2 deletions

View File

@ -168,13 +168,26 @@ class CitationReferences(Transform):
refnode += nodes.Text('[' + cittext + ']')
citnode.parent.replace(citnode, refnode)
class CategorizeReferences(Transform):
"""Categorize references (hyperlinks) as link outside or link inside"""
default_priority = 619
def apply(self):
for reference in self.document.traverse(nodes.reference):
if reference.hasattr('refuri'):
refuri = reference['refuri']
if re.match(r"(?:http|https|ftp)://", refuri):
classes = ("link", "outside")
else:
classes = ("link", "inside")
reference["classes"].extend(classes)
class SphinxStandaloneReader(standalone.Reader):
"""
Add our own transforms.
"""
transforms = [CitationReferences, DefaultSubstitutions, MoveModuleTargets,
HandleCodeBlocks, SortIds]
HandleCodeBlocks, SortIds, CategorizeReferences]
def get_transforms(self):
return standalone.Reader.get_transforms(self) + self.transforms

View File

@ -147,7 +147,8 @@ div.sphinxsidebar input {
font-size: 1em;
}
/* -- body styles ----------------------------------------------------------- */
/* -- hyperlink styles ------------------------------------------------------ */
a {
color: {{ theme_linkcolor }};
@ -163,6 +164,48 @@ a:hover {
text-decoration: underline;
}
div.toctree-wrapper a,
div.toctree-wrapper a:visited,
div#indices-and-tables a,
div#indices-and-tables a:visited,
div.sphinxsidebar a,
div.sphinxsidebar a:visited,
div.related a,
div.related a:visited {
text-decoration: none;
}
div.toctree-wrapper a:hover,
div#indices-and-tables a:hover,
div.sphinxsidebar a:hover,
div.related a:hover {
text-decoration: underline;
}
a.link.outside {
text-decoration: none;
border-bottom: 1px dashed {{ theme_linkcolor }};
}
a.link.outside:hover {
text-decoration: none;
border-bottom: none;
}
/* To distinguish between internal & external references uncomment following */
/*
a.reference,
a.reference em {
font-style: normal;
}
a.reference.internal em {
font-style: italic;
}
*/
/* -- body styles ----------------------------------------------------------- */
div.body h1,
div.body h2,
div.body h3,