mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
In HTML output, inline roles now get a CSS class with their name,
allowing styles to customize their appearance. Domain-specific roles get two classes, ``domain`` and ``domain-rolename``.
This commit is contained in:
4
CHANGES
4
CHANGES
@@ -10,6 +10,10 @@ Release 1.0 (in development)
|
||||
|
||||
* Added a manual page builder.
|
||||
|
||||
* In HTML output, inline roles now get a CSS class with their name,
|
||||
allowing styles to customize their appearance. Domain-specific
|
||||
roles get two classes, ``domain`` and ``domain-rolename``.
|
||||
|
||||
* New more compact doc field syntax is now recognized:
|
||||
``:param type name: description``.
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ generic_docroles = {
|
||||
}
|
||||
|
||||
for rolename, nodeclass in generic_docroles.iteritems():
|
||||
role = roles.GenericRole(rolename, nodeclass)
|
||||
generic = roles.GenericRole(rolename, nodeclass)
|
||||
role = roles.CustomRole(rolename, generic, {'classes': [rolename]})
|
||||
roles.register_local_role(rolename, role)
|
||||
|
||||
|
||||
@@ -102,12 +103,13 @@ class XRefRole(object):
|
||||
domain, role = '', typ
|
||||
else:
|
||||
domain, role = typ.split(':', 1)
|
||||
classes = ['xref', domain, '%s-%s' % (domain, role)]
|
||||
text = utils.unescape(text)
|
||||
# if the first character is a bang, don't cross-reference at all
|
||||
if text[0:1] == '!':
|
||||
if self.fix_parens:
|
||||
text, tgt = self._fix_parens(env, False, text[1:], "")
|
||||
innernode = self.innernodeclass(rawtext, text, classes=['xref'])
|
||||
innernode = self.innernodeclass(rawtext, text, classes=classes)
|
||||
return self.result_nodes(inliner.document, env, innernode,
|
||||
is_ref=False)
|
||||
# split title and target in role content
|
||||
@@ -127,7 +129,7 @@ class XRefRole(object):
|
||||
env, refnode, has_explicit_title, title, target)
|
||||
# now that the target and title are finally determined, set them
|
||||
refnode['reftarget'] = target
|
||||
refnode += self.innernodeclass(rawtext, title, classes=['xref'])
|
||||
refnode += self.innernodeclass(rawtext, title, classes=classes)
|
||||
# we also need the source document
|
||||
refnode['refdoc'] = env.docname
|
||||
# result_nodes allow further modification of return values
|
||||
@@ -179,7 +181,7 @@ def indexmarkup_role(typ, rawtext, etext, lineno, inliner,
|
||||
return [prb], [msg]
|
||||
ref = inliner.document.settings.pep_base_url + 'pep-%04d' % pepnum
|
||||
sn = nodes.strong('PEP '+text, 'PEP '+text)
|
||||
rn = nodes.reference('', '', refuri=ref)
|
||||
rn = nodes.reference('', '', refuri=ref, classes=[typ])
|
||||
rn += sn
|
||||
return [indexnode, targetnode, rn], []
|
||||
elif typ == 'rfc':
|
||||
@@ -194,15 +196,15 @@ def indexmarkup_role(typ, rawtext, etext, lineno, inliner,
|
||||
return [prb], [msg]
|
||||
ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum
|
||||
sn = nodes.strong('RFC '+text, 'RFC '+text)
|
||||
rn = nodes.reference('', '', refuri=ref)
|
||||
rn = nodes.reference('', '', refuri=ref, classes=[typ])
|
||||
rn += sn
|
||||
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}'))], []
|
||||
rawtext, utils.unescape(text).replace('-->', u'\N{TRIANGULAR BULLET}'),
|
||||
classes=[typ])], []
|
||||
return role
|
||||
|
||||
|
||||
@@ -212,7 +214,7 @@ def emph_literal_role(typ, rawtext, text, lineno, inliner,
|
||||
options={}, content=[]):
|
||||
text = utils.unescape(text)
|
||||
pos = 0
|
||||
retnode = nodes.literal(role=typ.lower())
|
||||
retnode = nodes.literal(role=typ.lower(), classes=[typ])
|
||||
for m in _litvar_re.finditer(text):
|
||||
if m.start() > pos:
|
||||
txt = text[pos:m.start()]
|
||||
|
||||
@@ -80,26 +80,26 @@ def verify(rst, html_expected, latex_expected):
|
||||
|
||||
def test_inline():
|
||||
# correct interpretation of code with whitespace
|
||||
_html = ('<p><tt class="docutils literal"><span class="pre">'
|
||||
_html = ('<p><tt class="(samp )?docutils literal"><span class="pre">'
|
||||
'code</span> <span class="pre">sample</span></tt></p>')
|
||||
yield verify, '``code sample``', _html, '\\code{code sample}'
|
||||
yield verify, ':samp:`code sample`', _html, '\\samp{code sample}'
|
||||
yield verify_re, '``code sample``', _html, r'\\code{code sample}'
|
||||
yield verify_re, ':samp:`code sample`', _html, r'\\samp{code sample}'
|
||||
|
||||
# interpolation of braces in samp and file roles (HTML only)
|
||||
yield (verify, ':samp:`a{b}c`',
|
||||
'<p><tt class="docutils literal"><span class="pre">a</span>'
|
||||
'<p><tt class="samp docutils literal"><span class="pre">a</span>'
|
||||
'<em><span class="pre">b</span></em>'
|
||||
'<span class="pre">c</span></tt></p>',
|
||||
'\\samp{abc}')
|
||||
|
||||
# interpolation of arrows in menuselection
|
||||
yield (verify, ':menuselection:`a --> b`',
|
||||
u'<p><em>a \N{TRIANGULAR BULLET} b</em></p>',
|
||||
u'<p><em class="menuselection">a \N{TRIANGULAR BULLET} b</em></p>',
|
||||
'\\emph{a \\(\\rightarrow\\) b}')
|
||||
|
||||
# non-interpolation of dashes in option role
|
||||
yield (verify_re, ':option:`--with-option`',
|
||||
'<p><em( class="xref")?>--with-option</em></p>$',
|
||||
'<p><em( class="xref std-option")?>--with-option</em></p>$',
|
||||
r'\\emph{\\texttt{-{-}with-option}}$')
|
||||
|
||||
# verify smarty-pants quotes
|
||||
@@ -110,6 +110,11 @@ def test_inline():
|
||||
'"John"</span></tt></p>',
|
||||
'\\code{"John"}')
|
||||
|
||||
# verify classes for inline roles
|
||||
yield (verify, ':manpage:`mp(1)`',
|
||||
'<p><em class="manpage">mp(1)</em></p>',
|
||||
'\\emph{\\texttt{mp(1)}}')
|
||||
|
||||
def test_latex_escaping():
|
||||
# correct escaping in normal mode
|
||||
yield (verify, u'Γ\\\\∞$', None,
|
||||
|
||||
Reference in New Issue
Block a user