From a4fee155567555a3e62ba04a50117ae36fabc114 Mon Sep 17 00:00:00 2001 From: tpowers Date: Mon, 26 Apr 2010 20:33:06 -0700 Subject: [PATCH 1/5] Added "link outside" and "link inside" classes to reference nodes. Distinguishes hyperlinks that are outside of current sphinx hierarchy. --- sphinx/environment.py | 15 +++++++- sphinx/themes/default/static/default.css_t | 45 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) 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, From 034de58736212c6f5de2a0d54c498e7e796da136 Mon Sep 17 00:00:00 2001 From: tpowers Date: Mon, 26 Apr 2010 23:02:18 -0700 Subject: [PATCH 2/5] Indicate "accelerator" key of menu & gui items via ampersand. Accelerator(s) will be underlined within :menuselection: and :guilabel:. --- sphinx/roles.py | 31 ++++++++++++++++++++++------ sphinx/themes/basic/static/basic.css | 28 ++++++++++++++++++------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/sphinx/roles.py b/sphinx/roles.py index 76ec311de..0e1c7fda6 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -36,7 +36,6 @@ for rolename, nodeclass in generic_docroles.iteritems(): simple_docroles = [ 'command', 'dfn', - 'guilabel', 'kbd', 'makevar', 'program', @@ -217,12 +216,31 @@ def indexmarkup_role(typ, rawtext, etext, lineno, inliner, return [indexnode, targetnode, rn], [] -def menusel_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): - return [nodes.emphasis( - rawtext, utils.unescape(text).replace('-->', u'\N{TRIANGULAR BULLET}'), - classes=[typ])], [] - return role +_amp_re = re.compile(r'&(?![&\s])') +def menusel_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): + if typ == 'menuselection': + text = utils.unescape(text).replace('-->', u'\N{TRIANGULAR BULLET}') + spans = _amp_re.split(text) + + node = nodes.inline(rawtext=rawtext) + for i, span in enumerate(spans): + span = span.replace('&&', '&') + if i == 0: + if len(span) > 0: + textnode = nodes.Text(span) + node += textnode + continue + underline_node = nodes.inline() + letter_node = nodes.Text(span[0]) + underline_node += letter_node + underline_node['classes'].append('underline') + node += underline_node + textnode = nodes.Text(span[1:]) + node += textnode + + node['classes'].append(typ) + return [node], [] _litvar_re = re.compile('{([^}]+)}') @@ -266,6 +284,7 @@ specific_docroles = { 'pep': indexmarkup_role, 'rfc': indexmarkup_role, + 'guilabel': menusel_role, 'menuselection': menusel_role, 'file': emph_literal_role, 'samp': emph_literal_role, diff --git a/sphinx/themes/basic/static/basic.css b/sphinx/themes/basic/static/basic.css index 9cd07bb30..a01278410 100644 --- a/sphinx/themes/basic/static/basic.css +++ b/sphinx/themes/basic/static/basic.css @@ -369,25 +369,37 @@ dl.glossary dt { } .command, -.guilabel, .makevar, .program { - font-weight: bold; + font-weight: bold; } .kbd, .regexp { - font-family: monospace; - white-space: pre-wrap; - background-color: #ecf0f3; - padding: 0 1px 0 1px; - font-size: 0.95em; + font-family: monospace; + white-space: pre-wrap; + background-color: #ecf0f3; + padding: 0 1px 0 1px; + font-size: 0.95em; } .dfn { - font-style: italic; + font-style: italic; +} + +.guilabel { + font-weight: bold; +} + +.menuselection { + font-style: italic; + font-weight: bold; +} + +.underline { + text-decoration: underline; } /* -- code displays --------------------------------------------------------- */ From 93141d3eca2d92065d1b296fdc4ce86727ab132f Mon Sep 17 00:00:00 2001 From: tpowers Date: Tue, 27 Apr 2010 00:36:24 -0700 Subject: [PATCH 3/5] :menuselection: and :guilabel: look better with sans-serif font. --- sphinx/themes/basic/static/basic.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sphinx/themes/basic/static/basic.css b/sphinx/themes/basic/static/basic.css index a01278410..e0aef71e8 100644 --- a/sphinx/themes/basic/static/basic.css +++ b/sphinx/themes/basic/static/basic.css @@ -390,10 +390,12 @@ dl.glossary dt { } .guilabel { + font-family: sans-serif; font-weight: bold; } .menuselection { + font-family: sans-serif; font-style: italic; font-weight: bold; } From 52ba45f45832edce7ad343fc9265aa2f349b77c3 Mon Sep 17 00:00:00 2001 From: tpowers Date: Tue, 27 Apr 2010 13:47:55 -0700 Subject: [PATCH 4/5] Make test for "outside" references case insensitive. --- sphinx/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/environment.py b/sphinx/environment.py index 8cca084fb..27ed93cf4 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -176,7 +176,7 @@ class CategorizeReferences(Transform): for reference in self.document.traverse(nodes.reference): if reference.hasattr('refuri'): refuri = reference['refuri'] - if re.match(r"(?:http|https|ftp)://", refuri): + if re.match(r"(?i)(?:http|https|ftp)://", refuri): classes = ("link", "outside") else: classes = ("link", "inside") From 0301dccddaaaf0615e3d8df47a744a437fa5d355 Mon Sep 17 00:00:00 2001 From: tpowers Date: Tue, 27 Apr 2010 20:09:11 -0700 Subject: [PATCH 5/5] Rename "underline" class to accelerator to preserve separation of semantics & presentation. --- sphinx/roles.py | 9 +++++---- sphinx/themes/basic/static/basic.css | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sphinx/roles.py b/sphinx/roles.py index 0e1c7fda6..0f3eaf14a 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -1,3 +1,4 @@ + # -*- coding: utf-8 -*- """ sphinx.roles @@ -231,11 +232,11 @@ def menusel_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): textnode = nodes.Text(span) node += textnode continue - underline_node = nodes.inline() + accel_node = nodes.inline() letter_node = nodes.Text(span[0]) - underline_node += letter_node - underline_node['classes'].append('underline') - node += underline_node + accel_node += letter_node + accel_node['classes'].append('accelerator') + node += accel_node textnode = nodes.Text(span[1:]) node += textnode diff --git a/sphinx/themes/basic/static/basic.css b/sphinx/themes/basic/static/basic.css index e0aef71e8..e78109f4d 100644 --- a/sphinx/themes/basic/static/basic.css +++ b/sphinx/themes/basic/static/basic.css @@ -400,7 +400,7 @@ dl.glossary dt { font-weight: bold; } -.underline { +.accelerator { text-decoration: underline; }