mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Get rid of the "module" node.
This commit is contained in:
parent
1b5fbd6fa1
commit
7f8f3f86b6
@ -90,9 +90,6 @@ class abbreviation(nodes.Inline, nodes.TextElement): pass
|
||||
# glossary
|
||||
class glossary(nodes.Element): pass
|
||||
|
||||
# module declaration
|
||||
class module(nodes.Element): pass
|
||||
|
||||
# start of a file, used in the LaTeX builder only
|
||||
class start_of_file(nodes.Element): pass
|
||||
|
||||
|
@ -351,16 +351,12 @@ class PyModule(Directive):
|
||||
env.domaindata['py']['modules'][modname] = \
|
||||
(env.docname, self.options.get('synopsis', ''),
|
||||
self.options.get('platform', ''), 'deprecated' in self.options)
|
||||
modulenode = addnodes.module()
|
||||
modulenode['modname'] = modname
|
||||
modulenode['synopsis'] = self.options.get('synopsis', '')
|
||||
targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True)
|
||||
self.state.document.note_explicit_target(targetnode)
|
||||
ret = [modulenode, targetnode]
|
||||
ret = [targetnode]
|
||||
# XXX this behavior of the module directive is a mess...
|
||||
if 'platform' in self.options:
|
||||
platform = self.options['platform']
|
||||
modulenode['platform'] = platform
|
||||
node = nodes.paragraph()
|
||||
node += nodes.emphasis('', _('Platforms: '))
|
||||
node += nodes.Text(platform, platform)
|
||||
@ -371,7 +367,7 @@ class PyModule(Directive):
|
||||
indextext = _('%s (module)') % modname
|
||||
inode = addnodes.index(entries=[('single', indextext,
|
||||
'module-' + modname, modname)])
|
||||
ret.insert(0, inode)
|
||||
ret.append(inode)
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -109,7 +109,8 @@ class DefaultSubstitutions(Transform):
|
||||
|
||||
class MoveModuleTargets(Transform):
|
||||
"""
|
||||
Move module targets to their nearest enclosing section title.
|
||||
Move module targets that are the first thing in a section to the section
|
||||
title.
|
||||
|
||||
XXX Python specific
|
||||
"""
|
||||
@ -119,9 +120,10 @@ class MoveModuleTargets(Transform):
|
||||
for node in self.document.traverse(nodes.target):
|
||||
if not node['ids']:
|
||||
continue
|
||||
if node['ids'][0].startswith('module-') and \
|
||||
node.parent.__class__ is nodes.section and \
|
||||
node.has_key('ismod'):
|
||||
if (node.has_key('ismod') and
|
||||
node.parent.__class__ is nodes.section and
|
||||
# index 0 is the section title node
|
||||
node.parent.index(node) == 1):
|
||||
node.parent['ids'][0:0] = node['ids']
|
||||
node.parent.remove(node)
|
||||
|
||||
|
@ -352,11 +352,6 @@ class HTMLTranslator(BaseTranslator):
|
||||
def depart_acks(self, node):
|
||||
pass
|
||||
|
||||
def visit_module(self, node):
|
||||
pass
|
||||
def depart_module(self, node):
|
||||
pass
|
||||
|
||||
def visit_hlist(self, node):
|
||||
self.body.append('<table class="hlist"><tr>')
|
||||
def depart_hlist(self, node):
|
||||
|
@ -220,7 +220,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.top_sectionlevel = 0
|
||||
else:
|
||||
self.top_sectionlevel = 1
|
||||
self.next_section_target = None
|
||||
self.next_section_ids = []
|
||||
# flags
|
||||
self.verbatim = None
|
||||
self.in_title = 0
|
||||
@ -240,14 +240,14 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.generate_indices() +
|
||||
FOOTER % self.elements)
|
||||
|
||||
def hypertarget(self, target, text='', anchor=True):
|
||||
#return '\\hypertarget{%s}{%s}' % (self.idescape(target), text)
|
||||
def hypertarget(self, id, text='', anchor=True):
|
||||
#return '\\hypertarget{%s}{%s}' % (self.idescape(id), text)
|
||||
return (anchor and '\\phantomsection' or '') + \
|
||||
'\\label{%s}%s' % (self.idescape(target), text)
|
||||
'\\label{%s}%s' % (self.idescape(id), text)
|
||||
|
||||
def hyperlink(self, target):
|
||||
#return '\\hyperlink{%s}{' % (self.idescape(target))
|
||||
return '\\hyperref[%s]{' % (self.idescape(target))
|
||||
def hyperlink(self, id):
|
||||
#return '\\hyperlink{%s}{' % (self.idescape(id))
|
||||
return '\\hyperref[%s]{' % (self.idescape(id))
|
||||
|
||||
def idescape(self, id):
|
||||
return str(unicode(id).translate(tex_replace_map))
|
||||
@ -362,7 +362,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if not self.this_is_the_title:
|
||||
self.sectionlevel += 1
|
||||
self.body.append('\n\n')
|
||||
#if node.get('ids'):
|
||||
if node.get('ids'):
|
||||
self.next_section_ids.extend(node['ids'])
|
||||
# for id in node['ids']:
|
||||
# if id not in self.written_ids:
|
||||
# self.body.append(self.hypertarget(id))
|
||||
@ -438,10 +439,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.body.append(r'\%s{' % self.sectionnames[-1])
|
||||
self.context.append('}\n')
|
||||
|
||||
if self.next_section_target:
|
||||
self.context[-1] += self.hypertarget(self.next_section_target,
|
||||
anchor=False)
|
||||
self.next_section_target = None
|
||||
if self.next_section_ids:
|
||||
for id in self.next_section_ids:
|
||||
if id not in self.written_ids:
|
||||
self.context[-1] += self.hypertarget(id, anchor=False)
|
||||
self.written_ids.add(id)
|
||||
self.next_section_ids = []
|
||||
|
||||
elif isinstance(parent, (nodes.topic, nodes.sidebar)):
|
||||
self.body.append(r'\textbf{')
|
||||
@ -800,19 +803,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
def depart_hlistcol(self, node):
|
||||
pass
|
||||
|
||||
def visit_module(self, node):
|
||||
modname = node['modname']
|
||||
self.body.append('\n' +
|
||||
self.hypertarget('module-' + modname.replace(' ','')))
|
||||
#self.body.append('\n\\declaremodule[%s]{}{%s}' % (
|
||||
# modname.replace('_', ''), self.encode(modname)))
|
||||
#self.body.append('\n\\modulesynopsis{%s}' %
|
||||
# self.encode(node['synopsis']))
|
||||
#if node.has_key('platform'):
|
||||
# self.body.append('\\platform{%s}' % self.encode(node['platform']))
|
||||
def depart_module(self, node):
|
||||
pass
|
||||
|
||||
def latex_image_length(self, width_str):
|
||||
match = re.match('(\d*\.?\d*)\s*(\S*)', width_str)
|
||||
if not match:
|
||||
@ -976,7 +966,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
next = node.parent[parindex+1]
|
||||
if isinstance(next, nodes.section):
|
||||
# postpone the label until after the sectioning command
|
||||
self.next_section_target = node['refid']
|
||||
self.next_section_ids.append(node['refid'])
|
||||
return
|
||||
except IndexError:
|
||||
pass
|
||||
@ -1035,9 +1025,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
elif uri.startswith('%'):
|
||||
# references to documents or labels inside documents
|
||||
hashindex = uri.find('#')
|
||||
targetname = (hashindex == -1) and '--doc-' + uri[1:] \
|
||||
or uri[hashindex+1:]
|
||||
self.body.append(self.hyperlink(targetname))
|
||||
id = (hashindex == -1) and '--doc-' + uri[1:] or uri[hashindex+1:]
|
||||
self.body.append(self.hyperlink(id))
|
||||
self.context.append('}')
|
||||
elif uri.startswith('@token'):
|
||||
if self.in_production_list:
|
||||
|
@ -160,13 +160,6 @@ class TextTranslator(nodes.NodeVisitor):
|
||||
def depart_attribution(self, node):
|
||||
pass
|
||||
|
||||
def visit_module(self, node):
|
||||
if node.has_key('platform'):
|
||||
self.new_state(0)
|
||||
self.add_text(_('Platform: %s') % node['platform'])
|
||||
self.end_state()
|
||||
raise nodes.SkipNode
|
||||
|
||||
def visit_desc(self, node):
|
||||
pass
|
||||
def depart_desc(self, node):
|
||||
|
Loading…
Reference in New Issue
Block a user