Commit d7e93e24 authored by Andreas Jung's avatar Andreas Jung

update to docutils 0.3.9

parent 635843bd
# Author: David Goodger # Author: David Goodger
# Contact: goodger@python.org # Contact: goodger@python.org
# Revision: $Revision: 1.2.10.9 $ # Revision: $Revision: 3374 $
# Date: $Date: 2005/01/07 13:26:01 $ # Date: $Date: 2005-05-26 23:21:48 +0200 (Thu, 26 May 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -51,7 +51,7 @@ Subpackages: ...@@ -51,7 +51,7 @@ Subpackages:
__docformat__ = 'reStructuredText' __docformat__ = 'reStructuredText'
__version__ = '0.3.7' __version__ = '0.3.9'
"""``major.minor.micro`` version number. The micro number is bumped for API """``major.minor.micro`` version number. The micro number is bumped for API
changes, for new functionality, and for interim project releases. The minor changes, for new functionality, and for interim project releases. The minor
number is bumped whenever there is a significant project release. The major number is bumped whenever there is a significant project release. The major
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@python.org # Contact: goodger@python.org
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2987 $
# Date: $Date: 2005/01/07 13:26:01 $ # Date: $Date: 2005-02-26 19:17:59 +0100 (Sat, 26 Feb 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -197,6 +197,7 @@ class Publisher: ...@@ -197,6 +197,7 @@ class Publisher:
self.writer.assemble_parts() self.writer.assemble_parts()
except Exception, error: except Exception, error:
if self.settings.traceback: # propagate exceptions? if self.settings.traceback: # propagate exceptions?
self.debugging_dumps(document)
raise raise
self.report_Exception(error) self.report_Exception(error)
exit = 1 exit = 1
...@@ -210,6 +211,8 @@ class Publisher: ...@@ -210,6 +211,8 @@ class Publisher:
return output return output
def debugging_dumps(self, document): def debugging_dumps(self, document):
if not document:
return
if self.settings.dump_settings: if self.settings.dump_settings:
print >>sys.stderr, '\n::: Runtime settings:' print >>sys.stderr, '\n::: Runtime settings:'
print >>sys.stderr, pprint.pformat(self.settings.__dict__) print >>sys.stderr, pprint.pformat(self.settings.__dict__)
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@python.org # Contact: goodger@python.org
# Revision: $Revision: 1.1.4.3 $ # Revision: $Revision: 3247 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-04-23 21:23:57 +0200 (Sat, 23 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
This module contains practical examples of Docutils client code. This module contains practical examples of Docutils client code.
Importing this module is not recommended; its contents are subject to change Importing this module from client code is not recommended; its contents are
in future Docutils releases. Instead, it is recommended that you copy and subject to change in future Docutils releases. Instead, it is recommended
paste the parts you need into your own code, modifying as necessary. that you copy and paste the parts you need into your own code, modifying as
necessary.
""" """
from docutils import core from docutils import core, io
def html_parts(input_string, source_path=None, destination_path=None, def html_parts(input_string, source_path=None, destination_path=None,
...@@ -72,3 +73,23 @@ def html_fragment(input_string, source_path=None, destination_path=None, ...@@ -72,3 +73,23 @@ def html_fragment(input_string, source_path=None, destination_path=None,
if output_encoding != 'unicode': if output_encoding != 'unicode':
fragment = fragment.encode(output_encoding) fragment = fragment.encode(output_encoding)
return fragment return fragment
def internals(input_string, source_path=None, destination_path=None,
input_encoding='unicode'):
"""
Return the document tree and publisher, for exploring Docutils internals.
Parameters: see `html_parts()`.
"""
overrides = {'input_encoding': input_encoding}
output, pub = core.publish_programmatically(
source_class=io.StringInput, source=input_string,
source_path=source_path,
destination_class=io.NullOutput, destination=None,
destination_path=destination_path,
reader=None, reader_name='standalone',
parser=None, parser_name='restructuredtext',
writer=None, writer_name='null',
settings=None, settings_spec=None, settings_overrides=overrides,
config_section=None, enable_exit_status=None)
return pub.writer.document, pub
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.8 $ # Revision: $Revision: 3358 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-05-21 02:00:25 +0200 (Sat, 21 May 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -124,6 +124,13 @@ def validate_boolean(setting, value, option_parser, ...@@ -124,6 +124,13 @@ def validate_boolean(setting, value, option_parser,
None, sys.exc_info()[2]) None, sys.exc_info()[2])
return value return value
def validate_nonnegative_int(setting, value, option_parser,
config_parser=None, config_section=None):
value = int(value)
if value < 0:
raise ValueError('negative value; must be positive or zero')
return value
def validate_threshold(setting, value, option_parser, def validate_threshold(setting, value, option_parser,
config_parser=None, config_section=None): config_parser=None, config_section=None):
try: try:
...@@ -333,10 +340,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ...@@ -333,10 +340,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
'validator': validate_threshold}), 'validator': validate_threshold}),
('Report all system messages, info-level and higher. (Same as ' ('Report all system messages, info-level and higher. (Same as '
'"--report=info".)', '"--report=info".)',
['--verbose', '-v'], {'action': 'store_const', 'const': 'info', ['--verbose', '-v'], {'action': 'store_const', 'const': 1,
'dest': 'report_level'}), 'dest': 'report_level'}),
('Do not report any system messages. (Same as "--report=none".)', ('Do not report any system messages. (Same as "--report=none".)',
['--quiet', '-q'], {'action': 'store_const', 'const': 'none', ['--quiet', '-q'], {'action': 'store_const', 'const': 5,
'dest': 'report_level'}), 'dest': 'report_level'}),
('Set the threshold (<level>) at or above which system messages are ' ('Set the threshold (<level>) at or above which system messages are '
'converted to exceptions, halting execution immediately by ' 'converted to exceptions, halting execution immediately by '
...@@ -429,6 +436,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ...@@ -429,6 +436,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
['--version', '-V'], {'action': 'version'}), ['--version', '-V'], {'action': 'version'}),
('Show this help message and exit.', ('Show this help message and exit.',
['--help', '-h'], {'action': 'help'}), ['--help', '-h'], {'action': 'help'}),
# Typically not useful for non-programmatical use.
(SUPPRESS_HELP, ['--id-prefix'], {'default': ''}),
(SUPPRESS_HELP, ['--auto-id-prefix'], {'default': 'id'}),
# Hidden options, for development use only: # Hidden options, for development use only:
(SUPPRESS_HELP, ['--dump-settings'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--dump-settings'], {'action': 'store_true'}),
(SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}),
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3138 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-03-27 17:05:34 +0200 (Sun, 27 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -70,32 +70,42 @@ class Input(TransformSpec): ...@@ -70,32 +70,42 @@ class Input(TransformSpec):
if (self.encoding and self.encoding.lower() == 'unicode' if (self.encoding and self.encoding.lower() == 'unicode'
or isinstance(data, UnicodeType)): or isinstance(data, UnicodeType)):
return data return data
encodings = [self.encoding, 'utf-8'] encodings = [self.encoding]
try: if not self.encoding:
encodings.append(locale.nl_langinfo(locale.CODESET)) # Apply heuristics only if no encoding is explicitly given.
except: encodings.append('utf-8')
pass try:
try: encodings.append(locale.nl_langinfo(locale.CODESET))
encodings.append(locale.getlocale()[1]) except:
except: pass
pass try:
try: encodings.append(locale.getlocale()[1])
encodings.append(locale.getdefaultlocale()[1]) except:
except: pass
pass try:
encodings.append('latin-1') encodings.append(locale.getdefaultlocale()[1])
except:
pass
encodings.append('latin-1')
error = None
error_details = ''
for enc in encodings: for enc in encodings:
if not enc: if not enc:
continue continue
try: try:
decoded = unicode(data, enc, self.error_handler) decoded = unicode(data, enc, self.error_handler)
self.successful_encoding = enc self.successful_encoding = enc
return decoded # Return decoded, removing BOMs.
except (UnicodeError, LookupError): return decoded.replace(u'\ufeff', u'')
except (UnicodeError, LookupError), error:
pass pass
if error is not None:
error_details = '\n(%s: %s)' % (error.__class__.__name__, error)
raise UnicodeError( raise UnicodeError(
'Unable to decode input data. Tried the following encodings: %s.' 'Unable to decode input data. Tried the following encodings: '
% ', '.join([repr(enc) for enc in encodings if enc])) '%s.%s'
% (', '.join([repr(enc) for enc in encodings if enc]),
error_details))
class Output(TransformSpec): class Output(TransformSpec):
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# Internationalization details are documented in # Internationalization details are documented in
......
# Author: Jannie Hofmeyr # Author: Jannie Hofmeyr
# Contact: jhsh@sun.ac.za # Contact: jhsh@sun.ac.za
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Marek Blaha # Author: Marek Blaha
# Contact: mb@dat.cz # Contact: mb@dat.cz
# Revision: $Revision: 1.1.4.4 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Authors: David Goodger; Gunnar Schwant # Authors: David Goodger; Gunnar Schwant
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Marcelo Huerta San Martin # Author: Marcelo Huerta San Martin
# Contact: richieadler@users.sourceforge.net # Contact: richieadler@users.sourceforge.net
# Revision: $Revision: 1.1.2.5 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
# Author: Marcelo Huerta San Martn # Author: Marcelo Huerta San Martn
# Contact: mghsm@uol.com.ar # Contact: mghsm@uol.com.ar
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Asko Soukka # Author: Asko Soukka
# Contact: asko.soukka@iki.fi # Contact: asko.soukka@iki.fi
# Revision: $Revision: 1.1.2.1 $ # Revision: $Revision: 2609 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-09-13 21:25:33 +0200 (Mon, 13 Sep 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Stefane Fermigier # Author: Stefane Fermigier
# Contact: sf@fermigier.com # Contact: sf@fermigier.com
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Nicola Larosa # Author: Nicola Larosa
# Contact: docutils@tekNico.net # Contact: docutils@tekNico.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2944 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-01-20 13:11:50 +0100 (Thu, 20 Jan 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -45,7 +45,7 @@ bibliographic_fields = { ...@@ -45,7 +45,7 @@ bibliographic_fields = {
'autori': 'authors', 'autori': 'authors',
'organizzazione': 'organization', 'organizzazione': 'organization',
'indirizzo': 'address', 'indirizzo': 'address',
'contatti': 'contact', 'contatto': 'contact',
'versione': 'version', 'versione': 'version',
'revisione': 'revision', 'revisione': 'revision',
'status': 'status', 'status': 'status',
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.4.4 $ # Revision: $Revision: 2333 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-20 22:51:22 +0200 (Sun, 20 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Roman Suzi # Author: Roman Suzi
# Contact: rnd@onego.ru # Contact: rnd@onego.ru
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 2999 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-03-03 20:35:02 +0100 (Thu, 03 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -46,21 +46,21 @@ labels = { ...@@ -46,21 +46,21 @@ labels = {
"""Mapping of node class name to label text.""" """Mapping of node class name to label text."""
bibliographic_fields = { bibliographic_fields = {
u'\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f': u'abstract', u'\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f': u'abstract',
u'\u0410\u0434\u0440\u0435\u0441': u'address', u'\u0430\u0434\u0440\u0435\u0441': u'address',
u'\u0410\u0432\u0442\u043e\u0440': u'author', u'\u0430\u0432\u0442\u043e\u0440': u'author',
u'\u0410\u0432\u0442\u043e\u0440\u044b': u'authors', u'\u0430\u0432\u0442\u043e\u0440\u044b': u'authors',
u'\u041a\u043e\u043d\u0442\u0430\u043a\u0442': u'contact', u'\u043a\u043e\u043d\u0442\u0430\u043a\u0442': u'contact',
u'\u041f\u0440\u0430\u0432\u0430 \u043a\u043e\u043f\u0438\u0440\u043e' u'\u043f\u0440\u0430\u0432\u0430 \u043a\u043e\u043f\u0438\u0440\u043e'
u'\u0432\u0430\u043d\u0438\u044f': u'copyright', u'\u0432\u0430\u043d\u0438\u044f': u'copyright',
u'\u0414\u0430\u0442\u0430': u'date', u'\u0434\u0430\u0442\u0430': u'date',
u'\u041f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0438\u0435': u'\u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0438\u0435':
u'dedication', u'dedication',
u'\u041e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f': u'\u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044f':
u'organization', u'organization',
u'\u0420\u0435\u0434\u0430\u043a\u0446\u0438\u044f': u'revision', u'\u0440\u0435\u0434\u0430\u043a\u0446\u0438\u044f': u'revision',
u'\u0421\u0442\u0430\u0442\u0443\u0441': u'status', u'\u0441\u0442\u0430\u0442\u0443\u0441': u'status',
u'\u0412\u0435\u0440\u0441\u0438\u044f': u'version'} u'\u0432\u0435\u0440\u0441\u0438\u044f': u'version'}
"""Russian (lowcased) to canonical name mapping for bibliographic fields.""" """Russian (lowcased) to canonical name mapping for bibliographic fields."""
author_separators = [';', ','] author_separators = [';', ',']
......
# :Author: Miroslav Vasko # :Author: Miroslav Vasko
# :Contact: zemiak@zoznam.sk # :Contact: zemiak@zoznam.sk
# :Revision: $Revision: 1.2.10.7 $ # :Revision: $Revision: 2224 $
# :Date: $Date: 2005/01/07 13:26:02 $ # :Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# :Copyright: This module has been placed in the public domain. # :Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Adam Chodorowski # Author: Adam Chodorowski
# Contact: chodorowski@users.sourceforge.net # Contact: chodorowski@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
# Author: Joe YS Jaw # Author: Joe YS Jaw
# Contact: joeysj@users.sourceforge.net # Contact: joeysj@users.sourceforge.net
# Revision: $Revision: 1.1.2.1 $ # Revision: $Revision: 2608 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-09-13 21:09:56 +0200 (Mon, 13 Sep 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
......
This diff is collapsed.
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 1645 $
# Date: $Date: 2005/01/07 13:26:03 $ # Date: $Date: 2003-08-27 22:50:43 +0200 (Wed, 27 Aug 2003) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3171 $
# Date: $Date: 2005/01/07 13:26:03 $ # Date: $Date: 2005-04-05 17:26:16 +0200 (Tue, 05 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -112,7 +112,23 @@ class Parser(docutils.parsers.Parser): ...@@ -112,7 +112,23 @@ class Parser(docutils.parsers.Parser):
('Leave spaces before footnote references.', ('Leave spaces before footnote references.',
['--leave-footnote-reference-space'], ['--leave-footnote-reference-space'],
{'action': 'store_false', 'dest': 'trim_footnote_reference_space', {'action': 'store_false', 'dest': 'trim_footnote_reference_space',
'validator': frontend.validate_boolean}),)) 'validator': frontend.validate_boolean}),
('Disable directives that insert the contents of external file '
'("include" & "raw"); replaced with a "warning" system message.',
['--no-file-insertion'],
{'action': 'store_false', 'default': 1,
'dest': 'file_insertion_enabled'}),
('Enable directives that insert the contents of external file '
'("include" & "raw"). Enabled by default.',
['--file-insertion-enabled'],
{'action': 'store_true', 'dest': 'file_insertion_enabled'}),
('Disable the "raw" directives; replaced with a "warning" '
'system message.',
['--no-raw'],
{'action': 'store_false', 'default': 1, 'dest': 'raw_enabled'}),
('Enable the "raw" directive. Enabled by default.',
['--raw-enabled'],
{'action': 'store_true', 'dest': 'raw_enabled'}),))
config_section = 'restructuredtext parser' config_section = 'restructuredtext parser'
config_section_dependencies = ('parsers',) config_section_dependencies = ('parsers',)
...@@ -128,11 +144,10 @@ class Parser(docutils.parsers.Parser): ...@@ -128,11 +144,10 @@ class Parser(docutils.parsers.Parser):
def parse(self, inputstring, document): def parse(self, inputstring, document):
"""Parse `inputstring` and populate `document`, a document tree.""" """Parse `inputstring` and populate `document`, a document tree."""
self.setup_parse(inputstring, document) self.setup_parse(inputstring, document)
debug = document.reporter[''].debug
self.statemachine = states.RSTStateMachine( self.statemachine = states.RSTStateMachine(
state_classes=self.state_classes, state_classes=self.state_classes,
initial_state=self.initial_state, initial_state=self.initial_state,
debug=debug) debug=document.reporter.debug_flag)
inputlines = docutils.statemachine.string2lines( inputlines = docutils.statemachine.string2lines(
inputstring, tab_width=document.settings.tab_width, inputstring, tab_width=document.settings.tab_width,
convert_whitespace=1) convert_whitespace=1)
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@python.org # Contact: goodger@python.org
# Revision: $Revision: 1.2.10.8 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -113,10 +113,13 @@ _directive_registry = { ...@@ -113,10 +113,13 @@ _directive_registry = {
#'questions': ('body', 'question_list'), #'questions': ('body', 'question_list'),
'table': ('tables', 'table'), 'table': ('tables', 'table'),
'csv-table': ('tables', 'csv_table'), 'csv-table': ('tables', 'csv_table'),
'list-table': ('tables', 'list_table'),
'image': ('images', 'image'), 'image': ('images', 'image'),
'figure': ('images', 'figure'), 'figure': ('images', 'figure'),
'contents': ('parts', 'contents'), 'contents': ('parts', 'contents'),
'sectnum': ('parts', 'sectnum'), 'sectnum': ('parts', 'sectnum'),
'header': ('parts', 'header'),
'footer': ('parts', 'footer'),
#'footnotes': ('parts', 'footnotes'), #'footnotes': ('parts', 'footnotes'),
#'citations': ('parts', 'citations'), #'citations': ('parts', 'citations'),
'target-notes': ('references', 'target_notes'), 'target-notes': ('references', 'target_notes'),
...@@ -250,17 +253,26 @@ def path(argument): ...@@ -250,17 +253,26 @@ def path(argument):
Return the path argument unwrapped (with newlines removed). Return the path argument unwrapped (with newlines removed).
(Directive option conversion function.) (Directive option conversion function.)
Raise ``ValueError`` if no argument is found or if the path contains Raise ``ValueError`` if no argument is found.
internal whitespace.
""" """
if argument is None: if argument is None:
raise ValueError('argument required but none supplied') raise ValueError('argument required but none supplied')
else: else:
path = ''.join([s.strip() for s in argument.splitlines()]) path = ''.join([s.strip() for s in argument.splitlines()])
if path.find(' ') == -1: return path
return path
else: def uri(argument):
raise ValueError('path contains whitespace') """
Return the URI argument with whitespace removed.
(Directive option conversion function.)
Raise ``ValueError`` if no argument is found.
"""
if argument is None:
raise ValueError('argument required but none supplied')
else:
uri = ''.join(argument.split())
return uri
def nonnegative_int(argument): def nonnegative_int(argument):
""" """
...@@ -274,7 +286,7 @@ def nonnegative_int(argument): ...@@ -274,7 +286,7 @@ def nonnegative_int(argument):
def class_option(argument): def class_option(argument):
""" """
Convert the argument into an ID-compatible string and return it. Convert the argument into a list of ID-compatible strings and return it.
(Directive option conversion function.) (Directive option conversion function.)
Raise ``ValueError`` if no argument is found. Raise ``ValueError`` if no argument is found.
...@@ -288,7 +300,7 @@ def class_option(argument): ...@@ -288,7 +300,7 @@ def class_option(argument):
if not class_name: if not class_name:
raise ValueError('cannot make "%s" into a class name' % name) raise ValueError('cannot make "%s" into a class name' % name)
class_names.append(class_name) class_names.append(class_name)
return ' '.join(class_names) return class_names
unicode_pattern = re.compile( unicode_pattern = re.compile(
r'(?:0x|x|\\x|U\+?|\\u)([0-9a-f]+)$|&#x([0-9a-f]+);$', re.IGNORECASE) r'(?:0x|x|\\x|U\+?|\\u)([0-9a-f]+)$|&#x([0-9a-f]+);$', re.IGNORECASE)
...@@ -296,10 +308,13 @@ unicode_pattern = re.compile( ...@@ -296,10 +308,13 @@ unicode_pattern = re.compile(
def unicode_code(code): def unicode_code(code):
r""" r"""
Convert a Unicode character code to a Unicode character. Convert a Unicode character code to a Unicode character.
(Directive option conversion function.)
Codes may be decimal numbers, hexadecimal numbers (prefixed by ``0x``, Codes may be decimal numbers, hexadecimal numbers (prefixed by ``0x``,
``x``, ``\x``, ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style ``x``, ``\x``, ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style
numeric character entities (e.g. ``&#x262E;``). Other text remains as-is. numeric character entities (e.g. ``&#x262E;``). Other text remains as-is.
Raise ValueError for illegal Unicode code values.
""" """
try: try:
if code.isdigit(): # decimal number if code.isdigit(): # decimal number
...@@ -315,6 +330,10 @@ def unicode_code(code): ...@@ -315,6 +330,10 @@ def unicode_code(code):
raise ValueError('code too large (%s)' % detail) raise ValueError('code too large (%s)' % detail)
def single_char_or_unicode(argument): def single_char_or_unicode(argument):
"""
A single character is returned as-is. Unicode characters codes are
converted as in `unicode_code`. (Directive option conversion function.)
"""
char = unicode_code(argument) char = unicode_code(argument)
if len(char) > 1: if len(char) > 1:
raise ValueError('%r invalid; must be a single character or ' raise ValueError('%r invalid; must be a single character or '
...@@ -322,6 +341,10 @@ def single_char_or_unicode(argument): ...@@ -322,6 +341,10 @@ def single_char_or_unicode(argument):
return char return char
def single_char_or_whitespace_or_unicode(argument): def single_char_or_whitespace_or_unicode(argument):
"""
As with `single_char_or_unicode`, but "tab" and "space" are also supported.
(Directive option conversion function.)
"""
if argument == 'tab': if argument == 'tab':
char = '\t' char = '\t'
elif argument == 'space': elif argument == 'space':
...@@ -331,12 +354,23 @@ def single_char_or_whitespace_or_unicode(argument): ...@@ -331,12 +354,23 @@ def single_char_or_whitespace_or_unicode(argument):
return char return char
def positive_int(argument): def positive_int(argument):
"""
Converts the argument into an integer. Raises ValueError for negative,
zero, or non-integer values. (Directive option conversion function.)
"""
value = int(argument) value = int(argument)
if value < 1: if value < 1:
raise ValueError('negative or zero value; must be positive') raise ValueError('negative or zero value; must be positive')
return value return value
def positive_int_list(argument): def positive_int_list(argument):
"""
Converts a space- or comma-separated list of values into a Python list
of integers.
(Directive option conversion function.)
Raises ValueError for non-positive-integer values.
"""
if ',' in argument: if ',' in argument:
entries = argument.split(',') entries = argument.split(',')
else: else:
...@@ -344,6 +378,12 @@ def positive_int_list(argument): ...@@ -344,6 +378,12 @@ def positive_int_list(argument):
return [positive_int(entry) for entry in entries] return [positive_int(entry) for entry in entries]
def encoding(argument): def encoding(argument):
"""
Verfies the encoding argument by lookup.
(Directive option conversion function.)
Raises ValueError for unknown encodings.
"""
try: try:
codecs.lookup(argument) codecs.lookup(argument)
except LookupError: except LookupError:
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3155 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-02 23:57:06 +0200 (Sat, 02 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -30,10 +30,10 @@ def make_admonition(node_class, name, arguments, options, content, lineno, ...@@ -30,10 +30,10 @@ def make_admonition(node_class, name, arguments, options, content, lineno,
admonition_node += nodes.title(title_text, '', *textnodes) admonition_node += nodes.title(title_text, '', *textnodes)
admonition_node += messages admonition_node += messages
if options.has_key('class'): if options.has_key('class'):
class_value = options['class'] classes = options['class']
else: else:
class_value = 'admonition-' + nodes.make_id(title_text) classes = ['admonition-' + nodes.make_id(title_text)]
admonition_node.set_class(class_value) admonition_node['classes'] += classes
state.nested_parse(content, content_offset, admonition_node) state.nested_parse(content, content_offset, admonition_node)
return [admonition_node] return [admonition_node]
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@python.org # Contact: goodger@python.org
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3206 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-12 01:16:11 +0200 (Tue, 12 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -16,14 +16,16 @@ __docformat__ = 'reStructuredText' ...@@ -16,14 +16,16 @@ __docformat__ = 'reStructuredText'
import sys import sys
from docutils import nodes from docutils import nodes
from docutils.parsers.rst import directives from docutils.parsers.rst import directives
from docutils.parsers.rst.roles import set_classes
def topic(name, arguments, options, content, lineno, def topic(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine, content_offset, block_text, state, state_machine,
node_class=nodes.topic): node_class=nodes.topic):
if not state_machine.match_titles: if not (state_machine.match_titles
or isinstance(state_machine.node, nodes.sidebar)):
error = state_machine.reporter.error( error = state_machine.reporter.error(
'The "%s" directive may not be used within topics, sidebars, ' 'The "%s" directive may not be used within topics '
'or body elements.' % name, 'or body elements.' % name,
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
return [error] return [error]
...@@ -44,8 +46,7 @@ def topic(name, arguments, options, content, lineno, ...@@ -44,8 +46,7 @@ def topic(name, arguments, options, content, lineno,
messages.extend(more_messages) messages.extend(more_messages)
text = '\n'.join(content) text = '\n'.join(content)
node = node_class(text, *(titles + messages)) node = node_class(text, *(titles + messages))
if options.has_key('class'): node['classes'] += options.get('class', [])
node.set_class(options['class'])
if text: if text:
state.nested_parse(content, content_offset, node) state.nested_parse(content, content_offset, node)
return [node] return [node]
...@@ -56,6 +57,11 @@ topic.content = 1 ...@@ -56,6 +57,11 @@ topic.content = 1
def sidebar(name, arguments, options, content, lineno, def sidebar(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
if isinstance(state_machine.node, nodes.sidebar):
error = state_machine.reporter.error(
'The "%s" directive may not be used within a sidebar element.'
% name, nodes.literal_block(block_text, block_text), line=lineno)
return [error]
return topic(name, arguments, options, content, lineno, return topic(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine, content_offset, block_text, state, state_machine,
node_class=nodes.sidebar) node_class=nodes.sidebar)
...@@ -72,7 +78,7 @@ def line_block(name, arguments, options, content, lineno, ...@@ -72,7 +78,7 @@ def line_block(name, arguments, options, content, lineno,
'Content block expected for the "%s" directive; none found.' 'Content block expected for the "%s" directive; none found.'
% name, nodes.literal_block(block_text, block_text), line=lineno) % name, nodes.literal_block(block_text, block_text), line=lineno)
return [warning] return [warning]
block = nodes.line_block() block = nodes.line_block(classes=options.get('class', []))
node_list = [block] node_list = [block]
for line_text in content: for line_text in content:
text_nodes, messages = state.inline_text(line_text.strip(), text_nodes, messages = state.inline_text(line_text.strip(),
...@@ -91,6 +97,7 @@ line_block.content = 1 ...@@ -91,6 +97,7 @@ line_block.content = 1
def parsed_literal(name, arguments, options, content, lineno, def parsed_literal(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
set_classes(options)
return block(name, arguments, options, content, lineno, return block(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine, content_offset, block_text, state, state_machine,
node_class=nodes.literal_block) node_class=nodes.literal_block)
...@@ -124,7 +131,7 @@ rubric.options = {'class': directives.class_option} ...@@ -124,7 +131,7 @@ rubric.options = {'class': directives.class_option}
def epigraph(name, arguments, options, content, lineno, def epigraph(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
block_quote, messages = state.block_quote(content, content_offset) block_quote, messages = state.block_quote(content, content_offset)
block_quote.set_class('epigraph') block_quote['classes'].append('epigraph')
return [block_quote] + messages return [block_quote] + messages
epigraph.content = 1 epigraph.content = 1
...@@ -132,7 +139,7 @@ epigraph.content = 1 ...@@ -132,7 +139,7 @@ epigraph.content = 1
def highlights(name, arguments, options, content, lineno, def highlights(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
block_quote, messages = state.block_quote(content, content_offset) block_quote, messages = state.block_quote(content, content_offset)
block_quote.set_class('highlights') block_quote['classes'].append('highlights')
return [block_quote] + messages return [block_quote] + messages
highlights.content = 1 highlights.content = 1
...@@ -140,7 +147,7 @@ highlights.content = 1 ...@@ -140,7 +147,7 @@ highlights.content = 1
def pull_quote(name, arguments, options, content, lineno, def pull_quote(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
block_quote, messages = state.block_quote(content, content_offset) block_quote, messages = state.block_quote(content, content_offset)
block_quote.set_class('pull-quote') block_quote['classes'].append('pull-quote')
return [block_quote] + messages return [block_quote] + messages
pull_quote.content = 1 pull_quote.content = 1
...@@ -154,8 +161,7 @@ def compound(name, arguments, options, content, lineno, ...@@ -154,8 +161,7 @@ def compound(name, arguments, options, content, lineno,
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
return [error] return [error]
node = nodes.compound(text) node = nodes.compound(text)
if options.has_key('class'): node['classes'] += options.get('class', [])
node.set_class(options['class'])
state.nested_parse(content, content_offset, node) state.nested_parse(content, content_offset, node)
return [node] return [node]
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3038 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-03-14 17:16:57 +0100 (Mon, 14 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -34,7 +34,7 @@ def meta(name, arguments, options, content, lineno, ...@@ -34,7 +34,7 @@ def meta(name, arguments, options, content, lineno,
'Empty meta directive.', 'Empty meta directive.',
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
node += error node += error
return node.get_children() return node.children
meta.content = 1 meta.content = 1
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3347 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-05-18 20:17:33 +0200 (Wed, 18 May 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -14,27 +14,43 @@ __docformat__ = 'reStructuredText' ...@@ -14,27 +14,43 @@ __docformat__ = 'reStructuredText'
import sys import sys
from docutils import nodes, utils from docutils import nodes, utils
from docutils.parsers.rst import directives, states from docutils.parsers.rst import directives, states
from docutils.nodes import whitespace_normalize_name from docutils.nodes import fully_normalize_name
from docutils.parsers.rst.roles import set_classes
try: try:
import Image # PIL import Image # PIL
except ImportError: except ImportError:
Image = None Image = None
align_values = ('top', 'middle', 'bottom', 'left', 'center', 'right') align_h_values = ('left', 'center', 'right')
align_v_values = ('top', 'middle', 'bottom')
align_values = align_v_values + align_h_values
def align(argument): def align(argument):
return directives.choice(argument, align_values) return directives.choice(argument, align_values)
def image(name, arguments, options, content, lineno, def image(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
if options.has_key('align'):
# check for align_v values only
if isinstance(state, states.SubstitutionDef):
if options['align'] not in align_v_values:
error = state_machine.reporter.error(
'Error in "%s" directive: "%s" is not a valid value for '
'the "align" option within a substitution definition. '
'Valid values for "align" are: "%s".'
% (name, options['align'], '", "'.join(align_v_values)),
nodes.literal_block(block_text, block_text), line=lineno)
return [error]
elif options['align'] not in align_h_values:
error = state_machine.reporter.error(
'Error in "%s" directive: "%s" is not a valid value for '
'the "align" option. Valid values for "align" are: "%s".'
% (name, options['align'], '", "'.join(align_h_values)),
nodes.literal_block(block_text, block_text), line=lineno)
return [error]
messages = [] messages = []
reference = ''.join(arguments[0].split('\n')) reference = directives.uri(arguments[0])
if reference.find(' ') != -1:
error = state_machine.reporter.error(
'Image URI contains whitespace.',
nodes.literal_block(block_text, block_text), line=lineno)
return [error]
options['uri'] = reference options['uri'] = reference
reference_node = None reference_node = None
if options.has_key('target'): if options.has_key('target'):
...@@ -44,12 +60,13 @@ def image(name, arguments, options, content, lineno, ...@@ -44,12 +60,13 @@ def image(name, arguments, options, content, lineno,
if target_type == 'refuri': if target_type == 'refuri':
reference_node = nodes.reference(refuri=data) reference_node = nodes.reference(refuri=data)
elif target_type == 'refname': elif target_type == 'refname':
reference_node = nodes.reference( reference_node = nodes.reference(refname=data,
refname=data, name=whitespace_normalize_name(options['target'])) name=fully_normalize_name(options['target']))
state.document.note_refname(reference_node) state.document.note_refname(reference_node)
else: # malformed target else: # malformed target
messages.append(data) # data is a system message messages.append(data) # data is a system message
del options['target'] del options['target']
set_classes(options)
image_node = nodes.image(block_text, **options) image_node = nodes.image(block_text, **options)
if reference_node: if reference_node:
reference_node += image_node reference_node += image_node
...@@ -66,31 +83,38 @@ image.options = {'alt': directives.unchanged, ...@@ -66,31 +83,38 @@ image.options = {'alt': directives.unchanged,
'target': directives.unchanged_required, 'target': directives.unchanged_required,
'class': directives.class_option} 'class': directives.class_option}
def figure_align(argument):
return directives.choice(argument, align_h_values)
def figure(name, arguments, options, content, lineno, def figure(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
figwidth = options.setdefault('figwidth') figwidth = options.setdefault('figwidth')
figclass = options.setdefault('figclass') figclasses = options.setdefault('figclass')
align = options.setdefault('align')
del options['figwidth'] del options['figwidth']
del options['figclass'] del options['figclass']
del options['align']
(image_node,) = image(name, arguments, options, content, lineno, (image_node,) = image(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine) content_offset, block_text, state, state_machine)
if isinstance(image_node, nodes.system_message): if isinstance(image_node, nodes.system_message):
return [image_node] return [image_node]
figure_node = nodes.figure('', image_node) figure_node = nodes.figure('', image_node)
if figwidth == 'image': if figwidth == 'image':
if Image: if Image and state.document.settings.file_insertion_enabled:
# PIL doesn't like Unicode paths: # PIL doesn't like Unicode paths:
try: try:
i = Image.open(str(image_node['uri'])) i = Image.open(str(image_node['uri']))
except (IOError, UnicodeError): except (IOError, UnicodeError):
pass pass
else: else:
state.document.settings.record_dependencies.add(reference) state.document.settings.record_dependencies.add(image_node['uri'])
figure_node['width'] = i.size[0] figure_node['width'] = i.size[0]
elif figwidth is not None: elif figwidth is not None:
figure_node['width'] = figwidth figure_node['width'] = figwidth
if figclass: if figclasses:
figure_node.set_class(figclass) figure_node['classes'] += figclasses
if align:
figure_node['align'] = align
if content: if content:
node = nodes.Element() # anonymous container for parsing node = nodes.Element() # anonymous container for parsing
state.nested_parse(content, content_offset, node) state.nested_parse(content, content_offset, node)
...@@ -119,4 +143,5 @@ figure.arguments = (1, 0, 1) ...@@ -119,4 +143,5 @@ figure.arguments = (1, 0, 1)
figure.options = {'figwidth': figwidth_value, figure.options = {'figwidth': figwidth_value,
'figclass': directives.class_option} 'figclass': directives.class_option}
figure.options.update(image.options) figure.options.update(image.options)
figure.options['align'] = figure_align
figure.content = 1 figure.content = 1
# Authors: David Goodger, Dethe Elza # Authors: David Goodger, Dethe Elza
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3129 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-03-26 17:21:28 +0100 (Sat, 26 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
"""Miscellaneous directives.""" """Miscellaneous directives."""
...@@ -24,15 +24,15 @@ except ImportError: ...@@ -24,15 +24,15 @@ except ImportError:
def include(name, arguments, options, content, lineno, def include(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
"""Include a reST file as part of the content of this reST file.""" """Include a reST file as part of the content of this reST file."""
if not state.document.settings.file_insertion_enabled:
warning = state_machine.reporter.warning(
'"%s" directive disabled.' % name,
nodes.literal_block(block_text, block_text), line=lineno)
return [warning]
source = state_machine.input_lines.source( source = state_machine.input_lines.source(
lineno - state_machine.input_offset - 1) lineno - state_machine.input_offset - 1)
source_dir = os.path.dirname(os.path.abspath(source)) source_dir = os.path.dirname(os.path.abspath(source))
path = ''.join(arguments[0].splitlines()) path = directives.path(arguments[0])
if path.find(' ') != -1:
error = state_machine.reporter.error(
'"%s" directive path contains whitespace.' % name,
nodes.literal_block(block_text, block_text), line=lineno)
return [error]
path = os.path.normpath(os.path.join(source_dir, path)) path = os.path.normpath(os.path.join(source_dir, path))
path = utils.relative_path(None, path) path = utils.relative_path(None, path)
encoding = options.get('encoding', state.document.settings.input_encoding) encoding = options.get('encoding', state.document.settings.input_encoding)
...@@ -48,7 +48,14 @@ def include(name, arguments, options, content, lineno, ...@@ -48,7 +48,14 @@ def include(name, arguments, options, content, lineno,
% (name, error.__class__.__name__, error), % (name, error.__class__.__name__, error),
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
return [severe] return [severe]
include_text = include_file.read() try:
include_text = include_file.read()
except UnicodeError, error:
severe = state_machine.reporter.severe(
'Problem with "%s" directive:\n%s: %s'
% (name, error.__class__.__name__, error),
nodes.literal_block(block_text, block_text), line=lineno)
return [severe]
if options.has_key('literal'): if options.has_key('literal'):
literal_block = nodes.literal_block(include_text, include_text, literal_block = nodes.literal_block(include_text, include_text,
source=path) source=path)
...@@ -74,6 +81,14 @@ def raw(name, arguments, options, content, lineno, ...@@ -74,6 +81,14 @@ def raw(name, arguments, options, content, lineno,
Content may be included inline (content section of directive) or Content may be included inline (content section of directive) or
imported from a file or url. imported from a file or url.
""" """
print 2
if ( not state.document.settings.raw_enabled
or (not state.document.settings.file_insertion_enabled
and (options.has_key('file') or options.has_key('url'))) ):
warning = state_machine.reporter.warning(
'"%s" directive disabled.' % name,
nodes.literal_block(block_text, block_text), line=lineno)
return [warning]
attributes = {'format': ' '.join(arguments[0].lower().split())} attributes = {'format': ' '.join(arguments[0].lower().split())}
encoding = options.get('encoding', state.document.settings.input_encoding) encoding = options.get('encoding', state.document.settings.input_encoding)
if content: if content:
...@@ -106,7 +121,14 @@ def raw(name, arguments, options, content, lineno, ...@@ -106,7 +121,14 @@ def raw(name, arguments, options, content, lineno,
'Problems with "%s" directive path:\n%s.' % (name, error), 'Problems with "%s" directive path:\n%s.' % (name, error),
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
return [severe] return [severe]
text = raw_file.read() try:
text = raw_file.read()
except UnicodeError, error:
severe = state_machine.reporter.severe(
'Problem with "%s" directive:\n%s: %s'
% (name, error.__class__.__name__, error),
nodes.literal_block(block_text, block_text), line=lineno)
return [severe]
attributes['source'] = path attributes['source'] = path
elif options.has_key('url'): elif options.has_key('url'):
if not urllib2: if not urllib2:
...@@ -128,7 +150,14 @@ def raw(name, arguments, options, content, lineno, ...@@ -128,7 +150,14 @@ def raw(name, arguments, options, content, lineno,
raw_file = io.StringInput( raw_file = io.StringInput(
source=raw_text, source_path=source, encoding=encoding, source=raw_text, source_path=source, encoding=encoding,
error_handler=state.document.settings.input_encoding_error_handler) error_handler=state.document.settings.input_encoding_error_handler)
text = raw_file.read() try:
text = raw_file.read()
except UnicodeError, error:
severe = state_machine.reporter.severe(
'Problem with "%s" directive:\n%s: %s'
% (name, error.__class__.__name__, error),
nodes.literal_block(block_text, block_text), line=lineno)
return [severe]
attributes['source'] = source attributes['source'] = source
else: else:
error = state_machine.reporter.warning( error = state_machine.reporter.warning(
...@@ -140,7 +169,7 @@ def raw(name, arguments, options, content, lineno, ...@@ -140,7 +169,7 @@ def raw(name, arguments, options, content, lineno,
raw.arguments = (1, 0, 1) raw.arguments = (1, 0, 1)
raw.options = {'file': directives.path, raw.options = {'file': directives.path,
'url': directives.path, 'url': directives.uri,
'encoding': directives.encoding} 'encoding': directives.encoding}
raw.content = 1 raw.content = 1
...@@ -160,8 +189,7 @@ def replace(name, arguments, options, content, lineno, ...@@ -160,8 +189,7 @@ def replace(name, arguments, options, content, lineno,
messages = [] messages = []
for node in element: for node in element:
if isinstance(node, nodes.system_message): if isinstance(node, nodes.system_message):
if node.has_key('backrefs'): node['backrefs'] = []
del node['backrefs']
messages.append(node) messages.append(node)
error = state_machine.reporter.error( error = state_machine.reporter.error(
'Error in "%s" directive: may contain a single paragraph ' 'Error in "%s" directive: may contain a single paragraph '
......
# Author: David Goodger, Dmitry Jemerov # Author: David Goodger, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3199 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-09 03:32:29 +0200 (Sat, 09 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -26,10 +26,24 @@ def backlinks(arg): ...@@ -26,10 +26,24 @@ def backlinks(arg):
def contents(name, arguments, options, content, lineno, def contents(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
"""Table of contents.""" """
Table of contents.
The table of contents is generated in two passes: initial parse and
transform. During the initial parse, a 'pending' element is generated
which acts as a placeholder, storing the TOC title and any options
internally. At a later stage in the processing, the 'pending' element is
replaced by a 'topic' element, a title and the table of contents proper.
"""
if not (state_machine.match_titles
or isinstance(state_machine.node, nodes.sidebar)):
error = state_machine.reporter.error(
'The "%s" directive may not be used within topics '
'or body elements.' % name,
nodes.literal_block(block_text, block_text), line=lineno)
return [error]
document = state_machine.document document = state_machine.document
language = languages.get_language(document.settings.language_code) language = languages.get_language(document.settings.language_code)
if arguments: if arguments:
title_text = arguments[0] title_text = arguments[0]
text_nodes, messages = state.inline_text(title_text, lineno) text_nodes, messages = state.inline_text(title_text, lineno)
...@@ -40,24 +54,17 @@ def contents(name, arguments, options, content, lineno, ...@@ -40,24 +54,17 @@ def contents(name, arguments, options, content, lineno,
title = None title = None
else: else:
title = nodes.title('', language.labels['contents']) title = nodes.title('', language.labels['contents'])
topic = nodes.topic(classes=['contents'])
topic = nodes.topic(CLASS='contents') topic['classes'] += options.get('class', [])
cls = options.get('class')
if cls:
topic.set_class(cls)
if title: if title:
name = title.astext() name = title.astext()
topic += title topic += title
else: else:
name = language.labels['contents'] name = language.labels['contents']
name = nodes.fully_normalize_name(name) name = nodes.fully_normalize_name(name)
if not document.has_name(name): if not document.has_name(name):
topic['name'] = name topic['names'].append(name)
document.note_implicit_target(topic) document.note_implicit_target(topic)
pending = nodes.pending(parts.Contents, rawsource=block_text) pending = nodes.pending(parts.Contents, rawsource=block_text)
pending.details.update(options) pending.details.update(options)
document.note_pending(pending) document.note_pending(pending)
...@@ -82,3 +89,36 @@ sectnum.options = {'depth': int, ...@@ -82,3 +89,36 @@ sectnum.options = {'depth': int,
'start': int, 'start': int,
'prefix': directives.unchanged_required, 'prefix': directives.unchanged_required,
'suffix': directives.unchanged_required} 'suffix': directives.unchanged_required}
def header_footer(node, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
"""Contents of document header or footer."""
if not content:
warning = state_machine.reporter.warning(
'Content block expected for the "%s" directive; none found.'
% name, nodes.literal_block(block_text, block_text),
line=lineno)
node.append(nodes.paragraph(
'', 'Problem with the "%s" directive: no content supplied.' % name))
return [warning]
text = '\n'.join(content)
state.nested_parse(content, content_offset, node)
return []
def header(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
decoration = state_machine.document.get_decoration()
node = decoration.get_header()
return header_footer(node, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine)
header.content = 1
def footer(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
decoration = state_machine.document.get_decoration()
node = decoration.get_footer()
return header_footer(node, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine)
footer.content = 1
# Author: David Goodger, Dmitry Jemerov # Author: David Goodger, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 856 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2002-10-24 03:01:53 +0200 (Thu, 24 Oct 2002) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2224 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2004-06-05 21:40:46 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# Internationalization details are documented in # Internationalization details are documented in
......
# Author: Jannie Hofmeyr # Author: Jannie Hofmeyr
# Contact: jhsh@sun.ac.za # Contact: jhsh@sun.ac.za
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -42,6 +42,7 @@ directives = { ...@@ -42,6 +42,7 @@ directives = {
#'faq': 'questions', #'faq': 'questions',
'table (translation required)': 'table', 'table (translation required)': 'table',
'csv-table (translation required)': 'csv-table', 'csv-table (translation required)': 'csv-table',
'list-table (translation required)': 'list-table',
'meta': 'meta', 'meta': 'meta',
#'beeldkaart': 'imagemap', #'beeldkaart': 'imagemap',
'beeld': 'image', 'beeld': 'image',
...@@ -55,6 +56,8 @@ directives = { ...@@ -55,6 +56,8 @@ directives = {
'inhoud': 'contents', 'inhoud': 'contents',
'sectnum': 'sectnum', 'sectnum': 'sectnum',
'section-numbering': 'sectnum', 'section-numbering': 'sectnum',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#'voetnote': 'footnotes', #'voetnote': 'footnotes',
#'aanhalings': 'citations', #'aanhalings': 'citations',
'teikennotas': 'target-notes', 'teikennotas': 'target-notes',
......
# Author: Marek Blaha # Author: Marek Blaha
# Contact: mb@dat.cz # Contact: mb@dat.cz
# Revision: $Revision: 1.1.4.4 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -43,6 +43,7 @@ directives = { ...@@ -43,6 +43,7 @@ directives = {
#'faq': 'questions', #'faq': 'questions',
u'table (translation required)': 'table', u'table (translation required)': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
u'meta (translation required)': 'meta', u'meta (translation required)': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
u'image (translation required)': 'image', # obrazek u'image (translation required)': 'image', # obrazek
...@@ -56,6 +57,8 @@ directives = { ...@@ -56,6 +57,8 @@ directives = {
u'obsah': 'contents', u'obsah': 'contents',
u'sectnum (translation required)': 'sectnum', u'sectnum (translation required)': 'sectnum',
u'section-numbering (translation required)': 'sectnum', u'section-numbering (translation required)': 'sectnum',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
u'target-notes (translation required)': 'target-notes', u'target-notes (translation required)': 'target-notes',
......
# Authors: Engelbert Gruber; Felix Wiemann # Authors: Engelbert Gruber; Felix Wiemann
# Contact: grubert@users.sourceforge.net # Contact: grubert@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -42,6 +42,7 @@ directives = { ...@@ -42,6 +42,7 @@ directives = {
#'fragen': 'questions', #'fragen': 'questions',
'tabelle': 'table', 'tabelle': 'table',
'csv-tabelle': 'csv-table', 'csv-tabelle': 'csv-table',
'list-table (translation required)': 'list-table',
'meta': 'meta', 'meta': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
'bild': 'image', 'bild': 'image',
...@@ -59,6 +60,8 @@ directives = { ...@@ -59,6 +60,8 @@ directives = {
'kapitel-nummerierung': 'sectnum', 'kapitel-nummerierung': 'sectnum',
'abschnitts-nummerierung': 'sectnum', 'abschnitts-nummerierung': 'sectnum',
u'linkziel-fu\xdfnoten': 'target-notes', u'linkziel-fu\xdfnoten': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'fu\xdfnoten': 'footnotes', #u'fu\xdfnoten': 'footnotes',
#'zitate': 'citations', #'zitate': 'citations',
} }
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -41,6 +41,7 @@ directives = { ...@@ -41,6 +41,7 @@ directives = {
#'questions': 'questions', #'questions': 'questions',
'table': 'table', 'table': 'table',
'csv-table': 'csv-table', 'csv-table': 'csv-table',
'list-table': 'list-table',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
'meta': 'meta', 'meta': 'meta',
...@@ -56,6 +57,8 @@ directives = { ...@@ -56,6 +57,8 @@ directives = {
'contents': 'contents', 'contents': 'contents',
'sectnum': 'sectnum', 'sectnum': 'sectnum',
'section-numbering': 'sectnum', 'section-numbering': 'sectnum',
'header': 'header',
'footer': 'footer',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
'target-notes': 'target-notes', 'target-notes': 'target-notes',
......
# Author: Marcelo Huerta San Martin # Author: Marcelo Huerta San Martin
# Contact: richieadler@users.sourceforge.net # Contact: richieadler@users.sourceforge.net
# Revision: $Revision: 1.1.2.5 $ # Revision: $Revision: 3189 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-08 05:05:45 +0200 (Fri, 08 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -48,6 +48,7 @@ directives = { ...@@ -48,6 +48,7 @@ directives = {
u'tabelo': 'table', u'tabelo': 'table',
u'tabelo-vdk': 'csv-table', # "valoroj disigitaj per komoj" u'tabelo-vdk': 'csv-table', # "valoroj disigitaj per komoj"
u'tabelo-csv': 'csv-table', u'tabelo-csv': 'csv-table',
u'tabelo-lista': 'list-table',
u'meta': 'meta', u'meta': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
u'bildo': 'image', u'bildo': 'image',
...@@ -62,6 +63,8 @@ directives = { ...@@ -62,6 +63,8 @@ directives = {
u'enhavo': 'contents', u'enhavo': 'contents',
u'seknum': 'sectnum', u'seknum': 'sectnum',
u'sekcia-numerado': 'sectnum', u'sekcia-numerado': 'sectnum',
u'kapsekcio': 'header',
u'piedsekcio': 'footer',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
u'celaj-notoj': 'target-notes', u'celaj-notoj': 'target-notes',
......
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
# Author: Marcelo Huerta San Martn # Author: Marcelo Huerta San Martn
# Contact: richieadler@users.sourceforge.net # Contact: richieadler@users.sourceforge.net
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 3190 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-08 05:06:12 +0200 (Fri, 08 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -50,6 +50,7 @@ directives = { ...@@ -50,6 +50,7 @@ directives = {
u'tabla': 'table', u'tabla': 'table',
u'tabla-vsc': 'csv-table', u'tabla-vsc': 'csv-table',
u'tabla-csv': 'csv-table', u'tabla-csv': 'csv-table',
u'tabla-lista': 'list-table',
u'meta': 'meta', u'meta': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
u'imagen': 'image', u'imagen': 'image',
...@@ -67,6 +68,8 @@ directives = { ...@@ -67,6 +68,8 @@ directives = {
u'numeracion-seccion': 'sectnum', u'numeracion-seccion': 'sectnum',
u'numeraci\u00f3n-secci\u00f3n': 'sectnum', u'numeraci\u00f3n-secci\u00f3n': 'sectnum',
u'notas-destino': 'target-notes', u'notas-destino': 'target-notes',
u'cabecera': 'header',
u'pie': 'footer',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
u'restructuredtext-test-directive': 'restructuredtext-test-directive'} u'restructuredtext-test-directive': 'restructuredtext-test-directive'}
......
# Author: Asko Soukka # Author: Asko Soukka
# Contact: asko.soukka@iki.fi # Contact: asko.soukka@iki.fi
# Revision: $Revision: 1.1.2.1 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -39,6 +39,7 @@ directives = { ...@@ -39,6 +39,7 @@ directives = {
u'lainaus': u'pull-quote', u'lainaus': u'pull-quote',
u'taulukko': u'table', u'taulukko': u'table',
u'csv-taulukko': u'csv-table', u'csv-taulukko': u'csv-table',
u'list-table (translation required)': 'list-table',
u'compound (translation required)': 'compound', u'compound (translation required)': 'compound',
#u'kysymykset': u'questions', #u'kysymykset': u'questions',
u'meta': u'meta', u'meta': u'meta',
...@@ -53,6 +54,8 @@ directives = { ...@@ -53,6 +54,8 @@ directives = {
u'rooli': u'role', u'rooli': u'role',
u'sis\u00e4llys': u'contents', u'sis\u00e4llys': u'contents',
u'kappale': u'sectnum', u'kappale': u'sectnum',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'alaviitteet': u'footnotes', #u'alaviitteet': u'footnotes',
#u'viitaukset': u'citations', #u'viitaukset': u'citations',
u'target-notes (translation required)': u'target-notes'} u'target-notes (translation required)': u'target-notes'}
......
# Authors: David Goodger; William Dode # Authors: David Goodger; William Dode
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -44,6 +44,7 @@ directives = { ...@@ -44,6 +44,7 @@ directives = {
#u'faq': 'questions', #u'faq': 'questions',
u'tableau': 'table', u'tableau': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
u'm\u00E9ta': 'meta', u'm\u00E9ta': 'meta',
#u'imagemap (translation required)': 'imagemap', #u'imagemap (translation required)': 'imagemap',
u'image': 'image', u'image': 'image',
...@@ -60,6 +61,8 @@ directives = { ...@@ -60,6 +61,8 @@ directives = {
u'sectnum': 'sectnum', u'sectnum': 'sectnum',
u'section-num\u00E9rot\u00E9e': 'sectnum', u'section-num\u00E9rot\u00E9e': 'sectnum',
u'liens': 'target-notes', u'liens': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'footnotes (translation required)': 'footnotes', #u'footnotes (translation required)': 'footnotes',
#u'citations (translation required)': 'citations', #u'citations (translation required)': 'citations',
} }
......
# Author: Nicola Larosa, Lele Gaifax # Author: Nicola Larosa, Lele Gaifax
# Contact: docutils@tekNico.net, lele@seldati.it # Contact: docutils@tekNico.net, lele@seldati.it
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # Beware: the italian translation of the reStructuredText documentation
# read <http://docutils.sf.net/docs/howto/i18n.html>. Two files must be # at http://docit.bice.dyndns.org/static/ReST, in particular
# translated for each language: one in docutils/languages, the other in # http://docit.bice.dyndns.org/static/ReST/ref/rst/directives.html, needs
# docutils/parsers/rst/languages. # to be synced with the content of this file.
""" """
Italian-language mappings for language-dependent features of Italian-language mappings for language-dependent features of
...@@ -34,14 +34,15 @@ directives = { ...@@ -34,14 +34,15 @@ directives = {
'blocco-interpretato': 'parsed-literal', 'blocco-interpretato': 'parsed-literal',
'rubrica': 'rubric', 'rubrica': 'rubric',
'epigrafe': 'epigraph', 'epigrafe': 'epigraph',
'evidenzia': 'highlights', 'punti-salienti': 'highlights',
'pull-quote (translation required)': 'pull-quote', 'estratto-evidenziato': 'pull-quote',
'compound (translation required)': 'compound', 'composito': 'compound',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
'tabella': 'table', 'tabella': 'table',
'csv-table (translation required)': 'csv-table', 'tabella-csv': 'csv-table',
'tabella-elenco': 'list-table',
'meta': 'meta', 'meta': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
'immagine': 'image', 'immagine': 'image',
...@@ -53,9 +54,12 @@ directives = { ...@@ -53,9 +54,12 @@ directives = {
'classe': 'class', 'classe': 'class',
'ruolo': 'role', 'ruolo': 'role',
'indice': 'contents', 'indice': 'contents',
'contenuti': 'contents',
'seznum': 'sectnum', 'seznum': 'sectnum',
'sezioni-autonumerate': 'sectnum', 'sezioni-autonumerate': 'sectnum',
'annota-riferimenti-esterni': 'target-notes', 'annota-riferimenti-esterni': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
'restructuredtext-test-directive': 'restructuredtext-test-directive'} 'restructuredtext-test-directive': 'restructuredtext-test-directive'}
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.4.4 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -43,6 +43,7 @@ directives = { ...@@ -43,6 +43,7 @@ directives = {
#'faq': 'questions', #'faq': 'questions',
u'table (translation required)': 'table', u'table (translation required)': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
'meta': 'meta', 'meta': 'meta',
#'imagemap': 'imagemap', #'imagemap': 'imagemap',
'imagem': 'image', 'imagem': 'image',
...@@ -56,6 +57,8 @@ directives = { ...@@ -56,6 +57,8 @@ directives = {
u'\u00EDndice': 'contents', u'\u00EDndice': 'contents',
'numsec': 'sectnum', 'numsec': 'sectnum',
u'numera\u00E7\u00E3o-de-se\u00E7\u00F5es': 'sectnum', u'numera\u00E7\u00E3o-de-se\u00E7\u00F5es': 'sectnum',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'notas-de-rorap\u00E9': 'footnotes', #u'notas-de-rorap\u00E9': 'footnotes',
#u'cita\u00E7\u00F5es': 'citations', #u'cita\u00E7\u00F5es': 'citations',
u'links-no-rodap\u00E9': 'target-notes', u'links-no-rodap\u00E9': 'target-notes',
......
# Author: Roman Suzi # Author: Roman Suzi
# Contact: rnd@onego.ru # Contact: rnd@onego.ru
# Revision: $Revision: 1.1.2.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -26,6 +26,7 @@ directives = { ...@@ -26,6 +26,7 @@ directives = {
u'compound (translation required)': 'compound', u'compound (translation required)': 'compound',
u'table (translation required)': 'table', u'table (translation required)': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
u'\u0441\u044b\u0440\u043e\u0439': u'raw', u'\u0441\u044b\u0440\u043e\u0439': u'raw',
u'\u0437\u0430\u043c\u0435\u043d\u0430': u'replace', u'\u0437\u0430\u043c\u0435\u043d\u0430': u'replace',
u'\u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430-restructuredtext': u'\u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f-\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430-restructuredtext':
...@@ -60,7 +61,9 @@ directives = { ...@@ -60,7 +61,9 @@ directives = {
u'\u0441\u043e\u0432\u0435\u0442': u'hint', u'\u0441\u043e\u0432\u0435\u0442': u'hint',
u'\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435': u'contents', u'\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435': u'contents',
u'\u0442\u0435\u043c\u0430': u'topic', u'\u0442\u0435\u043c\u0430': u'topic',
u'\u044d\u043f\u0438\u0433\u0440\u0430\u0444': u'epigraph'} u'\u044d\u043f\u0438\u0433\u0440\u0430\u0444': u'epigraph',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',}
"""Russian name to registered (in directives/__init__.py) directive name """Russian name to registered (in directives/__init__.py) directive name
mapping.""" mapping."""
......
# Author: Miroslav Vasko # Author: Miroslav Vasko
# Contact: zemiak@zoznam.sk # Contact: zemiak@zoznam.sk
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -42,6 +42,7 @@ directives = { ...@@ -42,6 +42,7 @@ directives = {
#u'faq': 'questions', #u'faq': 'questions',
u'table (translation required)': 'table', u'table (translation required)': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
u'meta': 'meta', u'meta': 'meta',
#u'imagemap': 'imagemap', #u'imagemap': 'imagemap',
u'obr\xe1zok': 'image', u'obr\xe1zok': 'image',
...@@ -56,6 +57,8 @@ directives = { ...@@ -56,6 +57,8 @@ directives = {
u'\xe8as\x9d': 'sectnum', u'\xe8as\x9d': 'sectnum',
u'\xe8as\x9d-\xe8\xedslovanie': 'sectnum', u'\xe8as\x9d-\xe8\xedslovanie': 'sectnum',
u'cie\xbeov\xe9-pozn\xe1mky': 'target-notes', u'cie\xbeov\xe9-pozn\xe1mky': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'footnotes': 'footnotes', #u'footnotes': 'footnotes',
#u'citations': 'citations', #u'citations': 'citations',
} }
......
# Author: Adam Chodorowski # Author: Adam Chodorowski
# Contact: chodorowski@users.sourceforge.net # Contact: chodorowski@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -42,6 +42,7 @@ directives = { ...@@ -42,6 +42,7 @@ directives = {
# u'vanliga-fr\u00e5gor': 'questions', # u'vanliga-fr\u00e5gor': 'questions',
u'table (translation required)': 'table', u'table (translation required)': 'table',
u'csv-table (translation required)': 'csv-table', u'csv-table (translation required)': 'csv-table',
u'list-table (translation required)': 'list-table',
u'meta': 'meta', u'meta': 'meta',
# u'bildkarta': 'imagemap', # FIXME: Translation might be too literal. # u'bildkarta': 'imagemap', # FIXME: Translation might be too literal.
u'bild': 'image', u'bild': 'image',
...@@ -55,6 +56,8 @@ directives = { ...@@ -55,6 +56,8 @@ directives = {
u'inneh\u00e5ll': 'contents', u'inneh\u00e5ll': 'contents',
u'sektionsnumrering': 'sectnum', u'sektionsnumrering': 'sectnum',
u'target-notes (translation required)': 'target-notes', u'target-notes (translation required)': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
# u'fotnoter': 'footnotes', # u'fotnoter': 'footnotes',
# u'citeringar': 'citations', # u'citeringar': 'citations',
} }
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.2.1 $ # Revision: $Revision: 3184 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2005-04-07 21:36:11 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please # New language mappings are welcome. Before doing a new translation, please
...@@ -41,6 +41,7 @@ directives = { ...@@ -41,6 +41,7 @@ directives = {
#'questions (translation required)': 'questions', #'questions (translation required)': 'questions',
'table (translation required)': 'table', 'table (translation required)': 'table',
'csv-table (translation required)': 'csv-table', 'csv-table (translation required)': 'csv-table',
'list-table (translation required)': 'list-table',
#'qa (translation required)': 'questions', #'qa (translation required)': 'questions',
#'faq (translation required)': 'questions', #'faq (translation required)': 'questions',
'meta (translation required)': 'meta', 'meta (translation required)': 'meta',
...@@ -56,6 +57,8 @@ directives = { ...@@ -56,6 +57,8 @@ directives = {
'contents (translation required)': 'contents', 'contents (translation required)': 'contents',
'sectnum (translation required)': 'sectnum', 'sectnum (translation required)': 'sectnum',
'section-numbering (translation required)': 'sectnum', 'section-numbering (translation required)': 'sectnum',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#'footnotes (translation required)': 'footnotes', #'footnotes (translation required)': 'footnotes',
#'citations (translation required)': 'citations', #'citations (translation required)': 'citations',
'target-notes (translation required)': 'target-notes', 'target-notes (translation required)': 'target-notes',
......
# Author: Edward Loper # Author: Edward Loper
# Contact: edloper@gradient.cis.upenn.edu # Contact: edloper@gradient.cis.upenn.edu
# Revision: $Revision: 1.1.4.4 $ # Revision: $Revision: 3155 $
# Date: $Date: 2005/01/07 13:26:03 $ # Date: $Date: 2005-04-02 23:57:06 +0200 (Sat, 02 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -174,7 +174,7 @@ def set_implicit_options(role_fn): ...@@ -174,7 +174,7 @@ def set_implicit_options(role_fn):
if not hasattr(role_fn, 'options') or role_fn.options is None: if not hasattr(role_fn, 'options') or role_fn.options is None:
role_fn.options = {'class': directives.class_option} role_fn.options = {'class': directives.class_option}
elif not role_fn.options.has_key('class'): elif not role_fn.options.has_key('class'):
role_fn.options['class'] = directives.class_option role_fn.options['class'] = directives.class_option
def register_generic_role(canonical_name, node_class): def register_generic_role(canonical_name, node_class):
"""For roles which simply wrap a given `node_class` around the text.""" """For roles which simply wrap a given `node_class` around the text."""
...@@ -195,6 +195,7 @@ class GenericRole: ...@@ -195,6 +195,7 @@ class GenericRole:
def __call__(self, role, rawtext, text, lineno, inliner, def __call__(self, role, rawtext, text, lineno, inliner,
options={}, content=[]): options={}, content=[]):
set_classes(options)
return [self.node_class(rawtext, utils.unescape(text), **options)], [] return [self.node_class(rawtext, utils.unescape(text), **options)], []
...@@ -233,6 +234,7 @@ def generic_custom_role(role, rawtext, text, lineno, inliner, ...@@ -233,6 +234,7 @@ def generic_custom_role(role, rawtext, text, lineno, inliner,
"""""" """"""
# Once nested inline markup is implemented, this and other methods should # Once nested inline markup is implemented, this and other methods should
# recursively call inliner.nested_parse(). # recursively call inliner.nested_parse().
set_classes(options)
return [nodes.inline(rawtext, utils.unescape(text), **options)], [] return [nodes.inline(rawtext, utils.unescape(text), **options)], []
generic_custom_role.options = {'class': directives.class_option} generic_custom_role.options = {'class': directives.class_option}
...@@ -265,6 +267,7 @@ def pep_reference_role(role, rawtext, text, lineno, inliner, ...@@ -265,6 +267,7 @@ def pep_reference_role(role, rawtext, text, lineno, inliner,
return [prb], [msg] return [prb], [msg]
# Base URL mainly used by inliner.pep_reference; so this is correct: # Base URL mainly used by inliner.pep_reference; so this is correct:
ref = inliner.document.settings.pep_base_url + inliner.pep_url % pepnum ref = inliner.document.settings.pep_base_url + inliner.pep_url % pepnum
set_classes(options)
return [nodes.reference(rawtext, 'PEP ' + utils.unescape(text), refuri=ref, return [nodes.reference(rawtext, 'PEP ' + utils.unescape(text), refuri=ref,
**options)], [] **options)], []
...@@ -284,6 +287,7 @@ def rfc_reference_role(role, rawtext, text, lineno, inliner, ...@@ -284,6 +287,7 @@ def rfc_reference_role(role, rawtext, text, lineno, inliner,
return [prb], [msg] return [prb], [msg]
# Base URL mainly used by inliner.rfc_reference, so this is correct: # Base URL mainly used by inliner.rfc_reference, so this is correct:
ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum
set_classes(options)
node = nodes.reference(rawtext, 'RFC ' + utils.unescape(text), refuri=ref, node = nodes.reference(rawtext, 'RFC ' + utils.unescape(text), refuri=ref,
**options) **options)
return [node], [] return [node], []
...@@ -299,10 +303,11 @@ def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]): ...@@ -299,10 +303,11 @@ def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
'an associated format.' % role, line=lineno) 'an associated format.' % role, line=lineno)
prb = inliner.problematic(rawtext, rawtext, msg) prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg] return [prb], [msg]
set_classes(options)
node = nodes.raw(rawtext, utils.unescape(text, 1), **options) node = nodes.raw(rawtext, utils.unescape(text, 1), **options)
return [node], [] return [node], []
raw_role.options = {'format': directives.class_option} raw_role.options = {'format': directives.unchanged}
register_canonical_role('raw', raw_role) register_canonical_role('raw', raw_role)
...@@ -329,3 +334,14 @@ register_canonical_role('target', unimplemented_role) ...@@ -329,3 +334,14 @@ register_canonical_role('target', unimplemented_role)
# This should remain unimplemented, for testing purposes: # This should remain unimplemented, for testing purposes:
register_canonical_role('restructuredtext-unimplemented-role', register_canonical_role('restructuredtext-unimplemented-role',
unimplemented_role) unimplemented_role)
def set_classes(options):
"""
Auxiliary function to set options['classes'] and delete
options['class'].
"""
if options.has_key('class'):
assert not options.has_key('classes')
options['classes'] = options['class']
del options['class']
This diff is collapsed.
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 1574 $
# Date: $Date: 2005/01/07 13:26:04 $ # Date: $Date: 2003-07-06 00:38:28 +0200 (Sun, 06 Jul 2003) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Authors: David Goodger; Ueli Schlaepfer # Authors: David Goodger; Ueli Schlaepfer
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 1645 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2003-08-27 22:50:43 +0200 (Wed, 27 Aug 2003) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3129 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2005-03-26 17:21:28 +0100 (Sat, 26 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -31,9 +31,9 @@ class Reader(standalone.Reader): ...@@ -31,9 +31,9 @@ class Reader(standalone.Reader):
config_section_dependencies = ('readers', 'standalone reader') config_section_dependencies = ('readers', 'standalone reader')
default_transforms = (references.Substitutions, default_transforms = (references.Substitutions,
references.PropagateTargets,
peps.Headers, peps.Headers,
peps.Contents, peps.Contents,
references.ChainedTargets,
references.AnonymousHyperlinks, references.AnonymousHyperlinks,
references.IndirectHyperlinks, references.IndirectHyperlinks,
peps.TargetNotes, peps.TargetNotes,
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.3.2.5 $ # Revision: $Revision: 3038 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2005-03-14 17:16:57 +0100 (Mon, 14 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -88,7 +88,7 @@ class DocstringFormattingVisitor(nodes.SparseNodeVisitor): ...@@ -88,7 +88,7 @@ class DocstringFormattingVisitor(nodes.SparseNodeVisitor):
node['docformat'] = docformat node['docformat'] = docformat
parser = self.get_parser(docformat) parser = self.get_parser(docformat)
parser.parse(text, self.document) parser.parse(text, self.document)
for child in self.document.get_children(): for child in self.document.children:
node.append(child) node.append(child)
self.document.current_source = self.document.current_line = None self.document.current_source = self.document.current_line = None
del self.document[:] del self.document[:]
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.3.2.5 $ # Revision: $Revision: 2449 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2004-07-25 03:45:27 +0200 (Sun, 25 Jul 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
""" """
:Author: David Goodger :Author: David Goodger
:Contact: goodger@users.sourceforge.net :Contact: goodger@users.sourceforge.net
:Revision: $Revision: 1.1.4.4 $ :Revision: $Revision: 1881 $
:Date: $Date: 2005/01/07 13:26:05 $ :Date: $Date: 2004-03-24 00:21:11 +0100 (Wed, 24 Mar 2004) $
:Copyright: This module has been placed in the public domain. :Copyright: This module has been placed in the public domain.
""" """
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3353 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2005-05-19 02:49:14 +0200 (Thu, 19 May 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -37,15 +37,26 @@ class Reader(readers.Reader): ...@@ -37,15 +37,26 @@ class Reader(readers.Reader):
'default).', 'default).',
['--no-doc-info'], ['--no-doc-info'],
{'dest': 'docinfo_xform', 'action': 'store_false', 'default': 1, {'dest': 'docinfo_xform', 'action': 'store_false', 'default': 1,
'validator': frontend.validate_boolean}),)) 'validator': frontend.validate_boolean}),
('Activate the promotion of lone subsection titles to '
'section subtitles (disabled by default).',
['--section-subtitles'],
{'dest': 'sectsubtitle_xform', 'action': 'store_true', 'default': 0,
'validator': frontend.validate_boolean}),
('Deactivate the promotion of lone subsection titles.',
['--no-section-subtitles'],
{'dest': 'sectsubtitle_xform', 'action': 'store_false',
'validator': frontend.validate_boolean}),
))
config_section = 'standalone reader' config_section = 'standalone reader'
config_section_dependencies = ('readers',) config_section_dependencies = ('readers',)
default_transforms = (references.Substitutions, default_transforms = (references.Substitutions,
references.PropagateTargets,
frontmatter.DocTitle, frontmatter.DocTitle,
frontmatter.SectionSubTitle,
frontmatter.DocInfo, frontmatter.DocInfo,
references.ChainedTargets,
references.AnonymousHyperlinks, references.AnonymousHyperlinks,
references.IndirectHyperlinks, references.IndirectHyperlinks,
references.Footnotes, references.Footnotes,
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2299 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2004-06-17 23:46:50 +0200 (Thu, 17 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Authors: David Goodger, Ueli Schlaepfer # Authors: David Goodger, Ueli Schlaepfer
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3066 $
# Date: $Date: 2005/01/07 13:26:05 $ # Date: $Date: 2005-03-21 18:33:42 +0100 (Mon, 21 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -59,7 +59,7 @@ class Transform: ...@@ -59,7 +59,7 @@ class Transform:
self.language = languages.get_language( self.language = languages.get_language(
document.settings.language_code) document.settings.language_code)
"""Language module local to this document.""" """Language module local to this document."""
def apply(self): def apply(self):
"""Override to apply the transform to the document tree.""" """Override to apply the transform to the document tree."""
...@@ -164,7 +164,6 @@ class Transformer(TransformSpec): ...@@ -164,7 +164,6 @@ class Transformer(TransformSpec):
decorated_list.sort() decorated_list.sort()
self.unknown_reference_resolvers.extend([f[1] for f in decorated_list]) self.unknown_reference_resolvers.extend([f[1] for f in decorated_list])
def apply_transforms(self): def apply_transforms(self):
"""Apply all of the stored transforms, in priority order.""" """Apply all of the stored transforms, in priority order."""
self.document.reporter.attach_observer( self.document.reporter.attach_observer(
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 853 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2002-10-24 02:51:10 +0200 (Thu, 24 Oct 2002) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Authors: David Goodger, Ueli Schlaepfer # Authors: David Goodger, Ueli Schlaepfer
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3351 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-05-19 00:27:52 +0200 (Thu, 19 May 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
Transforms related to the front matter of a document (information Transforms related to the front matter of a document or a section
found before the main text): (information found before the main text):
- `DocTitle`: Used to transform a lone top level section's title to - `DocTitle`: Used to transform a lone top level section's title to
the document title, and promote a remaining lone top-level section's the document title, and promote a remaining lone top-level section's
title to the document subtitle. title to the document subtitle.
- `SectionTitle`: Used to transform a lone subsection into a subtitle.
- `DocInfo`: Used to transform a bibliographic field list into docinfo - `DocInfo`: Used to transform a bibliographic field list into docinfo
elements. elements.
""" """
...@@ -23,7 +25,100 @@ from docutils import nodes, utils ...@@ -23,7 +25,100 @@ from docutils import nodes, utils
from docutils.transforms import TransformError, Transform from docutils.transforms import TransformError, Transform
class DocTitle(Transform): class TitlePromoter(Transform):
"""
Abstract base class for DocTitle and SectionSubTitle transforms.
"""
def promote_title(self, node):
"""
Transform the following tree::
<node>
<section>
<title>
...
into ::
<node>
<title>
...
`node` is normally a document.
"""
# `node` must not have a title yet.
assert not (len(node) and isinstance(node[0], nodes.title))
section, index = self.candidate_index(node)
if index is None:
return None
# Transfer the section's attributes to the node:
node.attributes.update(section.attributes)
# setup_child is called automatically for all nodes.
node[:] = (section[:1] # section title
+ node[:index] # everything that was in the
# node before the section
+ section[1:]) # everything that was in the section
assert isinstance(node[0], nodes.title)
return 1
def promote_subtitle(self, node):
"""
Transform the following node tree::
<node>
<title>
<section>
<title>
...
into ::
<node>
<title>
<subtitle>
...
"""
subsection, index = self.candidate_index(node)
if index is None:
return None
subtitle = nodes.subtitle()
# Transfer the subsection's attributes to the new subtitle:
# This causes trouble with list attributes! To do: Write a
# test case which catches direct access to the `attributes`
# dictionary and/or write a test case which shows problems in
# this particular case.
subtitle.attributes.update(subsection.attributes)
# We're losing the subtitle's attributes here! To do: Write a
# test case which shows this behavior.
# Transfer the contents of the subsection's title to the
# subtitle:
subtitle[:] = subsection[0][:]
node[:] = (node[:1] # title
+ [subtitle]
# everything that was before the section:
+ node[1:index]
# everything that was in the subsection:
+ subsection[1:])
return 1
def candidate_index(self, node):
"""
Find and return the promotion candidate and its index.
Return (None, None) if no valid candidate was found.
"""
index = node.first_child_not_matching_class(
nodes.PreBibliographic)
if index is None or len(node) > (index + 1) or \
not isinstance(node[index], nodes.section):
return None, None
else:
return node[index], index
class DocTitle(TitlePromoter):
""" """
In reStructuredText_, there is no way to specify a document title In reStructuredText_, there is no way to specify a document title
...@@ -50,7 +145,7 @@ class DocTitle(Transform): ...@@ -50,7 +145,7 @@ class DocTitle(Transform):
Once parsed, it looks like this:: Once parsed, it looks like this::
<document> <document>
<section name="top-level title"> <section names="top-level title">
<title> <title>
Top-Level Title Top-Level Title
<paragraph> <paragraph>
...@@ -58,7 +153,7 @@ class DocTitle(Transform): ...@@ -58,7 +153,7 @@ class DocTitle(Transform):
After running the DocTitle transform, we have:: After running the DocTitle transform, we have::
<document name="top-level title"> <document names="top-level title">
<title> <title>
Top-Level Title Top-Level Title
<paragraph> <paragraph>
...@@ -85,10 +180,10 @@ class DocTitle(Transform): ...@@ -85,10 +180,10 @@ class DocTitle(Transform):
After parsing and running the Section Promotion transform, the After parsing and running the Section Promotion transform, the
result is:: result is::
<document name="top-level title"> <document names="top-level title">
<title> <title>
Top-Level Title Top-Level Title
<subtitle name="second-level title"> <subtitle names="second-level title">
Second-Level Title Second-Level Title
<paragraph> <paragraph>
A paragraph. A paragraph.
...@@ -107,54 +202,47 @@ class DocTitle(Transform): ...@@ -107,54 +202,47 @@ class DocTitle(Transform):
def apply(self): def apply(self):
if not getattr(self.document.settings, 'doctitle_xform', 1): if not getattr(self.document.settings, 'doctitle_xform', 1):
return return
if self.promote_document_title(): if self.promote_title(self.document):
self.promote_document_subtitle() self.promote_subtitle(self.document)
def promote_document_title(self):
section, index = self.candidate_index()
if index is None:
return None
document = self.document
# Transfer the section's attributes to the document element (at root):
document.attributes.update(section.attributes)
document[:] = (section[:1] # section title
+ document[:index] # everything that was in the
# document before the section
+ section[1:]) # everything that was in the section
return 1
def promote_document_subtitle(self): class SectionSubTitle(TitlePromoter):
subsection, index = self.candidate_index()
if index is None:
return None
subtitle = nodes.subtitle()
# Transfer the subsection's attributes to the new subtitle:
subtitle.attributes.update(subsection.attributes)
# Transfer the contents of the subsection's title to the subtitle:
subtitle[:] = subsection[0][:]
document = self.document
document[:] = (document[:1] # document title
+ [subtitle]
# everything that was before the section:
+ document[1:index]
# everything that was in the subsection:
+ subsection[1:])
return 1
def candidate_index(self): """
""" This works like document subtitles, but for sections. For example, ::
Find and return the promotion candidate and its index.
Return (None, None) if no valid candidate was found. <section>
""" <title>
document = self.document Title
index = document.first_child_not_matching_class( <section>
nodes.PreBibliographic) <title>
if index is None or len(document) > (index + 1) or \ Subtitle
not isinstance(document[index], nodes.section): ...
return None, None
else: is transformed into ::
return document[index], index
<section>
<title>
Title
<subtitle>
Subtitle
...
For details refer to the docstring of DocTitle.
"""
default_priority = 350
def apply(self):
if not getattr(self.document.settings, 'sectsubtitle_xform', 1):
return
for section in self.document.traverse(lambda n:
isinstance(n, nodes.section)):
# On our way through the node tree, we are deleting
# sections, but we call self.promote_subtitle for those
# sections nonetheless. To do: Write a test case which
# shows the problem and discuss on Docutils-develop.
self.promote_subtitle(section)
class DocInfo(Transform): class DocInfo(Transform):
...@@ -189,7 +277,7 @@ class DocInfo(Transform): ...@@ -189,7 +277,7 @@ class DocInfo(Transform):
Status Status
<field_body> <field_body>
<paragraph> <paragraph>
$RCSfile: frontmatter.py,v $ $RCSfile$
... ...
After running the bibliographic field list transform, the After running the bibliographic field list transform, the
...@@ -258,11 +346,10 @@ class DocInfo(Transform): ...@@ -258,11 +346,10 @@ class DocInfo(Transform):
candidate = document[index] candidate = document[index]
if isinstance(candidate, nodes.field_list): if isinstance(candidate, nodes.field_list):
biblioindex = document.first_child_not_matching_class( biblioindex = document.first_child_not_matching_class(
nodes.Titular) (nodes.Titular, nodes.Decorative))
nodelist = self.extract_bibliographic(candidate) nodelist = self.extract_bibliographic(candidate)
del document[index] # untransformed field list (candidate) del document[index] # untransformed field list (candidate)
document[biblioindex:biblioindex] = nodelist document[biblioindex:biblioindex] = nodelist
return
def extract_bibliographic(self, field_list): def extract_bibliographic(self, field_list):
docinfo = nodes.docinfo() docinfo = nodes.docinfo()
...@@ -294,7 +381,7 @@ class DocInfo(Transform): ...@@ -294,7 +381,7 @@ class DocInfo(Transform):
raise TransformError raise TransformError
title = nodes.title(name, labels[canonical]) title = nodes.title(name, labels[canonical])
topics[canonical] = biblioclass( topics[canonical] = biblioclass(
'', title, CLASS=canonical, *field[1].children) '', title, classes=[canonical], *field[1].children)
else: else:
docinfo.append(biblioclass('', *field[1].children)) docinfo.append(biblioclass('', *field[1].children))
except TransformError: except TransformError:
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3155 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-04-02 23:57:06 +0200 (Sat, 02 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -45,7 +45,6 @@ class ClassAttribute(Transform): ...@@ -45,7 +45,6 @@ class ClassAttribute(Transform):
def apply(self): def apply(self):
pending = self.startnode pending = self.startnode
class_value = pending.details['class']
parent = pending.parent parent = pending.parent
child = pending child = pending
while parent: while parent:
...@@ -55,7 +54,7 @@ class ClassAttribute(Transform): ...@@ -55,7 +54,7 @@ class ClassAttribute(Transform):
if (isinstance(element, nodes.Invisible) or if (isinstance(element, nodes.Invisible) or
isinstance(element, nodes.system_message)): isinstance(element, nodes.system_message)):
continue continue
element.set_class(class_value) element['classes'] += pending.details['class']
pending.parent.remove(pending) pending.parent.remove(pending)
return return
else: else:
......
# Authors: David Goodger, Ueli Schlaepfer, Dmitry Jemerov # Authors: David Goodger, Ueli Schlaepfer, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3199 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-04-09 03:32:29 +0200 (Sat, 09 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -54,7 +54,7 @@ class SectNum(Transform): ...@@ -54,7 +54,7 @@ class SectNum(Transform):
generated = nodes.generated( generated = nodes.generated(
'', (self.prefix + '.'.join(numbers) + self.suffix '', (self.prefix + '.'.join(numbers) + self.suffix
+ u'\u00a0' * 3), + u'\u00a0' * 3),
CLASS='sectnum') classes=['sectnum'])
title.insert(0, generated) title.insert(0, generated)
title['auto'] = 1 title['auto'] = 1
if depth < self.maxdepth: if depth < self.maxdepth:
...@@ -84,14 +84,13 @@ class Contents(Transform): ...@@ -84,14 +84,13 @@ class Contents(Transform):
details = self.startnode.details details = self.startnode.details
if details.has_key('local'): if details.has_key('local'):
startnode = self.startnode.parent.parent startnode = self.startnode.parent.parent
# @@@ generate an error if the startnode (directive) not at while not (isinstance(startnode, nodes.section)
# section/document top-level? Drag it up until it is? or isinstance(startnode, nodes.document)):
while not isinstance(startnode, nodes.Structural): # find the ToC root: a direct ancestor of startnode
startnode = startnode.parent startnode = startnode.parent
else: else:
startnode = self.document startnode = self.document
self.toc_id = self.startnode.parent['ids'][0]
self.toc_id = self.startnode.parent['id']
if details.has_key('backlinks'): if details.has_key('backlinks'):
self.backlinks = details['backlinks'] self.backlinks = details['backlinks']
else: else:
...@@ -117,15 +116,17 @@ class Contents(Transform): ...@@ -117,15 +116,17 @@ class Contents(Transform):
title = section[0] title = section[0]
auto = title.get('auto') # May be set by SectNum. auto = title.get('auto') # May be set by SectNum.
entrytext = self.copy_and_filter(title) entrytext = self.copy_and_filter(title)
reference = nodes.reference('', '', refid=section['id'], reference = nodes.reference('', '', refid=section['ids'][0],
*entrytext) *entrytext)
ref_id = self.document.set_id(reference) ref_id = self.document.set_id(reference)
entry = nodes.paragraph('', '', reference) entry = nodes.paragraph('', '', reference)
item = nodes.list_item('', entry) item = nodes.list_item('', entry)
if self.backlinks == 'entry': if (self.backlinks in ('entry', 'top') and title.next_node(
title['refid'] = ref_id lambda n: isinstance(n, nodes.reference)) is None):
elif self.backlinks == 'top': if self.backlinks == 'entry':
title['refid'] = self.toc_id title['refid'] = ref_id
elif self.backlinks == 'top':
title['refid'] = self.toc_id
if level < depth: if level < depth:
subsects = self.build_contents(section, level) subsects = self.build_contents(section, level)
item += subsects item += subsects
...@@ -133,7 +134,7 @@ class Contents(Transform): ...@@ -133,7 +134,7 @@ class Contents(Transform):
if entries: if entries:
contents = nodes.bullet_list('', *entries) contents = nodes.bullet_list('', *entries)
if auto: if auto:
contents.set_class('auto-toc') contents['classes'].append('auto-toc')
return contents return contents
else: else:
return [] return []
...@@ -148,7 +149,7 @@ class Contents(Transform): ...@@ -148,7 +149,7 @@ class Contents(Transform):
class ContentsFilter(nodes.TreeCopyVisitor): class ContentsFilter(nodes.TreeCopyVisitor):
def get_entry_text(self): def get_entry_text(self):
return self.get_tree_copy().get_children() return self.get_tree_copy().children
def visit_citation_reference(self, node): def visit_citation_reference(self, node):
raise nodes.SkipNode raise nodes.SkipNode
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3129 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-03-26 17:21:28 +0100 (Sat, 26 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -46,7 +46,7 @@ class Headers(Transform): ...@@ -46,7 +46,7 @@ class Headers(Transform):
raise DataError('Document tree is empty.') raise DataError('Document tree is empty.')
header = self.document[0] header = self.document[0]
if not isinstance(header, nodes.field_list) or \ if not isinstance(header, nodes.field_list) or \
header.get('class') != 'rfc2822': 'rfc2822' not in header['classes']:
raise DataError('Document does not begin with an RFC-2822 ' raise DataError('Document does not begin with an RFC-2822 '
'header; it is not a PEP.') 'header; it is not a PEP.')
pep = None pep = None
...@@ -149,10 +149,10 @@ class Contents(Transform): ...@@ -149,10 +149,10 @@ class Contents(Transform):
language = languages.get_language(self.document.settings.language_code) language = languages.get_language(self.document.settings.language_code)
name = language.labels['contents'] name = language.labels['contents']
title = nodes.title('', name) title = nodes.title('', name)
topic = nodes.topic('', title, CLASS='contents') topic = nodes.topic('', title, classes=['contents'])
name = nodes.fully_normalize_name(name) name = nodes.fully_normalize_name(name)
if not self.document.has_name(name): if not self.document.has_name(name):
topic['name'] = name topic['names'].append(name)
self.document.note_implicit_target(topic) self.document.note_implicit_target(topic)
pending = nodes.pending(parts.Contents) pending = nodes.pending(parts.Contents)
topic += pending topic += pending
...@@ -244,7 +244,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor): ...@@ -244,7 +244,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor):
node.parent.replace(node, mask_email(node)) node.parent.replace(node, mask_email(node))
def visit_field_list(self, node): def visit_field_list(self, node):
if node.hasattr('class') and node['class'] == 'rfc2822': if 'rfc2822' in node['classes']:
raise nodes.SkipNode raise nodes.SkipNode
def visit_tgroup(self, node): def visit_tgroup(self, node):
...@@ -254,7 +254,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor): ...@@ -254,7 +254,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor):
def visit_colspec(self, node): def visit_colspec(self, node):
self.entry += 1 self.entry += 1
if self.pep_table and self.entry == 2: if self.pep_table and self.entry == 2:
node['class'] = 'num' node['classes'].append('num')
def visit_row(self, node): def visit_row(self, node):
self.entry = 0 self.entry = 0
...@@ -262,7 +262,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor): ...@@ -262,7 +262,7 @@ class PEPZeroSpecial(nodes.SparseNodeVisitor):
def visit_entry(self, node): def visit_entry(self, node):
self.entry += 1 self.entry += 1
if self.pep_table and self.entry == 2 and len(node) == 1: if self.pep_table and self.entry == 2 and len(node) == 1:
node['class'] = 'num' node['classes'].append('num')
p = node[0] p = node[0]
if isinstance(p, nodes.paragraph) and len(p) == 1: if isinstance(p, nodes.paragraph) and len(p) == 1:
text = p.astext() text = p.astext()
......
# Authors: David Goodger, Ueli Schlaepfer # Authors: David Goodger, Ueli Schlaepfer
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3186 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-04-07 21:51:45 +0200 (Thu, 07 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -32,19 +32,16 @@ class Decorations(Transform): ...@@ -32,19 +32,16 @@ class Decorations(Transform):
default_priority = 820 default_priority = 820
def apply(self): def apply(self):
header = self.generate_header() header_nodes = self.generate_header()
footer = self.generate_footer() if header_nodes:
if header or footer: decoration = self.document.get_decoration()
decoration = nodes.decoration() header = decoration.get_header()
decoration += header header.extend(header_nodes)
decoration += footer footer_nodes = self.generate_footer()
document = self.document if footer_nodes:
index = document.first_child_not_matching_class( decoration = self.document.get_decoration()
nodes.PreDecorative) footer = decoration.get_footer()
if index is None: footer.extend(footer_nodes)
document += decoration
else:
document[index:index] = [decoration]
def generate_header(self): def generate_header(self):
return None return None
...@@ -79,9 +76,7 @@ class Decorations(Transform): ...@@ -79,9 +76,7 @@ class Decorations(Transform):
nodes.reference('', 'reStructuredText', refuri='http://' nodes.reference('', 'reStructuredText', refuri='http://'
'docutils.sourceforge.net/rst.html'), 'docutils.sourceforge.net/rst.html'),
nodes.Text(' source.\n')]) nodes.Text(' source.\n')])
footer = nodes.footer() return [nodes.paragraph('', '', *text)]
footer += nodes.paragraph('', '', *text)
return footer
else: else:
return None return None
...@@ -97,13 +92,13 @@ class Messages(Transform): ...@@ -97,13 +92,13 @@ class Messages(Transform):
def apply(self): def apply(self):
unfiltered = self.document.transform_messages unfiltered = self.document.transform_messages
threshold = self.document.reporter['writer'].report_level threshold = self.document.reporter.report_level
messages = [] messages = []
for msg in unfiltered: for msg in unfiltered:
if msg['level'] >= threshold and not msg.parent: if msg['level'] >= threshold and not msg.parent:
messages.append(msg) messages.append(msg)
if messages: if messages:
section = nodes.section(CLASS='system-messages') section = nodes.section(classes=['system-messages'])
# @@@ get this from the language module? # @@@ get this from the language module?
section += nodes.title('', 'Docutils System Messages') section += nodes.title('', 'Docutils System Messages')
section += messages section += messages
...@@ -130,7 +125,7 @@ class SystemMessageFilterVisitor(nodes.SparseNodeVisitor): ...@@ -130,7 +125,7 @@ class SystemMessageFilterVisitor(nodes.SparseNodeVisitor):
pass pass
def visit_system_message(self, node): def visit_system_message(self, node):
if node['level'] < self.document.reporter['writer'].report_level: if node['level'] < self.document.reporter.report_level:
node.parent.remove(node) node.parent.remove(node)
...@@ -167,6 +162,21 @@ class FinalChecks(Transform): ...@@ -167,6 +162,21 @@ class FinalChecks(Transform):
if self.document.settings.expose_internals: if self.document.settings.expose_internals:
visitor = InternalAttributeExposer(self.document) visitor = InternalAttributeExposer(self.document)
self.document.walk(visitor) self.document.walk(visitor)
# *After* resolving all references, check for unreferenced
# targets:
for target in self.document.traverse():
if isinstance(target, nodes.target) and not target.referenced:
if target['names']:
naming = target['names'][0]
elif target['ids']:
naming = target['ids'][0]
else:
# Hack: Propagated targets always have their refid
# attribute set.
naming = target['refid']
self.document.reporter.info(
'Hyperlink target "%s" is not referenced.'
% naming, base_node=target)
class FinalCheckVisitor(nodes.SparseNodeVisitor): class FinalCheckVisitor(nodes.SparseNodeVisitor):
...@@ -206,7 +216,7 @@ class FinalCheckVisitor(nodes.SparseNodeVisitor): ...@@ -206,7 +216,7 @@ class FinalCheckVisitor(nodes.SparseNodeVisitor):
else: else:
del node['refname'] del node['refname']
node['refid'] = id node['refid'] = id
self.document.ids[id].referenced = 1 self.document.ids[id].note_referenced_by(id=id)
node.resolved = 1 node.resolved = 1
visit_footnote_reference = visit_citation_reference = visit_reference visit_footnote_reference = visit_citation_reference = visit_reference
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 3253 $
# Date: $Date: 2005/01/07 13:26:02 $ # Date: $Date: 2005-04-25 17:08:01 +0200 (Mon, 25 Apr 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -13,6 +13,7 @@ __docformat__ = 'reStructuredText' ...@@ -13,6 +13,7 @@ __docformat__ = 'reStructuredText'
import sys import sys
import os import os
import os.path import os.path
import warnings
from types import StringType, UnicodeType from types import StringType, UnicodeType
from docutils import ApplicationError, DataError from docutils import ApplicationError, DataError
from docutils import frontend, nodes from docutils import frontend, nodes
...@@ -39,27 +40,14 @@ class Reporter: ...@@ -39,27 +40,14 @@ class Reporter:
There is typically one Reporter object per process. A Reporter object is There is typically one Reporter object per process. A Reporter object is
instantiated with thresholds for reporting (generating warnings) and instantiated with thresholds for reporting (generating warnings) and
halting processing (raising exceptions), a switch to turn debug output on halting processing (raising exceptions), a switch to turn debug output on
or off, and an I/O stream for warnings. These are stored in the default or off, and an I/O stream for warnings. These are stored as instance
reporting category, '' (zero-length string). attributes.
Multiple reporting categories [#]_ may be set, each with its own reporting When a system message is generated, its level is compared to the stored
and halting thresholds, debugging switch, and warning stream thresholds, and a warning or error is generated as appropriate. Debug
(collectively a `ConditionSet`). Categories are hierarchical dotted-name messages are produced iff the stored debug switch is on, independently of
strings that look like attribute references: 'spam', 'spam.eggs', other thresholds. Message output is sent to the stored warning stream if
'neeeow.wum.ping'. The 'spam' category is the ancestor of not set to ''.
'spam.bacon.eggs'. Unset categories inherit stored conditions from their
closest ancestor category that has been set.
When a system message is generated, the stored conditions from its
category (or ancestor if unset) are retrieved. The system message level
is compared to the thresholds stored in the category, and a warning or
error is generated as appropriate. Debug messages are produced iff the
stored debug switch is on. Message output is sent to the stored warning
stream if not set to ''.
The default category is '' (empty string). By convention, Writers should
retrieve reporting conditions from the 'writer' category (which, unless
explicitly set, defaults to the conditions of the default category).
The Reporter class also employs a modified form of the "Observer" pattern The Reporter class also employs a modified form of the "Observer" pattern
[GoF95]_ to track system messages generated. The `attach_observer` method [GoF95]_ to track system messages generated. The `attach_observer` method
...@@ -67,9 +55,6 @@ class Reporter: ...@@ -67,9 +55,6 @@ class Reporter:
accepts system messages. The observer can be removed with accepts system messages. The observer can be removed with
`detach_observer`, and another added in its place. `detach_observer`, and another added in its place.
.. [#] The concept of "categories" was inspired by the log4j project:
http://jakarta.apache.org/log4j/.
.. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of
Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA,
1995. 1995.
...@@ -81,10 +66,7 @@ class Reporter: ...@@ -81,10 +66,7 @@ class Reporter:
def __init__(self, source, report_level, halt_level, stream=None, def __init__(self, source, report_level, halt_level, stream=None,
debug=0, encoding='ascii', error_handler='replace'): debug=0, encoding='ascii', error_handler='replace'):
""" """
Initialize the `ConditionSet` forthe `Reporter`'s default category.
:Parameters: :Parameters:
- `source`: The path to or description of the source data. - `source`: The path to or description of the source data.
- `report_level`: The level at or above which warning output will - `report_level`: The level at or above which warning output will
be sent to `stream`. be sent to `stream`.
...@@ -101,6 +83,23 @@ class Reporter: ...@@ -101,6 +83,23 @@ class Reporter:
self.source = source self.source = source
"""The path to or description of the source data.""" """The path to or description of the source data."""
self.encoding = encoding
"""The character encoding for the stderr output."""
self.error_handler = error_handler
"""The character encoding error handler."""
self.debug_flag = debug
"""Show debug (level=0) system messages?"""
self.report_level = report_level
"""The level at or above which warning output will be sent
to `self.stream`."""
self.halt_level = halt_level
"""The level at or above which `SystemMessage` exceptions
will be raised, halting execution."""
if stream is None: if stream is None:
stream = sys.stderr stream = sys.stderr
elif type(stream) in (StringType, UnicodeType): elif type(stream) in (StringType, UnicodeType):
...@@ -111,15 +110,8 @@ class Reporter: ...@@ -111,15 +110,8 @@ class Reporter:
elif type(stream) == UnicodeType: elif type(stream) == UnicodeType:
stream = open(stream.encode(), 'w') stream = open(stream.encode(), 'w')
self.encoding = encoding self.stream = stream
"""The character encoding for the stderr output.""" """Where warning output is sent."""
self.error_handler = error_handler
"""The character encoding error handler."""
self.categories = {'': ConditionSet(debug, report_level, halt_level,
stream)}
"""Mapping of category names to conditions. Default category is ''."""
self.observers = [] self.observers = []
"""List of bound methods or functions to call with each system_message """List of bound methods or functions to call with each system_message
...@@ -130,23 +122,15 @@ class Reporter: ...@@ -130,23 +122,15 @@ class Reporter:
def set_conditions(self, category, report_level, halt_level, def set_conditions(self, category, report_level, halt_level,
stream=None, debug=0): stream=None, debug=0):
warnings.warn('docutils.utils.Reporter.set_conditions deprecated; '
'set attributes via configuration settings or directly',
DeprecationWarning, stacklevel=2)
self.report_level = report_level
self.halt_level = halt_level
if stream is None: if stream is None:
stream = sys.stderr stream = sys.stderr
self.categories[category] = ConditionSet(debug, report_level, self.stream = stream
halt_level, stream) self.debug = debug
def unset_conditions(self, category):
if category and self.categories.has_key(category):
del self.categories[category]
__delitem__ = unset_conditions
def get_conditions(self, category):
while not self.categories.has_key(category):
category = category[:category.rfind('.') + 1][:-1]
return self.categories[category]
__getitem__ = get_conditions
def attach_observer(self, observer): def attach_observer(self, observer):
""" """
...@@ -169,9 +153,6 @@ class Reporter: ...@@ -169,9 +153,6 @@ class Reporter:
Raise an exception or generate a warning if appropriate. Raise an exception or generate a warning if appropriate.
""" """
attributes = kwargs.copy() attributes = kwargs.copy()
category = kwargs.get('category', '')
if kwargs.has_key('category'):
del attributes['category']
if kwargs.has_key('base_node'): if kwargs.has_key('base_node'):
source, line = get_source_line(kwargs['base_node']) source, line = get_source_line(kwargs['base_node'])
del attributes['base_node'] del attributes['base_node']
...@@ -183,16 +164,13 @@ class Reporter: ...@@ -183,16 +164,13 @@ class Reporter:
msg = nodes.system_message(message, level=level, msg = nodes.system_message(message, level=level,
type=self.levels[level], type=self.levels[level],
*children, **attributes) *children, **attributes)
debug, report_level, halt_level, stream = self[category].astuple() if self.stream and (level >= self.report_level
if (level >= report_level or debug and level == 0) and stream: or self.debug_flag and level == 0):
msgtext = msg.astext().encode(self.encoding, self.error_handler) msgtext = msg.astext().encode(self.encoding, self.error_handler)
if category: print >>self.stream, msgtext
print >>stream, msgtext, '[%s]' % category if level >= self.halt_level:
else:
print >>stream, msgtext
if level >= halt_level:
raise SystemMessage(msg, level) raise SystemMessage(msg, level)
if level > 0 or debug: if level > 0 or self.debug_flag:
self.notify_observers(msg) self.notify_observers(msg)
self.max_level = max(level, self.max_level) self.max_level = max(level, self.max_level)
return msg return msg
...@@ -203,7 +181,8 @@ class Reporter: ...@@ -203,7 +181,8 @@ class Reporter:
effect on the processing. Level-0 system messages are handled effect on the processing. Level-0 system messages are handled
separately from the others. separately from the others.
""" """
return self.system_message(0, *args, **kwargs) if self.debug_flag:
return self.system_message(0, *args, **kwargs)
def info(self, *args, **kwargs): def info(self, *args, **kwargs):
""" """
...@@ -235,25 +214,6 @@ class Reporter: ...@@ -235,25 +214,6 @@ class Reporter:
return self.system_message(4, *args, **kwargs) return self.system_message(4, *args, **kwargs)
class ConditionSet:
"""
A set of two thresholds (`report_level` & `halt_level`), a switch
(`debug`), and an I/O stream (`stream`), corresponding to one `Reporter`
category.
"""
def __init__(self, debug, report_level, halt_level, stream):
self.debug = debug
self.report_level = report_level
self.halt_level = halt_level
self.stream = stream
def astuple(self):
return (self.debug, self.report_level, self.halt_level,
self.stream)
class ExtensionOptionError(DataError): pass class ExtensionOptionError(DataError): pass
class BadOptionError(ExtensionOptionError): pass class BadOptionError(ExtensionOptionError): pass
class BadOptionDataError(ExtensionOptionError): pass class BadOptionDataError(ExtensionOptionError): pass
...@@ -346,7 +306,7 @@ def assemble_option_dict(option_list, options_spec): ...@@ -346,7 +306,7 @@ def assemble_option_dict(option_list, options_spec):
options[name] = convertor(value) options[name] = convertor(value)
except (ValueError, TypeError), detail: except (ValueError, TypeError), detail:
raise detail.__class__('(option: "%s"; value: %r)\n%s' raise detail.__class__('(option: "%s"; value: %r)\n%s'
% (name, value, detail)) % (name, value, ' '.join(detail.args)))
return options return options
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2321 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2004-06-20 14:28:08 +0200 (Sun, 20 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.7 $ # Revision: $Revision: 2223 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2004-06-05 21:32:15 +0200 (Sat, 05 Jun 2004) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
This diff is collapsed.
This diff is collapsed.
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.2.10.6 $ # Revision: $Revision: 3129 $
# Date: $Date: 2005/01/07 13:26:06 $ # Date: $Date: 2005-03-26 17:21:28 +0100 (Sat, 26 Mar 2005) $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -11,7 +11,6 @@ PEP HTML Writer. ...@@ -11,7 +11,6 @@ PEP HTML Writer.
__docformat__ = 'reStructuredText' __docformat__ = 'reStructuredText'
import random
import sys import sys
import docutils import docutils
from docutils import frontend, nodes, utils from docutils import frontend, nodes, utils
...@@ -22,8 +21,7 @@ class Writer(html4css1.Writer): ...@@ -22,8 +21,7 @@ class Writer(html4css1.Writer):
settings_spec = html4css1.Writer.settings_spec + ( settings_spec = html4css1.Writer.settings_spec + (
'PEP/HTML-Specific Options', 'PEP/HTML-Specific Options',
"""The HTML --footnote-references option's default is set to """ None,
'"brackets".',
(('Specify a template file. Default is "pep-html-template".', (('Specify a template file. Default is "pep-html-template".',
['--template'], ['--template'],
{'default': 'pep-html-template', 'metavar': '<file>'}), {'default': 'pep-html-template', 'metavar': '<file>'}),
...@@ -32,9 +30,11 @@ class Writer(html4css1.Writer): ...@@ -32,9 +30,11 @@ class Writer(html4css1.Writer):
{'default': '..', 'metavar': '<URL>'}), {'default': '..', 'metavar': '<URL>'}),
('Home URL prefix for PEPs. Default is "." (current directory).', ('Home URL prefix for PEPs. Default is "." (current directory).',
['--pep-home'], ['--pep-home'],
{'default': '.', 'metavar': '<URL>'}),)) {'default': '.', 'metavar': '<URL>'}),
# For testing.
settings_default_overrides = {'footnote_references': 'brackets'} (frontend.SUPPRESS_HELP,
['--no-random'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),))
relative_path_settings = (html4css1.Writer.relative_path_settings relative_path_settings = (html4css1.Writer.relative_path_settings
+ ('template',)) + ('template',))
...@@ -66,7 +66,11 @@ class Writer(html4css1.Writer): ...@@ -66,7 +66,11 @@ class Writer(html4css1.Writer):
header = self.document[index] header = self.document[index]
pepnum = header[0][1].astext() pepnum = header[0][1].astext()
subs['pep'] = pepnum subs['pep'] = pepnum
subs['banner'] = random.randrange(64) if settings.no_random:
subs['banner'] = 0
else:
import random
subs['banner'] = random.randrange(64)
try: try:
subs['pepnum'] = '%04i' % int(pepnum) subs['pepnum'] = '%04i' % int(pepnum)
except ValueError: except ValueError:
...@@ -82,5 +86,5 @@ class HTMLTranslator(html4css1.HTMLTranslator): ...@@ -82,5 +86,5 @@ class HTMLTranslator(html4css1.HTMLTranslator):
def depart_field_list(self, node): def depart_field_list(self, node):
html4css1.HTMLTranslator.depart_field_list(self, node) html4css1.HTMLTranslator.depart_field_list(self, node)
if node.get('class') == 'rfc2822': if 'rfc2822' in node['classes']:
self.body.append('<hr />\n') self.body.append('<hr />\n')
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment