Role `numref uses %s as special character instead #` symbol

This commit is contained in:
Takeshi KOMIYA 2015-03-08 07:57:05 +09:00
parent 3d62e353a5
commit 5e48ac9b4f
6 changed files with 15 additions and 16 deletions

View File

@ -6,6 +6,8 @@ Incompatible changes
* Roles ``ref``, ``term`` and ``menusel`` now don't generate :durole:`emphasis`
nodes anymore. If you want to keep italic style, adapt your stylesheet.
* Role ``numref`` uses ``%s`` as special character to indicate position of
figure numbers instead ``#`` symbol.
Features added
--------------

View File

@ -212,9 +212,9 @@ Cross-referencing figures by figure number
labels are used. When you use this role, it will insert a reference to the
figure with link text by its figure number like "Fig. 1.1".
If an explicit link text is given (like usual: ``:doc:`Image of Sphinx (Fig.
#) <my-figure>```), the link caption will be the title of the reference.
As a special character, `#` will be replaced to figure number.
If an explicit link text is given (like usual: ``:numref:`Image of Sphinx (Fig.
%s) <my-figure>```), the link caption will be the title of the reference.
As a special character, `%s` will be replaced to figure number.
If :confval:`numfig` is ``False``, figures are not numbered.
so this role inserts not a reference but labels or link text.

View File

@ -638,12 +638,9 @@ class StandardDomain(Domain):
title = contnode.astext()
if target == fully_normalize_name(title):
prefix = env.config.numfig_format.get(figtype, '')
title = prefix.replace('%s', '#')
newtitle = prefix % '.'.join(map(str, fignumber))
else:
newtitle = title.replace('#', '.'.join(map(str, fignumber)))
title = env.config.numfig_format.get(figtype, '')
newtitle = title % '.'.join(map(str, fignumber))
return self.build_reference_node(fromdocname, builder,
docname, labelid, newtitle,
nodeclass=addnodes.number_reference,

View File

@ -1350,8 +1350,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
id = node.get('refuri', '')[1:].replace('#', ':')
ref = '\\ref{%s}' % self.idescape(id)
title = text_type(node.get('title', '#')).translate(tex_escape_map)
hyperref = '\\hyperref[%s]{%s}' % (self.idescape(id), title.replace('\\#', ref))
title = text_type(node.get('title', '%s')).translate(tex_escape_map).replace('\\%s', '%s')
hyperref = '\\hyperref[%s]{%s}' % (self.idescape(id), title % ref)
self.body.append(hyperref)
raise nodes.SkipNode

View File

@ -43,8 +43,8 @@ test-tocdepth
* Fig.1 is :numref:`fig1`
* Fig.2.2 is :numref:`Figure# <fig22>`
* Fig.2.2 is :numref:`Figure%s <fig22>`
* Table.1 is :numref:`table-1`
* Table.2.2 is :numref:`Table:# <table22>`
* Table.2.2 is :numref:`Table:%s <table22>`
* List.1 is :numref:`CODE_1`
* List.2.2 is :numref:`Code-# <CODE22>`
* List.2.2 is :numref:`Code-%s <CODE22>`

View File

@ -489,11 +489,11 @@ def test_numfig_disabled(app, status, warning):
(".//div[@class='code-block-caption']/"
"span[@class='caption-number']", None, True),
(".//li/code/span", '^fig1$', True),
(".//li/code/span", '^Figure#$', True),
(".//li/code/span", '^Figure%s$', True),
(".//li/code/span", '^table-1$', True),
(".//li/code/span", '^Table:#$', True),
(".//li/code/span", '^Table:%s$', True),
(".//li/code/span", '^CODE_1$', True),
(".//li/code/span", '^Code-#$', True),
(".//li/code/span", '^Code-%s$', True),
],
'foo.html': [
(".//div[@class='figure']/p[@class='caption']/"