mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merged in tk0miya/sphinx (pull request #304)
numfig feature improvement
This commit is contained in:
commit
6c0b4f1933
@ -97,7 +97,10 @@ h3:hover > a.headerlink,
|
||||
h4:hover > a.headerlink,
|
||||
h5:hover > a.headerlink,
|
||||
h6:hover > a.headerlink,
|
||||
dt:hover > a.headerlink {
|
||||
dt:hover > a.headerlink,
|
||||
caption:hover > a.headerlink,
|
||||
p.caption:hover > a.headerlink,
|
||||
div.code-block-caption:hover > a.headerlink {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,10 @@ h3:hover > a.headerlink,
|
||||
h4:hover > a.headerlink,
|
||||
h5:hover > a.headerlink,
|
||||
h6:hover > a.headerlink,
|
||||
dt:hover > a.headerlink {
|
||||
dt:hover > a.headerlink,
|
||||
caption:hover > a.headerlink,
|
||||
p.caption:hover > a.headerlink,
|
||||
div.code-block-caption:hover > a.headerlink {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,10 @@ h4:hover > a.headerlink,
|
||||
h5:hover > a.headerlink,
|
||||
h6:hover > a.headerlink,
|
||||
dt:hover > a.headerlink,
|
||||
dt:hover > a.headerlink {
|
||||
dt:hover > a.headerlink,
|
||||
caption:hover > a.headerlink,
|
||||
p.caption:hover > a.headerlink,
|
||||
div.code-block-caption:hover > a.headerlink {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,7 @@ class HTMLTranslator(BaseTranslator):
|
||||
and node['ids'] and node['first']:
|
||||
self.body.append('<!--[%s]-->' % node['ids'][0])
|
||||
def depart_desc_signature(self, node):
|
||||
if node['ids'] and self.permalink_text and self.builder.add_permalinks:
|
||||
self.body.append(u'<a class="headerlink" href="#%s" '
|
||||
% node['ids'][0] +
|
||||
u'title="%s">%s</a>' % (
|
||||
_('Permalink to this definition'),
|
||||
self.permalink_text))
|
||||
self.add_permalink_ref(node, 'definition')
|
||||
self.body.append('</dt>\n')
|
||||
|
||||
def visit_desc_addname(self, node):
|
||||
@ -253,9 +248,11 @@ class HTMLTranslator(BaseTranslator):
|
||||
def add_fignumber(self, node):
|
||||
def append_fignumber(figtype, figure_id):
|
||||
if figure_id in self.builder.fignumbers.get(figtype, {}):
|
||||
self.body.append(self.starttag(node, 'span', '', CLASS='caption-number'))
|
||||
prefix = self.builder.config.numfig_prefix.get(figtype, '')
|
||||
numbers = self.builder.fignumbers[figtype][figure_id]
|
||||
self.body.append(prefix + '.'.join(map(str, numbers)) + " ")
|
||||
self.body.append('</span>')
|
||||
|
||||
if isinstance(node.parent, nodes.figure):
|
||||
append_fignumber('figure', node.parent['ids'][0])
|
||||
@ -264,6 +261,12 @@ class HTMLTranslator(BaseTranslator):
|
||||
elif isinstance(node.parent, nodes.container):
|
||||
append_fignumber('code-block', node.parent['ids'][0])
|
||||
|
||||
def add_permalink_ref(self, node, typename):
|
||||
if node['ids'] and self.permalink_text and self.builder.add_permalinks:
|
||||
title = _('Permalink to this %s' % typename)
|
||||
format = u'<a class="headerlink" href="#%s" title="%s">%s</a>'
|
||||
self.body.append(format % (node['ids'][0], title, self.permalink_text))
|
||||
|
||||
# overwritten to avoid emitting empty <ul></ul>
|
||||
def visit_bullet_list(self, node):
|
||||
if len(node) == 1 and node[0].tagname == 'toctree':
|
||||
@ -275,6 +278,8 @@ class HTMLTranslator(BaseTranslator):
|
||||
BaseTranslator.visit_title(self, node)
|
||||
self.add_secnumber(node)
|
||||
self.add_fignumber(node)
|
||||
if isinstance(node.parent, nodes.table):
|
||||
self.body.append(self.starttag(node, 'span', '', CLASS='caption-text'))
|
||||
|
||||
# overwritten
|
||||
def visit_literal_block(self, node):
|
||||
@ -307,8 +312,17 @@ class HTMLTranslator(BaseTranslator):
|
||||
else:
|
||||
BaseTranslator.visit_caption(self, node)
|
||||
self.add_fignumber(node)
|
||||
self.body.append(self.starttag(node, 'span', '', CLASS='caption-text'))
|
||||
|
||||
def depart_caption(self, node):
|
||||
self.body.append('</span>')
|
||||
|
||||
# append permalink if available
|
||||
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
||||
self.add_permalink_ref(node.parent, 'code')
|
||||
elif isinstance(node.parent, nodes.figure):
|
||||
self.add_permalink_ref(node.parent, 'image')
|
||||
|
||||
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
||||
self.body.append('</div>\n')
|
||||
else:
|
||||
@ -575,20 +589,19 @@ class HTMLTranslator(BaseTranslator):
|
||||
def depart_title(self, node):
|
||||
close_tag = self.context[-1]
|
||||
if (self.permalink_text and self.builder.add_permalinks and
|
||||
node.parent.hasattr('ids') and node.parent['ids']):
|
||||
aname = node.parent['ids'][0]
|
||||
node.parent.hasattr('ids') and node.parent['ids']):
|
||||
# add permalink anchor
|
||||
if close_tag.startswith('</h'):
|
||||
self.body.append(u'<a class="headerlink" href="#%s" ' % aname +
|
||||
u'title="%s">%s</a>' % (
|
||||
_('Permalink to this headline'),
|
||||
self.permalink_text))
|
||||
self.add_permalink_ref(node.parent, 'headline')
|
||||
elif close_tag.startswith('</a></h'):
|
||||
self.body.append(u'</a><a class="headerlink" href="#%s" ' %
|
||||
aname +
|
||||
node.parent['ids'][0] +
|
||||
u'title="%s">%s' % (
|
||||
_('Permalink to this headline'),
|
||||
self.permalink_text))
|
||||
elif isinstance(node.parent, nodes.table):
|
||||
self.body.append('</span>')
|
||||
self.add_permalink_ref(node.parent, 'table')
|
||||
|
||||
BaseTranslator.depart_title(self, node)
|
||||
|
||||
|
@ -305,8 +305,13 @@ class NslessParser(ET.XMLParser):
|
||||
|
||||
def check_xpath(etree, fname, path, check, be_found=True):
|
||||
nodes = list(etree.findall(path))
|
||||
assert nodes != [], ('did not find any node matching xpath '
|
||||
'%r in file %s' % (path, fname))
|
||||
if check is None:
|
||||
assert nodes == [], ('found any nodes matching xpath '
|
||||
'%r in file %s' % (path, fname))
|
||||
return
|
||||
else:
|
||||
assert nodes != [], ('did not find any node matching xpath '
|
||||
'%r in file %s' % (path, fname))
|
||||
if hasattr(check, '__call__'):
|
||||
check(nodes)
|
||||
elif not check:
|
||||
@ -464,62 +469,32 @@ def test_numfig(app, status, warning):
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.2$', True),
|
||||
(".//table/caption", '^should be Table 1$', True),
|
||||
(".//table/caption", '^should be Table 2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
(".//table/caption/span[@class='caption-number']", None, True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.1.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.1.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.1.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.1.4$', True),
|
||||
(".//table/caption", '^should be Table 1.1$', True),
|
||||
(".//table/caption", '^should be Table 1.2$', True),
|
||||
(".//table/caption", '^should be Table 1.3$', True),
|
||||
(".//table/caption", '^should be Table 1.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 1.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 1.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 1.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 1.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
(".//table/caption/span[@class='caption-number']", None, True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.2.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.2.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.2.4$', True),
|
||||
(".//table/caption", '^should be Table 2.1$', True),
|
||||
(".//table/caption", '^should be Table 2.3$', True),
|
||||
(".//table/caption", '^should be Table 2.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 2.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 2.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 2.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
(".//table/caption/span[@class='caption-number']", None, True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
],
|
||||
'baz.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^should be Fig.2.2$', True),
|
||||
(".//table/caption", '^should be Table 2.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^should be List 2.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
(".//table/caption/span[@class='caption-number']", None, True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", None, True),
|
||||
],
|
||||
}
|
||||
|
||||
@ -547,62 +522,72 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.9 should be Fig.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.10 should be Fig.2$', True),
|
||||
(".//table/caption", '^Table 9 should be Table 1$', True),
|
||||
(".//table/caption", '^Table 10 should be Table 2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 9 should be List 1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 10 should be List 2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.9 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.10 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 9 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 10 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 9 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 10 $', True),
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1 should be Fig.1.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2 should be Fig.1.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.3 should be Fig.1.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.4 should be Fig.1.4$', True),
|
||||
(".//table/caption", '^Table 1 should be Table 1.1$', True),
|
||||
(".//table/caption", '^Table 2 should be Table 1.2$', True),
|
||||
(".//table/caption", '^Table 3 should be Table 1.3$', True),
|
||||
(".//table/caption", '^Table 4 should be Table 1.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1 should be List 1.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2 should be List 1.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 3 should be List 1.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 4 should be List 1.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.4 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 4 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 4 $', True),
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.5 should be Fig.2.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.7 should be Fig.2.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.8 should be Fig.2.4$', True),
|
||||
(".//table/caption", '^Table 5 should be Table 2.1$', True),
|
||||
(".//table/caption", '^Table 7 should be Table 2.3$', True),
|
||||
(".//table/caption", '^Table 8 should be Table 2.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 5 should be List 2.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 7 should be List 2.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 8 should be List 2.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.5 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.7 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.8 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 5 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 7 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 8 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 5 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 7 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 8 $', True),
|
||||
],
|
||||
'baz.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.6 should be Fig.2.2$', True),
|
||||
(".//table/caption", '^Table 6 should be Table 2.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 6 should be List 2.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.6 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 6 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 6 $', True),
|
||||
],
|
||||
}
|
||||
|
||||
@ -626,62 +611,72 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1 should be Fig.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2 should be Fig.2$', True),
|
||||
(".//table/caption", '^Table 1 should be Table 1$', True),
|
||||
(".//table/caption", '^Table 2 should be Table 2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1 should be List 1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2 should be List 2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2 $', True),
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.1 should be Fig.1.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.2 should be Fig.1.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.3 should be Fig.1.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.4 should be Fig.1.4$', True),
|
||||
(".//table/caption", '^Table 1.1 should be Table 1.1$', True),
|
||||
(".//table/caption", '^Table 1.2 should be Table 1.2$', True),
|
||||
(".//table/caption", '^Table 1.3 should be Table 1.3$', True),
|
||||
(".//table/caption", '^Table 1.4 should be Table 1.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.1 should be List 1.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.2 should be List 1.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.3 should be List 1.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.4 should be List 1.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.2 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.4 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.4 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.4 $', True),
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.1 should be Fig.2.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.3 should be Fig.2.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.4 should be Fig.2.4$', True),
|
||||
(".//table/caption", '^Table 2.1 should be Table 2.1$', True),
|
||||
(".//table/caption", '^Table 2.3 should be Table 2.3$', True),
|
||||
(".//table/caption", '^Table 2.4 should be Table 2.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.1 should be List 2.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.3 should be List 2.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.4 should be List 2.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.4 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.4 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.4 $', True),
|
||||
],
|
||||
'baz.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.2 should be Fig.2.2$', True),
|
||||
(".//table/caption", '^Table 2.2 should be Table 2.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.2 should be List 2.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.2 $', True),
|
||||
],
|
||||
}
|
||||
|
||||
@ -699,68 +694,81 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
|
||||
|
||||
@gen_with_app(buildername='html', testroot='numfig',
|
||||
confoverrides={'numfig': True, 'numfig_prefix': {'figure': 'Figure:', 'table': 'Tab_', 'code-block': 'Code-'}})
|
||||
confoverrides={'numfig': True,
|
||||
'numfig_prefix': {'figure': 'Figure:',
|
||||
'table': 'Tab_',
|
||||
'code-block': 'Code-'}})
|
||||
def test_numfig_with_prefix(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:1 should be Fig.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:2 should be Fig.2$', True),
|
||||
(".//table/caption", '^Tab_1 should be Table 1$', True),
|
||||
(".//table/caption", '^Tab_2 should be Table 2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-1 should be List 1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-2 should be List 2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-2 $', True),
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:1.1 should be Fig.1.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:1.2 should be Fig.1.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:1.3 should be Fig.1.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:1.4 should be Fig.1.4$', True),
|
||||
(".//table/caption", '^Tab_1.1 should be Table 1.1$', True),
|
||||
(".//table/caption", '^Tab_1.2 should be Table 1.2$', True),
|
||||
(".//table/caption", '^Tab_1.3 should be Table 1.3$', True),
|
||||
(".//table/caption", '^Tab_1.4 should be Table 1.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-1.1 should be List 1.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-1.2 should be List 1.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-1.3 should be List 1.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-1.4 should be List 1.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:1.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:1.2 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:1.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:1.4 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_1.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_1.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_1.3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_1.4 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-1.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-1.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-1.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-1.4 $', True),
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:2.1 should be Fig.2.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:2.3 should be Fig.2.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:2.4 should be Fig.2.4$', True),
|
||||
(".//table/caption", '^Tab_2.1 should be Table 2.1$', True),
|
||||
(".//table/caption", '^Tab_2.3 should be Table 2.3$', True),
|
||||
(".//table/caption", '^Tab_2.4 should be Table 2.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-2.1 should be List 2.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-2.3 should be List 2.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-2.4 should be List 2.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:2.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:2.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:2.4 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_2.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_2.3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_2.4 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-2.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-2.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-2.4 $', True),
|
||||
],
|
||||
'baz.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Figure:2.2 should be Fig.2.2$', True),
|
||||
(".//table/caption", '^Tab_2.2 should be Table 2.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^Code-2.2 should be List 2.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Figure:2.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Tab_2.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^Code-2.2 $', True),
|
||||
],
|
||||
}
|
||||
|
||||
@ -784,62 +792,72 @@ def test_numfig_with_secnum_depth(app, status, warning):
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1 should be Fig.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2 should be Fig.2$', True),
|
||||
(".//table/caption", '^Table 1 should be Table 1$', True),
|
||||
(".//table/caption", '^Table 2 should be Table 2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1 should be List 1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2 should be List 2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2 $', True),
|
||||
],
|
||||
'foo.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.1 should be Fig.1.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.1.1 should be Fig.1.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.1.2 should be Fig.1.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.1.2.1 should be Fig.1.4$', True),
|
||||
(".//table/caption", '^Table 1.1 should be Table 1.1$', True),
|
||||
(".//table/caption", '^Table 1.1.1 should be Table 1.2$', True),
|
||||
(".//table/caption", '^Table 1.1.2 should be Table 1.3$', True),
|
||||
(".//table/caption", '^Table 1.2.1 should be Table 1.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.1 should be List 1.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.1.1 should be List 1.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.1.2 should be List 1.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 1.2.1 should be List 1.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.1.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.1.2 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.1.2.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.1.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.1.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 1.2.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.1.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.1.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 1.2.1 $', True),
|
||||
],
|
||||
'bar.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.1.1 should be Fig.2.1$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.1.3 should be Fig.2.3$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.2.1 should be Fig.2.4$', True),
|
||||
(".//table/caption", '^Table 2.1.1 should be Table 2.1$', True),
|
||||
(".//table/caption", '^Table 2.1.3 should be Table 2.3$', True),
|
||||
(".//table/caption", '^Table 2.2.1 should be Table 2.4$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.1.1 should be List 2.1$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.1.3 should be List 2.3$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.2.1 should be List 2.4$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.1.1 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.1.3 $', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.2.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.1.1 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.1.3 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.2.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.1.1 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.1.3 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.2.1 $', True),
|
||||
],
|
||||
'baz.html': [
|
||||
(".//div[@class='figure']/p[@class='caption']",
|
||||
'^Fig.2.1.2 should be Fig.2.2$', True),
|
||||
(".//table/caption", '^Table 2.1.2 should be Table 2.2$', True),
|
||||
(".//div[@class='code-block-caption']",
|
||||
'^List 2.1.2 should be List 2.2$', True),
|
||||
(".//div[@class='figure']/p[@class='caption']/"
|
||||
"span[@class='caption-number']", '^Fig.2.1.2 $', True),
|
||||
(".//table/caption/span[@class='caption-number']",
|
||||
'^Table 2.1.2 $', True),
|
||||
(".//div[@class='code-block-caption']/"
|
||||
"span[@class='caption-number']", '^List 2.1.2 $', True),
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,11 @@ def test_code_block_dedent(app, status, warning):
|
||||
@with_app('html', testroot='directive-code')
|
||||
def test_code_block_caption_html(app, status, warning):
|
||||
app.builder.build(['caption'])
|
||||
html = (app.outdir / 'caption.html').text()
|
||||
caption = '<div class="code-block-caption">caption <em>test</em> rb</div>'
|
||||
html = (app.outdir / 'caption.html').text(encoding='utf-8')
|
||||
caption = (u'<div class="code-block-caption">'
|
||||
u'<span class="caption-text">caption <em>test</em> rb'
|
||||
u'</span><a class="headerlink" href="#id1" '
|
||||
u'title="Permalink to this code">\xb6</a></div>')
|
||||
assert caption in html
|
||||
|
||||
|
||||
@ -98,8 +101,11 @@ def test_literal_include_dedent(app, status, warning):
|
||||
@with_app('html', testroot='directive-code')
|
||||
def test_literalinclude_caption_html(app, status, warning):
|
||||
app.builder.build('index')
|
||||
html = (app.outdir / 'caption.html').text()
|
||||
caption = '<div class="code-block-caption">caption <strong>test</strong> py</div>'
|
||||
html = (app.outdir / 'caption.html').text(encoding='utf-8')
|
||||
caption = (u'<div class="code-block-caption">'
|
||||
u'<span class="caption-text">caption <strong>test</strong> py'
|
||||
u'</span><a class="headerlink" href="#id2" '
|
||||
u'title="Permalink to this code">\xb6</a></div>')
|
||||
assert caption in html
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user