Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/docutils/parsers/rst/directives/parts.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 # $Id: parts.py 7308 2012-01-06 12:08:43Z milde $ | |
2 # Authors: David Goodger <goodger@python.org>; Dmitry Jemerov | |
3 # Copyright: This module has been placed in the public domain. | |
4 | |
5 """ | |
6 Directives for document parts. | |
7 """ | |
8 | |
9 __docformat__ = 'reStructuredText' | |
10 | |
11 from docutils import nodes, languages | |
12 from docutils.transforms import parts | |
13 from docutils.parsers.rst import Directive | |
14 from docutils.parsers.rst import directives | |
15 | |
16 | |
17 class Contents(Directive): | |
18 | |
19 """ | |
20 Table of contents. | |
21 | |
22 The table of contents is generated in two passes: initial parse and | |
23 transform. During the initial parse, a 'pending' element is generated | |
24 which acts as a placeholder, storing the TOC title and any options | |
25 internally. At a later stage in the processing, the 'pending' element is | |
26 replaced by a 'topic' element, a title and the table of contents proper. | |
27 """ | |
28 | |
29 backlinks_values = ('top', 'entry', 'none') | |
30 | |
31 def backlinks(arg): | |
32 value = directives.choice(arg, Contents.backlinks_values) | |
33 if value == 'none': | |
34 return None | |
35 else: | |
36 return value | |
37 | |
38 optional_arguments = 1 | |
39 final_argument_whitespace = True | |
40 option_spec = {'depth': directives.nonnegative_int, | |
41 'local': directives.flag, | |
42 'backlinks': backlinks, | |
43 'class': directives.class_option} | |
44 | |
45 def run(self): | |
46 if not (self.state_machine.match_titles | |
47 or isinstance(self.state_machine.node, nodes.sidebar)): | |
48 raise self.error('The "%s" directive may not be used within ' | |
49 'topics or body elements.' % self.name) | |
50 document = self.state_machine.document | |
51 language = languages.get_language(document.settings.language_code, | |
52 document.reporter) | |
53 if self.arguments: | |
54 title_text = self.arguments[0] | |
55 text_nodes, messages = self.state.inline_text(title_text, | |
56 self.lineno) | |
57 title = nodes.title(title_text, '', *text_nodes) | |
58 else: | |
59 messages = [] | |
60 if 'local' in self.options: | |
61 title = None | |
62 else: | |
63 title = nodes.title('', language.labels['contents']) | |
64 topic = nodes.topic(classes=['contents']) | |
65 topic['classes'] += self.options.get('class', []) | |
66 # the latex2e writer needs source and line for a warning: | |
67 topic.source, topic.line = self.state_machine.get_source_and_line() | |
68 topic.line -= 1 | |
69 if 'local' in self.options: | |
70 topic['classes'].append('local') | |
71 if title: | |
72 name = title.astext() | |
73 topic += title | |
74 else: | |
75 name = language.labels['contents'] | |
76 name = nodes.fully_normalize_name(name) | |
77 if not document.has_name(name): | |
78 topic['names'].append(name) | |
79 document.note_implicit_target(topic) | |
80 pending = nodes.pending(parts.Contents, rawsource=self.block_text) | |
81 pending.details.update(self.options) | |
82 document.note_pending(pending) | |
83 topic += pending | |
84 return [topic] + messages | |
85 | |
86 | |
87 class Sectnum(Directive): | |
88 | |
89 """Automatic section numbering.""" | |
90 | |
91 option_spec = {'depth': int, | |
92 'start': int, | |
93 'prefix': directives.unchanged_required, | |
94 'suffix': directives.unchanged_required} | |
95 | |
96 def run(self): | |
97 pending = nodes.pending(parts.SectNum) | |
98 pending.details.update(self.options) | |
99 self.state_machine.document.note_pending(pending) | |
100 return [pending] | |
101 | |
102 | |
103 class Header(Directive): | |
104 | |
105 """Contents of document header.""" | |
106 | |
107 has_content = True | |
108 | |
109 def run(self): | |
110 self.assert_has_content() | |
111 header = self.state_machine.document.get_decoration().get_header() | |
112 self.state.nested_parse(self.content, self.content_offset, header) | |
113 return [] | |
114 | |
115 | |
116 class Footer(Directive): | |
117 | |
118 """Contents of document footer.""" | |
119 | |
120 has_content = True | |
121 | |
122 def run(self): | |
123 self.assert_has_content() | |
124 footer = self.state_machine.document.get_decoration().get_footer() | |
125 self.state.nested_parse(self.content, self.content_offset, footer) | |
126 return [] |