diff --git a/sphinx/environment.py b/sphinx/environment.py index c4649ae83..8cca084fb 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -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 diff --git a/sphinx/themes/default/static/default.css_t b/sphinx/themes/default/static/default.css_t index 579f57a4c..8c44f1ef2 100644 --- a/sphinx/themes/default/static/default.css_t +++ b/sphinx/themes/default/static/default.css_t @@ -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,