1
1
# Author: David Goodger, Dmitry Jemerov
2
2
# Contact: goodger@users.sourceforge.net
3
# Revision: $Revision: 1.12 $
4
# Date: $Date: 2004/03/22 01:08:19 $
3
# Revision: $Revision: 3439 $
4
# Date: $Date: 2005-06-06 03:20:35 +0200 (Mon, 06 Jun 2005) $
5
5
# Copyright: This module has been placed in the public domain.
27
27
def contents(name, arguments, options, content, lineno,
28
28
content_offset, block_text, state, state_machine):
29
"""Table of contents."""
32
The table of contents is generated in two passes: initial parse and
33
transform. During the initial parse, a 'pending' element is generated
34
which acts as a placeholder, storing the TOC title and any options
35
internally. At a later stage in the processing, the 'pending' element is
36
replaced by a 'topic' element, a title and the table of contents proper.
38
if not (state_machine.match_titles
39
or isinstance(state_machine.node, nodes.sidebar)):
40
error = state_machine.reporter.error(
41
'The "%s" directive may not be used within topics '
42
'or body elements.' % name,
43
nodes.literal_block(block_text, block_text), line=lineno)
30
45
document = state_machine.document
31
46
language = languages.get_language(document.settings.language_code)
34
48
title_text = arguments[0]
35
49
text_nodes, messages = state.inline_text(title_text, lineno)
42
56
title = nodes.title('', language.labels['contents'])
44
topic = nodes.topic(CLASS='contents')
46
cls = options.get('class')
57
topic = nodes.topic(classes=['contents'])
58
topic['classes'] += options.get('class', [])
59
if options.has_key('local'):
60
topic['classes'].append('local')
51
62
name = title.astext()
54
65
name = language.labels['contents']
56
66
name = nodes.fully_normalize_name(name)
57
67
if not document.has_name(name):
68
topic['names'].append(name)
59
69
document.note_implicit_target(topic)
61
70
pending = nodes.pending(parts.Contents, rawsource=block_text)
62
71
pending.details.update(options)
63
72
document.note_pending(pending)
78
87
state_machine.document.note_pending(pending)
81
sectnum.options = {'depth': int}
90
sectnum.options = {'depth': int,
92
'prefix': directives.unchanged_required,
93
'suffix': directives.unchanged_required}
95
def header_footer(node, name, arguments, options, content, lineno,
96
content_offset, block_text, state, state_machine):
97
"""Contents of document header or footer."""
99
warning = state_machine.reporter.warning(
100
'Content block expected for the "%s" directive; none found.'
101
% name, nodes.literal_block(block_text, block_text),
103
node.append(nodes.paragraph(
104
'', 'Problem with the "%s" directive: no content supplied.' % name))
106
text = '\n'.join(content)
107
state.nested_parse(content, content_offset, node)
110
def header(name, arguments, options, content, lineno,
111
content_offset, block_text, state, state_machine):
112
decoration = state_machine.document.get_decoration()
113
node = decoration.get_header()
114
return header_footer(node, name, arguments, options, content, lineno,
115
content_offset, block_text, state, state_machine)
119
def footer(name, arguments, options, content, lineno,
120
content_offset, block_text, state, state_machine):
121
decoration = state_machine.document.get_decoration()
122
node = decoration.get_footer()
123
return header_footer(node, name, arguments, options, content, lineno,
124
content_offset, block_text, state, state_machine)