Commit 7e454840 authored by Christian Heimes's avatar Christian Heimes

Updated docutils to 0.3.4 (merge from tiran-restfixing-branch)

parent 7dd7aa5c
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:37 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -51,12 +51,14 @@ Subpackages: ...@@ -51,12 +51,14 @@ Subpackages:
__docformat__ = 'reStructuredText' __docformat__ = 'reStructuredText'
__version__ = '0.3.1' __version__ = '0.3.4'
"""``major.minor.micro`` version number. The micro number is bumped any time """``major.minor.micro`` version number. The micro number is bumped
there's a change in the API incompatible with one of the front ends or any time there's a change in the API incompatible with one of the
significant new functionality. The minor number is bumped whenever there is a front ends or significant new functionality, and at any alpha or beta
release. The minor number is bumped whenever there is a stable
project release. The major number will be bumped when the project is project release. The major number will be bumped when the project is
feature-complete, and perhaps if there is a major change in the design.""" feature-complete, and perhaps if there is a major change in the
design."""
class ApplicationError(StandardError): pass class ApplicationError(StandardError): pass
...@@ -122,6 +124,22 @@ class TransformSpec: ...@@ -122,6 +124,22 @@ class TransformSpec:
default_transforms = () default_transforms = ()
"""Transforms required by this class. Override in subclasses.""" """Transforms required by this class. Override in subclasses."""
unknown_reference_resolvers = ()
"""List of functions to try to resolve unknown references. Called when
FinalCheckVisitor is unable to find a correct target. The list should
contain functions which will try to resolve unknown references, with the
following signature::
def reference_resolver(node):
'''Returns boolean: true if resolved, false if not.'''
Each function must have a "priority" attribute which will affect the order
the unknown_reference_resolvers are run::
reference_resolver.priority = 100
Override in subclasses."""
class Component(SettingsSpec, TransformSpec): class Component(SettingsSpec, TransformSpec):
...@@ -129,11 +147,12 @@ class Component(SettingsSpec, TransformSpec): ...@@ -129,11 +147,12 @@ class Component(SettingsSpec, TransformSpec):
"""Base class for Docutils components.""" """Base class for Docutils components."""
component_type = None component_type = None
"""Override in subclasses.""" """Name of the component type ('reader', 'parser', 'writer'). Override in
subclasses."""
supported = () supported = ()
"""Names for this component. Override in subclasses.""" """Names for this component. Override in subclasses."""
def supports(self, format): def supports(self, format):
""" """
Is `format` supported by this component? Is `format` supported by this component?
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -180,6 +180,7 @@ class Publisher: ...@@ -180,6 +180,7 @@ class Publisher:
self.settings) self.settings)
self.apply_transforms(document) self.apply_transforms(document)
output = self.writer.write(document, self.destination) output = self.writer.write(document, self.destination)
self.writer.assemble_parts()
except utils.SystemMessage, error: except utils.SystemMessage, error:
if self.settings.traceback: if self.settings.traceback:
raise raise
...@@ -376,3 +377,63 @@ def publish_string(source, source_path=None, destination_path=None, ...@@ -376,3 +377,63 @@ def publish_string(source, source_path=None, destination_path=None,
pub.set_source(source, source_path) pub.set_source(source, source_path)
pub.set_destination(destination_path=destination_path) pub.set_destination(destination_path=destination_path)
return pub.publish(enable_exit=enable_exit) return pub.publish(enable_exit=enable_exit)
def publish_parts(source, source_path=None, destination_path=None,
reader=None, reader_name='standalone',
parser=None, parser_name='restructuredtext',
writer=None, writer_name='pseudoxml',
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit=None):
"""
Set up & run a `Publisher`, and return a dictionary of document parts.
Dictionary keys are the names of parts, and values are Unicode strings;
encoding is up to the client. For programmatic use with string I/O.
For encoded string input, be sure to set the "input_encoding" setting to
the desired encoding. Set it to "unicode" for unencoded Unicode string
input. Here's how::
publish_string(..., settings_overrides={'input_encoding': 'unicode'})
Parameters:
- `source`: An input string; required. This can be an encoded 8-bit
string (set the "input_encoding" setting to the correct encoding) or a
Unicode string (set the "input_encoding" setting to "unicode").
- `source_path`: Path to the file or object that produced `source`;
optional. Only used for diagnostic output.
- `destination_path`: Path to the file or object which will receive the
output; optional. Used for determining relative paths (stylesheets,
source links, etc.).
- `reader`: A `docutils.readers.Reader` object.
- `reader_name`: Name or alias of the Reader class to be instantiated if
no `reader` supplied.
- `parser`: A `docutils.parsers.Parser` object.
- `parser_name`: Name or alias of the Parser class to be instantiated if
no `parser` supplied.
- `writer`: A `docutils.writers.Writer` object.
- `writer_name`: Name or alias of the Writer class to be instantiated if
no `writer` supplied.
- `settings`: Runtime settings object.
- `settings_spec`: Extra settings specification; a `docutils.SettingsSpec`
subclass. Used only if no `settings` specified.
- `settings_overrides`: A dictionary containing program-specific overrides
of component settings.
- `config_section`: Name of configuration file section for application.
Used only if no `settings` or `settings_spec` specified.
- `enable_exit`: Boolean; enable exit status at end of processing?
"""
pub = Publisher(reader, parser, writer, settings=settings,
source_class=io.StringInput,
destination_class=io.NullOutput)
pub.set_components(reader_name, parser_name, writer_name)
if settings is None:
settings = pub.get_settings(settings_spec=settings_spec,
config_section=config_section)
if settings_overrides:
settings._update(settings_overrides, 'loose')
pub.set_source(source, source_path)
pub.set_destination(destination_path=destination_path)
pub.publish(enable_exit=enable_exit)
return pub.writer.parts
# Authors: David Goodger
# Contact: goodger@python.org
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain.
"""
This module contains practical examples of Docutils client code.
Importing this module is not recommended; its contents are subject to change
in future Docutils releases. Instead, it is recommended that you copy and
paste the parts you need into your own code, modifying as necessary.
"""
from docutils import core
def html_parts(input_string, source_path=None, destination_path=None,
input_encoding='unicode', doctitle=1, initial_header_level=1):
"""
Given an input string, returns a dictionary of HTML document parts.
Dictionary keys are the names of parts, and values are Unicode strings;
encoding is up to the client.
Parameters:
- `input_string`: A multi-line text string; required.
- `source_path`: Path to the source file or object. Optional, but useful
for diagnostic output (system messages).
- `destination_path`: Path to the file or object which will receive the
output; optional. Used for determining relative paths (stylesheets,
source links, etc.).
- `input_encoding`: The encoding of `input_string`. If it is an encoded
8-bit string, provide the correct encoding. If it is a Unicode string,
use "unicode", the default.
- `doctitle`: Disable the promotion of a lone top-level section title to
document title (and subsequent section title to document subtitle
promotion); enabled by default.
- `initial_header_level`: The initial level for header elements (e.g. 1
for "<h1>").
"""
overrides = {'input_encoding': input_encoding,
'doctitle_xform': doctitle,
'initial_header_level': initial_header_level}
parts = core.publish_parts(
source=input_string, source_path=source_path,
destination_path=destination_path,
writer_name='html', settings_overrides=overrides)
return parts
def html_fragment(input_string, source_path=None, destination_path=None,
input_encoding='unicode', output_encoding='unicode',
doctitle=1, initial_header_level=1):
"""
Given an input string, returns an HTML fragment as a string.
The return value is the contents of the <body> tag, less the title,
subtitle, and docinfo.
Parameters (see `html_parts()` for the remainder):
- `output_encoding`: The desired encoding of the output. If a Unicode
string is desired, use the default value of "unicode" .
"""
parts = html_parts(
input_string=input_string, source_path=source_path,
destination_path=destination_path,
input_encoding=input_encoding, doctitle=doctitle,
initial_header_level=initial_header_level)
fragment = parts['fragment']
if output_encoding != 'unicode':
fragment = fragment.encode(output_encoding)
return fragment
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.7 $ # Revision: $Revision: 1.2.10.4.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -126,8 +126,7 @@ def validate_boolean(setting, value, option_parser, ...@@ -126,8 +126,7 @@ def validate_boolean(setting, value, option_parser,
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:
int(value) return int(value)
return value
except ValueError: except ValueError:
try: try:
return option_parser.thresholds[value.lower()] return option_parser.thresholds[value.lower()]
...@@ -294,6 +293,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ...@@ -294,6 +293,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
('Disable backlinks from footnotes and citations.', ('Disable backlinks from footnotes and citations.',
['--no-footnote-backlinks'], ['--no-footnote-backlinks'],
{'dest': 'footnote_backlinks', 'action': 'store_false'}), {'dest': 'footnote_backlinks', 'action': 'store_false'}),
('Disable Docutils section numbering',
['--no-section-numbering'],
{'action': 'store_false', 'dest': 'sectnum_xform',
'default': 1, 'validator': validate_boolean}),
('Set verbosity threshold; report system messages at or higher than ' ('Set verbosity threshold; report system messages at or higher than '
'<level> (by name or number: "info" or "1", warning/2, error/3, ' '<level> (by name or number: "info" or "1", warning/2, error/3, '
'severe/4; also, "none" or "5"). Default is 2 (warning).', 'severe/4; also, "none" or "5"). Default is 2 (warning).',
...@@ -346,7 +349,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ...@@ -346,7 +349,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
{'metavar': '<name[:handler]>', 'default': 'utf-8', {'metavar': '<name[:handler]>', 'default': 'utf-8',
'validator': validate_encoding_and_error_handler}), 'validator': validate_encoding_and_error_handler}),
(SUPPRESS_HELP, # usually handled by --output-encoding (SUPPRESS_HELP, # usually handled by --output-encoding
['--output_encoding_error_handler'], ['--output-encoding-error-handler'],
{'default': 'strict', 'validator': validate_encoding_error_handler}), {'default': 'strict', 'validator': validate_encoding_error_handler}),
('Specify the text encoding for error output. Default is ASCII. ' ('Specify the text encoding for error output. Default is ASCII. '
'Optionally also specify the encoding error handler for unencodable ' 'Optionally also specify the encoding error handler for unencodable '
...@@ -357,7 +360,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ...@@ -357,7 +360,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
{'metavar': '<name[:handler]>', 'default': 'ascii', {'metavar': '<name[:handler]>', 'default': 'ascii',
'validator': validate_encoding_and_error_handler}), 'validator': validate_encoding_and_error_handler}),
(SUPPRESS_HELP, # usually handled by --error-encoding (SUPPRESS_HELP, # usually handled by --error-encoding
['--error_encoding_error_handler'], ['--error-encoding-error-handler'],
{'default': default_error_encoding_error_handler, {'default': default_error_encoding_error_handler,
'validator': validate_encoding_error_handler}), 'validator': validate_encoding_error_handler}),
('Specify the language of input text (ISO 639 2-letter identifier).' ('Specify the language of input text (ISO 639 2-letter identifier).'
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -12,7 +12,10 @@ will exist for a variety of input/output mechanisms. ...@@ -12,7 +12,10 @@ will exist for a variety of input/output mechanisms.
__docformat__ = 'reStructuredText' __docformat__ = 'reStructuredText'
import sys import sys
import locale try:
import locale
except:
pass
from types import UnicodeType from types import UnicodeType
from docutils import TransformSpec from docutils import TransformSpec
...@@ -156,7 +159,7 @@ class FileInput(Input): ...@@ -156,7 +159,7 @@ class FileInput(Input):
print >>sys.stderr, '%s: %s' % (error.__class__.__name__, print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error) error)
print >>sys.stderr, ( print >>sys.stderr, (
'Unable to open source file for reading (%s). Exiting.' 'Unable to open source file for reading (%r). Exiting.'
% source_path) % source_path)
sys.exit(1) sys.exit(1)
else: else:
...@@ -224,7 +227,7 @@ class FileOutput(Output): ...@@ -224,7 +227,7 @@ class FileOutput(Output):
print >>sys.stderr, '%s: %s' % (error.__class__.__name__, print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error) error)
print >>sys.stderr, ('Unable to open destination file for writing ' print >>sys.stderr, ('Unable to open destination file for writing '
'(%s). Exiting.' % source_path) '(%r). Exiting.' % self.destination_path)
sys.exit(1) sys.exit(1)
self.opened = 1 self.opened = 1
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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
# Contact: mb@dat.cz
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:42 $
# Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please
# read <http://docutils.sf.net/spec/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
"""
Czech-language mappings for language-dependent features of Docutils.
"""
__docformat__ = 'reStructuredText'
labels = {
# fixed: language-dependent
'author': u'Autor',
'authors': u'Auto\u0159i',
'organization': u'Organizace',
'address': u'Adresa',
'contact': u'Kontakt',
'version': u'Verze',
'revision': u'Revize',
'status': u'Stav',
'date': u'Datum',
'copyright': u'Copyright',
'dedication': u'V\u011Bnov\u00E1n\u00ED',
'abstract': u'Abstrakt',
'attention': u'Pozor!',
'caution': u'Opatrn\u011B!',
'danger': u'!NEBEZPE\u010C\u00CD!',
'error': u'Chyba',
'hint': u'Rada',
'important': u'D\u016Fle\u017Eit\u00E9',
'note': u'Pozn\u00E1mka',
'tip': u'Tip',
'warning': u'Varov\u00E1n\u00ED',
'contents': u'Obsah'}
"""Mapping of node class name to label text."""
bibliographic_fields = {
# language-dependent: fixed
u'autor': 'author',
u'auto\u0159i': 'authors',
u'organizace': 'organization',
u'adresa': 'address',
u'kontakt': 'contact',
u'verze': 'version',
u'revize': 'revision',
u'stav': 'status',
u'datum': 'date',
u'copyright': 'copyright',
u'v\u011Bnov\u00E1n\u00ED': 'dedication',
u'abstrakt': 'abstract'}
"""Czech (lowcased) to canonical name mapping for bibliographic fields."""
author_separators = [';', ',']
"""List of separator strings for the 'Authors' bibliographic field. Tried in
order."""
# Authors: David Goodger; Gunnar Schwant # Authors: David Goodger; Gunnar Schwant
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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 $ # Revision: $Revision: 1.1.2.1.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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 -*-
# Author: David Goodger
# Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:42 $
# Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please
# read <http://docutils.sf.net/spec/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
"""
Brazilian Portuguese-language mappings for language-dependent features of Docutils.
"""
__docformat__ = 'reStructuredText'
labels = {
# fixed: language-dependent
'author': u'Autor',
'authors': u'Autores',
'organization': unicode('Organizao', 'latin1'),
'address': unicode('Endereo', 'latin1'),
'contact': u'Contato',
'version': unicode('Verso', 'latin1'),
'revision': unicode('Reviso', 'latin1'),
'status': u'Estado',
'date': u'Data',
'copyright': u'Copyright',
'dedication': unicode('Dedicatria', 'latin1'),
'abstract': u'Resumo',
'attention': unicode('Atteno!', 'latin1'),
'caution': u'Cuidado!',
'danger': u'PERIGO!',
'error': u'Erro',
'hint': unicode('Sugesto', 'latin1'),
'important': u'Importante',
'note': u'Nota',
'tip': u'Dica',
'warning': u'Aviso',
'contents': unicode('Sumrio', 'latin1')}
"""Mapping of node class name to label text."""
bibliographic_fields = {
# language-dependent: fixed
u'autor': 'author',
u'autores': 'authors',
unicode('organizao', 'latin1'): 'organization',
unicode('endereo', 'latin1'): 'address',
u'contato': 'contact',
unicode('verso', 'latin1'): 'version',
unicode('reviso', 'latin1'): 'revision',
u'estado': 'status',
u'data': 'date',
u'copyright': 'copyright',
unicode('dedicatria', 'latin1'): 'dedication',
u'resumo': 'abstract'}
"""English (lowcased) to canonical name mapping for bibliographic fields."""
author_separators = [';', ',']
"""List of separator strings for the 'Authors' bibliographic field. Tried in
order."""
# Author: Roman Suzi # Author: Roman Suzi
# Contact: rnd@onego.ru # Contact: rnd@onego.ru
# Revision: $Revision: 1.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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: Miroslav Vasko # :Author: Miroslav Vasko
# :Contact: zemiak@zoznam.sk # :Contact: zemiak@zoznam.sk
# :Revision: $Revision: 1.5 $ # :Revision: $Revision: 1.2.10.3.8.1 $
# :Date: $Date: 2003/11/30 15:06:05 $ # :Date: $Date: 2004/05/12 19:57:42 $
# :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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:05 $ # Date: $Date: 2004/05/12 19:57:42 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -517,6 +517,9 @@ class TextElement(Element): ...@@ -517,6 +517,9 @@ class TextElement(Element):
its immediate parent is a `TextElement` instance (including subclasses). its immediate parent is a `TextElement` instance (including subclasses).
This is handy for nodes like `image` that can appear both inline and as This is handy for nodes like `image` that can appear both inline and as
standalone body elements. standalone body elements.
If passing children to `__init__()`, make sure to set `text` to
``''`` or some other suitable value.
""" """
child_text_separator = '' child_text_separator = ''
...@@ -599,6 +602,9 @@ class Targetable(Resolvable): ...@@ -599,6 +602,9 @@ class Targetable(Resolvable):
referenced = 0 referenced = 0
indirect_reference_name = None
"""Holds the whitespace_normalized_name (contains mixed case) of a target"""
class Labeled: class Labeled:
"""Contains a `label` as its first element.""" """Contains a `label` as its first element."""
...@@ -820,6 +826,7 @@ class document(Root, Structural, Element): ...@@ -820,6 +826,7 @@ class document(Root, Structural, Element):
def has_name(self, name): def has_name(self, name):
return self.nameids.has_key(name) return self.nameids.has_key(name)
# "note" here is an imperative verb: "take note of".
def note_implicit_target(self, target, msgnode=None): def note_implicit_target(self, target, msgnode=None):
id = self.set_id(target, msgnode) id = self.set_id(target, msgnode)
self.set_name_id_map(target, id, msgnode, explicit=None) self.set_name_id_map(target, id, msgnode, explicit=None)
...@@ -939,6 +946,7 @@ class rubric(Titular, TextElement): pass ...@@ -939,6 +946,7 @@ class rubric(Titular, TextElement): pass
# ======================== # ========================
class docinfo(Bibliographic, Element): pass class docinfo(Bibliographic, Element): pass
class info(Bibliographic, Element): pass
class author(Bibliographic, TextElement): pass class author(Bibliographic, TextElement): pass
class authors(Bibliographic, Element): pass class authors(Bibliographic, Element): pass
class organization(Bibliographic, TextElement): pass class organization(Bibliographic, TextElement): pass
...@@ -1182,7 +1190,7 @@ class raw(Special, Inline, PreBibliographic, FixedTextElement): ...@@ -1182,7 +1190,7 @@ class raw(Special, Inline, PreBibliographic, FixedTextElement):
class emphasis(Inline, TextElement): pass class emphasis(Inline, TextElement): pass
class strong(Inline, TextElement): pass class strong(Inline, TextElement): pass
class literal(Inline, TextElement): pass class literal(Inline, TextElement): pass
class reference(Inline, Referential, TextElement): pass class reference(General, Inline, Referential, TextElement): pass
class footnote_reference(Inline, Referential, TextElement): pass class footnote_reference(Inline, Referential, TextElement): pass
class citation_reference(Inline, Referential, TextElement): pass class citation_reference(Inline, Referential, TextElement): pass
class substitution_reference(Inline, TextElement): pass class substitution_reference(Inline, TextElement): pass
...@@ -1222,7 +1230,7 @@ node_class_names = """ ...@@ -1222,7 +1230,7 @@ node_class_names = """
footnote footnote_reference footnote footnote_reference
generated generated
header hint header hint
image important inline image important info inline
label legend line_block list_item literal literal_block label legend line_block list_item literal literal_block
note note
option option_argument option_group option_list option_list_item option option_argument option_group option_list option_list_item
...@@ -1273,8 +1281,8 @@ class NodeVisitor: ...@@ -1273,8 +1281,8 @@ class NodeVisitor:
Raise an exception unless overridden. Raise an exception unless overridden.
""" """
raise NotImplementedError('visiting unknown node type: %s' raise NotImplementedError('%s visiting unknown node type: %s'
% node.__class__.__name__) % (self.__class__, node.__class__.__name__))
def unknown_departure(self, node): def unknown_departure(self, node):
""" """
...@@ -1282,8 +1290,8 @@ class NodeVisitor: ...@@ -1282,8 +1290,8 @@ class NodeVisitor:
Raise exception unless overridden. Raise exception unless overridden.
""" """
raise NotImplementedError('departing unknown node type: %s' raise NotImplementedError('%s departing unknown node type: %s'
% node.__class__.__name__) % (self.__class__, node.__class__.__name__))
class SparseNodeVisitor(NodeVisitor): class SparseNodeVisitor(NodeVisitor):
...@@ -1295,16 +1303,6 @@ class SparseNodeVisitor(NodeVisitor): ...@@ -1295,16 +1303,6 @@ class SparseNodeVisitor(NodeVisitor):
subclasses), subclass `NodeVisitor` instead. subclasses), subclass `NodeVisitor` instead.
""" """
def _nop(self, node):
pass
# Save typing with dynamic assignments:
for _name in node_class_names:
setattr(SparseNodeVisitor, "visit_" + _name, _nop)
setattr(SparseNodeVisitor, "depart_" + _name, _nop)
del _name, _nop
class GenericNodeVisitor(NodeVisitor): class GenericNodeVisitor(NodeVisitor):
""" """
...@@ -1337,12 +1335,18 @@ def _call_default_visit(self, node): ...@@ -1337,12 +1335,18 @@ def _call_default_visit(self, node):
def _call_default_departure(self, node): def _call_default_departure(self, node):
self.default_departure(node) self.default_departure(node)
# Save typing with dynamic assignments: def _nop(self, node):
for _name in node_class_names: pass
setattr(GenericNodeVisitor, "visit_" + _name, _call_default_visit)
setattr(GenericNodeVisitor, "depart_" + _name, _call_default_departure) def _add_node_class_names(names):
del _name, _call_default_visit, _call_default_departure """Save typing with dynamic assignments:"""
for _name in names:
setattr(GenericNodeVisitor, "visit_" + _name, _call_default_visit)
setattr(GenericNodeVisitor, "depart_" + _name, _call_default_departure)
setattr(SparseNodeVisitor, 'visit_' + _name, _nop)
setattr(SparseNodeVisitor, 'depart' + _name, _nop)
_add_node_class_names(node_class_names)
class TreeCopyVisitor(GenericNodeVisitor): class TreeCopyVisitor(GenericNodeVisitor):
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:45 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:07:46 $ # Date: $Date: 2004/05/12 19:57:46 $
# 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.6 $ # Revision: $Revision: 1.2.10.4.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -102,6 +102,7 @@ _directive_registry = { ...@@ -102,6 +102,7 @@ _directive_registry = {
'epigraph': ('body', 'epigraph'), 'epigraph': ('body', 'epigraph'),
'highlights': ('body', 'highlights'), 'highlights': ('body', 'highlights'),
'pull-quote': ('body', 'pull_quote'), 'pull-quote': ('body', 'pull_quote'),
'table': ('body', 'table'),
#'questions': ('body', 'question_list'), #'questions': ('body', 'question_list'),
'image': ('images', 'image'), 'image': ('images', 'image'),
'figure': ('images', 'figure'), 'figure': ('images', 'figure'),
...@@ -117,6 +118,7 @@ _directive_registry = { ...@@ -117,6 +118,7 @@ _directive_registry = {
'replace': ('misc', 'replace'), 'replace': ('misc', 'replace'),
'unicode': ('misc', 'unicode_directive'), 'unicode': ('misc', 'unicode_directive'),
'class': ('misc', 'class_directive'), 'class': ('misc', 'class_directive'),
'role': ('misc', 'role'),
'restructuredtext-test-directive': ('misc', 'directive_test_function'),} 'restructuredtext-test-directive': ('misc', 'directive_test_function'),}
"""Mapping of directive name to (module name, function name). The directive """Mapping of directive name to (module name, function name). The directive
name is canonical & must be lowercase. Language-dependent names are defined name is canonical & must be lowercase. Language-dependent names are defined
...@@ -165,23 +167,37 @@ def directive(directive_name, language_module, document): ...@@ -165,23 +167,37 @@ def directive(directive_name, language_module, document):
try: try:
modulename, functionname = _directive_registry[canonicalname] modulename, functionname = _directive_registry[canonicalname]
except KeyError: except KeyError:
messages.append(document.reporter.error(
'Directive "%s" not registered (canonical name "%s").'
% (directive_name, canonicalname), line=document.current_line))
return None, messages return None, messages
if _modules.has_key(modulename): if _modules.has_key(modulename):
module = _modules[modulename] module = _modules[modulename]
else: else:
try: try:
module = __import__(modulename, globals(), locals()) module = __import__(modulename, globals(), locals())
except ImportError: except ImportError, detail:
messages.append(document.reporter.error(
'Error importing directive module "%s" (directive "%s"):\n%s'
% (modulename, directive_name, detail),
line=document.current_line))
return None, messages return None, messages
try: try:
function = getattr(module, functionname) function = getattr(module, functionname)
_directives[normname] = function _directives[normname] = function
except AttributeError: except AttributeError:
messages.append(document.reporter.error(
'No function "%s" in module "%s" (directive "%s").'
% (functionname, modulename, directive_name),
line=document.current_line))
return None, messages return None, messages
return function, messages return function, messages
def register_directive(name, directive): def register_directive(name, directive):
"""Register a nonstandard application-defined directive function.""" """
Register a nonstandard application-defined directive function.
Language lookups are not needed for such functions.
"""
_directives[name] = directive _directives[name] = directive
def flag(argument): def flag(argument):
...@@ -257,7 +273,10 @@ def class_option(argument): ...@@ -257,7 +273,10 @@ def class_option(argument):
""" """
if argument is None: if argument is None:
raise ValueError('argument required but none supplied') raise ValueError('argument required but none supplied')
return nodes.make_id(argument) class_name = nodes.make_id(argument)
if not class_name:
raise ValueError('cannot make "%s" into a class name' % argument)
return class_name
def format_values(values): def format_values(values):
return '%s, or "%s"' % (', '.join(['"%s"' % s for s in values[:-1]]), return '%s, or "%s"' % (', '.join(['"%s"' % s for s in values[:-1]]),
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -34,6 +34,7 @@ def topic(name, arguments, options, content, lineno, ...@@ -34,6 +34,7 @@ def topic(name, arguments, options, content, lineno,
title_text = arguments[0] title_text = arguments[0]
textnodes, messages = state.inline_text(title_text, lineno) textnodes, messages = state.inline_text(title_text, lineno)
titles = [nodes.title(title_text, '', *textnodes)] titles = [nodes.title(title_text, '', *textnodes)]
# sidebar uses this code
if options.has_key('subtitle'): if options.has_key('subtitle'):
textnodes, more_messages = state.inline_text(options['subtitle'], textnodes, more_messages = state.inline_text(options['subtitle'],
lineno) lineno)
...@@ -120,3 +121,38 @@ def pull_quote(name, arguments, options, content, lineno, ...@@ -120,3 +121,38 @@ def pull_quote(name, arguments, options, content, lineno,
return [block_quote] + messages return [block_quote] + messages
pull_quote.content = 1 pull_quote.content = 1
def table(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
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)
return [warning]
if arguments:
title_text = arguments[0]
text_nodes, messages = state.inline_text(title_text, lineno)
title = nodes.title(title_text, '', *text_nodes)
else:
title = None
node = nodes.Element() # anonymous container for parsing
text = '\n'.join(content)
state.nested_parse(content, content_offset, node)
if len(node) != 1 or not isinstance(node[0], nodes.table):
error = state_machine.reporter.error(
'Error parsing content block for the "%s" directive: '
'exactly one table expected.'
% name, nodes.literal_block(block_text, block_text),
line=lineno)
return [error]
table_node = node[0]
if options.has_key('class'):
table_node.set_class(options['class'])
if title:
table_node.insert(0, title)
return [table_node]
table.arguments = (0, 1, 1)
table.options = {'class': directives.class_option}
table.content = 1
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -13,7 +13,8 @@ __docformat__ = 'reStructuredText' ...@@ -13,7 +13,8 @@ __docformat__ = 'reStructuredText'
import sys import sys
from docutils import nodes, utils from docutils import nodes, utils
from docutils.parsers.rst import directives from docutils.parsers.rst import directives, states
from docutils.nodes import whitespace_normalize_name
try: try:
import Image # PIL import Image # PIL
...@@ -34,8 +35,23 @@ def image(name, arguments, options, content, lineno, ...@@ -34,8 +35,23 @@ def image(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]
options['uri'] = reference options['uri'] = reference
image_node = nodes.image(block_text, **options) if options.has_key('target'):
return [image_node] block = states.escape2null(options['target']).splitlines()
block = [line for line in block]
target_type, data = state.parse_target(block, block_text, lineno)
if target_type == 'refuri':
node_list = nodes.reference(refuri=data)
elif target_type == 'refname':
node_list = nodes.reference(
refname=data, name=whitespace_normalize_name(options['target']))
state.document.note_refname(node_list)
else: # malformed target
node_list = [data] # data is a system message
del options['target']
else:
node_list = []
node_list.append(nodes.image(block_text, **options))
return node_list
image.arguments = (1, 0, 1) image.arguments = (1, 0, 1)
image.options = {'alt': directives.unchanged, image.options = {'alt': directives.unchanged,
...@@ -43,6 +59,7 @@ image.options = {'alt': directives.unchanged, ...@@ -43,6 +59,7 @@ image.options = {'alt': directives.unchanged,
'width': directives.nonnegative_int, 'width': directives.nonnegative_int,
'scale': directives.nonnegative_int, 'scale': directives.nonnegative_int,
'align': align, 'align': align,
'target': directives.unchanged_required,
'class': directives.class_option} 'class': directives.class_option}
def figure(name, arguments, options, content, lineno, def figure(name, arguments, options, content, lineno,
......
# Authors: David Goodger, Dethe Elza # Authors: David Goodger, Dethe Elza
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
"""Miscellaneous directives.""" """Miscellaneous directives."""
...@@ -11,11 +11,15 @@ __docformat__ = 'reStructuredText' ...@@ -11,11 +11,15 @@ __docformat__ = 'reStructuredText'
import sys import sys
import os.path import os.path
import re import re
from urllib2 import urlopen, URLError
from docutils import io, nodes, statemachine, utils from docutils import io, nodes, statemachine, utils
from docutils.parsers.rst import directives, states from docutils.parsers.rst import directives, roles, states
from docutils.transforms import misc from docutils.transforms import misc
try:
import urllib2
except ImportError:
urllib2 = None
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):
...@@ -97,9 +101,16 @@ def raw(name, arguments, options, content, lineno, ...@@ -97,9 +101,16 @@ def raw(name, arguments, options, content, lineno,
raw_file.close() raw_file.close()
attributes['source'] = path attributes['source'] = path
elif options.has_key('url'): elif options.has_key('url'):
if not urllib2:
severe = state_machine.reporter.severe(
'Problems with the "%s" directive and its "url" option: '
'unable to access the required functionality (from the '
'"urllib2" module).' % name,
nodes.literal_block(block_text, block_text), line=lineno)
return [severe]
try: try:
raw_file = urlopen(options['url']) raw_file = urllib2.urlopen(options['url'])
except (URLError, IOError, OSError), error: except (urllib2.URLError, IOError, OSError), error:
severe = state_machine.reporter.severe( severe = state_machine.reporter.severe(
'Problems with "%s" directive URL "%s":\n%s.' 'Problems with "%s" directive URL "%s":\n%s.'
% (name, options['url'], error), % (name, options['url'], error),
...@@ -209,7 +220,7 @@ def class_directive(name, arguments, options, content, lineno, ...@@ -209,7 +220,7 @@ def class_directive(name, arguments, options, content, lineno,
return [pending] return [pending]
else: else:
error = state_machine.reporter.error( error = state_machine.reporter.error(
'Invalid class attribute value for "%s" directive: %s' 'Invalid class attribute value for "%s" directive: "%s".'
% (name, arguments[0]), % (name, arguments[0]),
nodes.literal_block(block_text, block_text), line=lineno) nodes.literal_block(block_text, block_text), line=lineno)
return [error] return [error]
...@@ -217,8 +228,67 @@ def class_directive(name, arguments, options, content, lineno, ...@@ -217,8 +228,67 @@ def class_directive(name, arguments, options, content, lineno,
class_directive.arguments = (1, 0, 0) class_directive.arguments = (1, 0, 0)
class_directive.content = 1 class_directive.content = 1
role_arg_pat = re.compile(r'(%s)\s*(\(\s*(%s)\s*\)\s*)?$'
% ((states.Inliner.simplename,) * 2))
def role(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
"""Dynamically create and register a custom interpreted text role."""
if content_offset > lineno or not content:
error = state_machine.reporter.error(
'"%s" directive requires arguments on the first line.'
% name, nodes.literal_block(block_text, block_text), line=lineno)
return [error]
args = content[0]
match = role_arg_pat.match(args)
if not match:
error = state_machine.reporter.error(
'"%s" directive arguments not valid role names: "%s".'
% (name, args), nodes.literal_block(block_text, block_text),
line=lineno)
return [error]
new_role_name = match.group(1)
base_role_name = match.group(3)
messages = []
if base_role_name:
base_role, messages = roles.role(
base_role_name, state_machine.language, lineno, state.reporter)
if base_role is None:
error = state.reporter.error(
'Unknown interpreted text role "%s".' % base_role_name,
nodes.literal_block(block_text, block_text), line=lineno)
return messages + [error]
else:
base_role = roles.generic_custom_role
assert not hasattr(base_role, 'arguments'), (
'Supplemental directive arguments for "%s" directive not supported'
'(specified by "%r" role).' % (name, base_role))
try:
(arguments, options, content, content_offset) = (
state.parse_directive_block(content[1:], content_offset, base_role,
option_presets={}))
except states.MarkupError, detail:
error = state_machine.reporter.error(
'Error in "%s" directive:\n%s.' % (name, detail),
nodes.literal_block(block_text, block_text), line=lineno)
return messages + [error]
if not options.has_key('class'):
try:
options['class'] = directives.class_option(new_role_name)
except ValueError, detail:
error = state_machine.reporter.error(
'Invalid argument for "%s" directive:\n%s.'
% (name, detail),
nodes.literal_block(block_text, block_text), line=lineno)
return messages + [error]
role = roles.CustomRole(new_role_name, base_role, options, content)
roles.register_local_role(new_role_name, role)
return messages
role.content = 1
def directive_test_function(name, arguments, options, content, lineno, def directive_test_function(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
"""This directive is useful only for testing purposes."""
if content: if content:
text = '\n'.join(content) text = '\n'.join(content)
info = state_machine.reporter.info( info = state_machine.reporter.info(
......
# Author: David Goodger, Dmitry Jemerov # Author: David Goodger, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -10,7 +10,7 @@ Directives for document parts. ...@@ -10,7 +10,7 @@ Directives for document parts.
__docformat__ = 'reStructuredText' __docformat__ = 'reStructuredText'
from docutils import nodes from docutils import nodes, languages
from docutils.transforms import parts from docutils.transforms import parts
from docutils.parsers.rst import directives from docutils.parsers.rst import directives
...@@ -27,17 +27,42 @@ def backlinks(arg): ...@@ -27,17 +27,42 @@ 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."""
document = state_machine.document
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)
title = nodes.title(title_text, '', *text_nodes) title = nodes.title(title_text, '', *text_nodes)
else: else:
messages = [] messages = []
title = None if options.has_key('local'):
pending = nodes.pending(parts.Contents, {'title': title}, block_text) title = None
else:
title = nodes.title('', language.labels['contents'])
topic = nodes.topic(CLASS='contents')
cls = options.get('class')
if cls:
topic.set_class(cls)
if title:
name = title.astext()
topic += title
else:
name = language.labels['contents']
name = nodes.fully_normalize_name(name)
if not document.has_name(name):
topic['name'] = name
document.note_implicit_target(topic)
pending = nodes.pending(parts.Contents, rawsource=block_text)
pending.details.update(options) pending.details.update(options)
state_machine.document.note_pending(pending) document.note_pending(pending)
return [pending] + messages topic += pending
return [topic] + messages
contents.arguments = (0, 1, 1) contents.arguments = (0, 1, 1)
contents.options = {'depth': directives.nonnegative_int, contents.options = {'depth': directives.nonnegative_int,
......
# Author: David Goodger, Dmitry Jemerov # Author: David Goodger, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:06 $ # Date: $Date: 2004/05/12 19:57:48 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:50 $
# 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.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:50 $
# 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
...@@ -36,6 +36,7 @@ directives = { ...@@ -36,6 +36,7 @@ directives = {
'epigraaf': 'epigraph', 'epigraaf': 'epigraph',
'hoogtepunte': 'highlights', 'hoogtepunte': 'highlights',
'pull-quote (translation required)': 'pull-quote', 'pull-quote (translation required)': 'pull-quote',
'table (translation required)': 'table',
#'vrae': 'questions', #'vrae': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -48,6 +49,7 @@ directives = { ...@@ -48,6 +49,7 @@ directives = {
'vervang': 'replace', 'vervang': 'replace',
'unicode': 'unicode', # should this be translated? unikode 'unicode': 'unicode', # should this be translated? unikode
'klas': 'class', 'klas': 'class',
'role (translation required)': 'role',
'inhoud': 'contents', 'inhoud': 'contents',
'sectnum': 'sectnum', 'sectnum': 'sectnum',
'section-numbering': 'sectnum', 'section-numbering': 'sectnum',
......
# Author: Marek Blaha
# Contact: mb@dat.cz
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:50 $
# Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please
# read <http://docutils.sf.net/spec/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
"""
Czech-language mappings for language-dependent features of
reStructuredText.
"""
__docformat__ = 'reStructuredText'
directives = {
# language-dependent: fixed
u'pozor': 'attention',
u'caution': 'caution', # jak rozlisit caution a warning?
u'nebezpe\u010D\u00ED': 'danger',
u'chyba': 'error',
u'rada': 'hint',
u'd\u016Fle\u017Eit\u00E9': 'important',
u'pozn\u00E1mka': 'note',
u'tip': 'tip',
u'varov\u00E1n\u00ED': 'warning',
u'admonition': 'admonition',
u'sidebar': 'sidebar',
u't\u00E9ma': 'topic',
u'line-block': 'line-block',
u'parsed-literal': 'parsed-literal',
u'odd\u00EDl': 'rubric',
u'moto': 'epigraph',
u'highlights': 'highlights',
u'pull-quote': 'pull-quote',
u'table (translation required)': 'table',
#'questions': 'questions',
#'qa': 'questions',
#'faq': 'questions',
u'meta': 'meta',
#'imagemap': 'imagemap',
u'image': 'image', # obrazek
u'figure': 'figure', # a tady?
u'include': 'include',
u'raw': 'raw',
u'replace': 'replace',
u'unicode': 'unicode',
u't\u0159\u00EDda': 'class',
u'role (translation required)': 'role',
u'obsah': 'contents',
u'sectnum': 'sectnum',
u'section-numbering': 'sectnum',
#'footnotes': 'footnotes',
#'citations': 'citations',
u'target-notes': 'target-notes',
u'restructuredtext-test-directive': 'restructuredtext-test-directive'}
"""Czech name to registered (in directives/__init__.py) directive name
mapping."""
roles = {
# language-dependent: fixed
u'abbreviation': 'abbreviation',
u'ab': 'abbreviation',
u'acronym': 'acronym',
u'ac': 'acronym',
u'index': 'index',
u'i': 'index',
u'subscript': 'subscript',
u'sub': 'subscript',
u'superscript': 'superscript',
u'sup': 'superscript',
u'title-reference': 'title-reference',
u'title': 'title-reference',
u't': 'title-reference',
u'pep-reference': 'pep-reference',
u'pep': 'pep-reference',
u'rfc-reference': 'rfc-reference',
u'rfc': 'rfc-reference',
u'emphasis': 'emphasis',
u'strong': 'strong',
u'literal': 'literal',
u'named-reference': 'named-reference',
u'anonymous-reference': 'anonymous-reference',
u'footnote-reference': 'footnote-reference',
u'citation-reference': 'citation-reference',
u'substitution-reference': 'substitution-reference',
u'target': 'target',
u'uri-reference': 'uri-reference',
u'uri': 'uri-reference',
u'url': 'uri-reference',}
"""Mapping of Czech role names to canonical role names for interpreted text.
"""
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
# Author: Engelbert Gruber # Author: Engelbert Gruber
# Contact: grubert@users.sourceforge.net # Contact: grubert@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:50 $
# 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
...@@ -37,6 +37,7 @@ directives = { ...@@ -37,6 +37,7 @@ directives = {
'epigraph (translation required)': 'epigraph', 'epigraph (translation required)': 'epigraph',
'highlights (translation required)': 'highlights', 'highlights (translation required)': 'highlights',
'pull-quote (translation required)': 'pull-quote', # kasten too ? 'pull-quote (translation required)': 'pull-quote', # kasten too ?
'table (translation required)': 'table',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -49,7 +50,8 @@ directives = { ...@@ -49,7 +50,8 @@ directives = {
# einfügung would be the noun. # einfügung would be the noun.
'ersetzung': 'replace', # ersetzen, ersetze 'ersetzung': 'replace', # ersetzen, ersetze
'unicode': 'unicode', 'unicode': 'unicode',
'klasse': 'class', # offer class too ? 'klasse': 'class', # offer "class" too ?
'role (translation required)': 'role',
'inhalt': 'contents', 'inhalt': 'contents',
'sectnum': 'sectnum', 'sectnum': 'sectnum',
'section-numbering': 'sectnum', 'section-numbering': 'sectnum',
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:50 $
# 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
...@@ -37,6 +37,7 @@ directives = { ...@@ -37,6 +37,7 @@ directives = {
'epigraph': 'epigraph', 'epigraph': 'epigraph',
'highlights': 'highlights', 'highlights': 'highlights',
'pull-quote': 'pull-quote', 'pull-quote': 'pull-quote',
'table': 'table',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -49,6 +50,7 @@ directives = { ...@@ -49,6 +50,7 @@ directives = {
'replace': 'replace', 'replace': 'replace',
'unicode': 'unicode', 'unicode': 'unicode',
'class': 'class', 'class': 'class',
'role': 'role',
'contents': 'contents', 'contents': 'contents',
'sectnum': 'sectnum', 'sectnum': 'sectnum',
'section-numbering': 'sectnum', 'section-numbering': 'sectnum',
......
# Author: Marcelo Huerta San Martin # Author: Marcelo Huerta San Martin
# Contact: richieadler@users.sourceforge.net # Contact: richieadler@users.sourceforge.net
# Revision: $Revision: 1.1 $ # Revision: $Revision: 1.1.2.1.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:50 $
# 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
...@@ -40,6 +40,7 @@ directives = { ...@@ -40,6 +40,7 @@ directives = {
u'elstara\u0135oj': 'highlights', u'elstara\u0135oj': 'highlights',
u'ekstera-citajxo': 'pull-quote', u'ekstera-citajxo': 'pull-quote',
u'ekstera-cita\u0135o': 'pull-quote', u'ekstera-cita\u0135o': 'pull-quote',
u'tabelo': 'table',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -53,6 +54,7 @@ directives = { ...@@ -53,6 +54,7 @@ directives = {
u'anstata\u016di': 'replace', u'anstata\u016di': 'replace',
u'unicode': 'unicode', u'unicode': 'unicode',
u'klaso': 'class', u'klaso': 'class',
u'rolo': 'role',
u'enhavo': 'contents', u'enhavo': 'contents',
u'seknum': 'sectnum', u'seknum': 'sectnum',
u'sekcia-numerado': 'sectnum', u'sekcia-numerado': 'sectnum',
......
# -*- 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.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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'epigrafe': 'epigraph', u'epigrafe': 'epigraph',
u'destacado': 'highlights', u'destacado': 'highlights',
u'cita-destacada': 'pull-quote', u'cita-destacada': 'pull-quote',
u'tabla': 'table',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -54,6 +55,7 @@ directives = { ...@@ -54,6 +55,7 @@ directives = {
u'reemplazar': 'replace', u'reemplazar': 'replace',
u'unicode': 'unicode', u'unicode': 'unicode',
u'clase': 'class', u'clase': 'class',
u'rol': 'role',
u'contenido': 'contents', u'contenido': 'contents',
u'numseccion': 'sectnum', u'numseccion': 'sectnum',
u'numsecci\u00f3n': 'sectnum', u'numsecci\u00f3n': 'sectnum',
...@@ -74,8 +76,10 @@ roles = { ...@@ -74,8 +76,10 @@ roles = {
u'ac': 'acronym', u'ac': 'acronym',
u'indice': 'index', u'indice': 'index',
u'i': 'index', u'i': 'index',
u'subscript (translation required)': 'subscript', u'subindice': 'subscript',
u'superscript (translation required)': 'superscript', u'sub\u00edndice': 'subscript',
u'superindice': 'superscript',
u'super\u00edndice': 'superscript',
u'referencia-titulo': 'title-reference', u'referencia-titulo': 'title-reference',
u'titulo': 'title-reference', u'titulo': 'title-reference',
u't': 'title-reference', u't': 'title-reference',
......
# Authors: David Goodger; William Dode # Authors: David Goodger; William Dode
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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
...@@ -38,6 +38,7 @@ directives = { ...@@ -38,6 +38,7 @@ directives = {
u'\u00E9pigraphe': 'epigraph', u'\u00E9pigraphe': 'epigraph',
u'chapeau': 'highlights', u'chapeau': 'highlights',
u'accroche': 'pull-quote', u'accroche': 'pull-quote',
u'tableau': 'table',
#u'questions': 'questions', #u'questions': 'questions',
#u'qr': 'questions', #u'qr': 'questions',
#u'faq': 'questions', #u'faq': 'questions',
...@@ -51,6 +52,7 @@ directives = { ...@@ -51,6 +52,7 @@ directives = {
u'remplace': 'replace', u'remplace': 'replace',
u'unicode': 'unicode', u'unicode': 'unicode',
u'classe': 'class', u'classe': 'class',
u'role (translation required)': 'role',
u'sommaire': 'contents', u'sommaire': 'contents',
u'table-des-mati\u00E8res': 'contents', u'table-des-mati\u00E8res': 'contents',
u'sectnum': 'sectnum', u'sectnum': 'sectnum',
......
# Author: Nicola Larosa # Author: Nicola Larosa, Lele Gaifax
# Contact: docutils@tekNico.net # Contact: docutils@tekNico.net, lele@seldati.it
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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
# read <http://docutils.sf.net/spec/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
""" """
Italian-language mappings for language-dependent features of Italian-language mappings for language-dependent features of
reStructuredText. reStructuredText.
...@@ -27,15 +22,16 @@ directives = { ...@@ -27,15 +22,16 @@ directives = {
'nota': 'note', 'nota': 'note',
'consiglio': 'tip', 'consiglio': 'tip',
'avvertenza': 'warning', 'avvertenza': 'warning',
'admonition (translation required)': 'admonition', 'ammonizione': 'admonition',
'sidebar (translation required)': 'sidebar', 'riquadro': 'sidebar',
'argomento': 'topic', 'argomento': 'topic',
'blocco di linee': 'line-block', 'blocco-di-righe': 'line-block',
'parsed-literal': 'parsed-literal', 'blocco-interpretato': 'parsed-literal',
'rubric (translation required)': 'rubric', 'rubrica': 'rubric',
'epigraph (translation required)': 'epigraph', 'epigrafe': 'epigraph',
'highlights (translation required)': 'highlights', 'evidenzia': 'highlights',
'pull-quote (translation required)': 'pull-quote', 'pull-quote (translation required)': 'pull-quote',
'tabella': 'table',
#'questions': 'questions', #'questions': 'questions',
#'qa': 'questions', #'qa': 'questions',
#'faq': 'questions', #'faq': 'questions',
...@@ -47,11 +43,12 @@ directives = { ...@@ -47,11 +43,12 @@ directives = {
'grezzo': 'raw', 'grezzo': 'raw',
'sostituisci': 'replace', 'sostituisci': 'replace',
'unicode': 'unicode', 'unicode': 'unicode',
'class (translation required)': 'class', 'classe': 'class',
'ruolo': 'role',
'indice': 'contents', 'indice': 'contents',
'seznum': 'sectnum', 'seznum': 'sectnum',
'section-numbering': 'sectnum', 'sezioni-autonumerate': 'sectnum',
'target-notes': 'target-notes', 'annota-riferimenti-esterni': 'target-notes',
#'footnotes': 'footnotes', #'footnotes': 'footnotes',
#'citations': 'citations', #'citations': 'citations',
'restructuredtext-test-directive': 'restructuredtext-test-directive'} 'restructuredtext-test-directive': 'restructuredtext-test-directive'}
...@@ -59,23 +56,23 @@ directives = { ...@@ -59,23 +56,23 @@ directives = {
mapping.""" mapping."""
roles = { roles = {
'abbreviation (translation required)': 'abbreviation', 'abbreviazione': 'abbreviation',
'acronym (translation required)': 'acronym', 'acronimo': 'acronym',
'index (translation required)': 'index', 'indice': 'index',
'subscript (translation required)': 'subscript', 'deponente': 'subscript',
'superscript (translation required)': 'superscript', 'esponente': 'superscript',
'title-reference (translation required)': 'title-reference', 'riferimento-titolo': 'title-reference',
'pep-reference (translation required)': 'pep-reference', 'riferimento-pep': 'pep-reference',
'rfc-reference (translation required)': 'rfc-reference', 'riferimento-rfc': 'rfc-reference',
'emphasis (translation required)': 'emphasis', 'enfasi': 'emphasis',
'strong (translation required)': 'strong', 'forte': 'strong',
'literal (translation required)': 'literal', 'letterale': 'literal',
'named-reference (translation required)': 'named-reference', 'riferimento-con-nome': 'named-reference',
'anonymous-reference (translation required)': 'anonymous-reference', 'riferimento-anonimo': 'anonymous-reference',
'footnote-reference (translation required)': 'footnote-reference', 'riferimento-nota': 'footnote-reference',
'citation-reference (translation required)': 'citation-reference', 'riferimento-citazione': 'citation-reference',
'substitution-reference (translation required)': 'substitution-reference', 'riferimento-sostituzione': 'substitution-reference',
'target (translation required)': 'target', 'destinazione': 'target',
'uri-reference (translation required)': 'uri-reference',} 'riferimento-uri': 'uri-reference',}
"""Mapping of Italian role names to canonical role names for interpreted text. """Mapping of Italian role names to canonical role names for interpreted text.
""" """
# -*- coding: iso-8859-1 -*-
# Author: David Goodger
# Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:51 $
# Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please
# read <http://docutils.sf.net/spec/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
"""
Brazilian Portuguese-language mappings for language-dependent features of
reStructuredText.
"""
__docformat__ = 'reStructuredText'
directives = {
# language-dependent: fixed
u'ateno': 'attention',
'cuidado': 'caution',
'perigo': 'danger',
'erro': 'error',
u'sugesto': 'hint',
'importante': 'important',
'nota': 'note',
'dica': 'tip',
'aviso': 'warning',
u'exortao': 'admonition',
'barra-lateral': 'sidebar',
u'tpico': 'topic',
'bloco-de-linhas': 'line-block',
'literal-interpretado': 'parsed-literal',
'rubrica': 'rubric',
u'epgrafo': 'epigraph',
'destaques': 'highlights',
u'citao-destacada': 'pull-quote',
u'table (translation required)': 'table',
#'perguntas': 'questions',
#'qa': 'questions',
#'faq': 'questions',
'meta': 'meta',
#'imagemap': 'imagemap',
'imagem': 'image',
'figura': 'figure',
u'incluso': 'include',
'cru': 'raw',
u'substituio': 'replace',
'unicode': 'unicode',
'classe': 'class',
'role (translation required)': 'role',
u'ndice': 'contents',
'numsec': 'sectnum',
u'numerao-de-sees': 'sectnum',
#u'notas-de-rorap': 'footnotes',
#u'citaes': 'citations',
u'links-no-rodap': 'target-notes',
'restructuredtext-test-directive': 'restructuredtext-test-directive'}
"""English name to registered (in directives/__init__.py) directive name
mapping."""
roles = {
# language-dependent: fixed
u'abbreviao': 'abbreviation',
'ab': 'abbreviation',
u'acrnimo': 'acronym',
'ac': 'acronym',
u'ndice-remissivo': 'index',
'i': 'index',
'subscrito': 'subscript',
'sub': 'subscript',
'sobrescrito': 'superscript',
'sob': 'superscript',
u'referncia-a-ttulo': 'title-reference',
u'ttulo': 'title-reference',
't': 'title-reference',
u'referncia-a-pep': 'pep-reference',
'pep': 'pep-reference',
u'referncia-a-rfc': 'rfc-reference',
'rfc': 'rfc-reference',
u'nfase': 'emphasis',
'forte': 'strong',
'literal': 'literal',
u'referncia-por-nome': 'named-reference',
u'referncia-annima': 'anonymous-reference',
u'referncia-a-nota-de-rodap': 'footnote-reference',
u'referncia-a-citao': 'citation-reference',
u'referncia-a-substituio': 'substitution-reference',
'alvo': 'target',
u'referncia-a-uri': 'uri-reference',
'uri': 'uri-reference',
'url': 'uri-reference',}
"""Mapping of English role names to canonical role names for interpreted text.
"""
# Author: Roman Suzi # Author: Roman Suzi
# Contact: rnd@onego.ru # Contact: rnd@onego.ru
# Revision: $Revision: 1.3 $ # Revision: $Revision: 1.1.2.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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
...@@ -23,6 +23,7 @@ directives = { ...@@ -23,6 +23,7 @@ directives = {
u'parsed-literal', u'parsed-literal',
u'\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f-\u0446\u0438\u0442\u0430\u0442\u0430': u'\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f-\u0446\u0438\u0442\u0430\u0442\u0430':
u'pull-quote', u'pull-quote',
u'table (translation required)': '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':
...@@ -40,6 +41,7 @@ directives = { ...@@ -40,6 +41,7 @@ directives = {
u'\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435': u'\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435':
u'image', u'image',
u'\u043a\u043b\u0430\u0441\u0441': u'class', u'\u043a\u043b\u0430\u0441\u0441': u'class',
u'role (translation required)': 'role',
u'\u043d\u043e\u043c\u0435\u0440-\u0440\u0430\u0437\u0434\u0435\u043b\u0430': u'\u043d\u043e\u043c\u0435\u0440-\u0440\u0430\u0437\u0434\u0435\u043b\u0430':
u'sectnum', u'sectnum',
u'\u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u044f-\u0440\u0430\u0437' u'\u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u044f-\u0440\u0430\u0437'
......
# Author: Miroslav Vasko # Author: Miroslav Vasko
# Contact: zemiak@zoznam.sk # Contact: zemiak@zoznam.sk
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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
...@@ -36,6 +36,7 @@ directives = { ...@@ -36,6 +36,7 @@ directives = {
u'epigraph (translation required)': 'epigraph', u'epigraph (translation required)': 'epigraph',
u'highlights (translation required)': 'highlights', u'highlights (translation required)': 'highlights',
u'pull-quote (translation required)': 'pull-quote', u'pull-quote (translation required)': 'pull-quote',
u'table (translation required)': 'table',
#u'questions': 'questions', #u'questions': 'questions',
#u'qa': 'questions', #u'qa': 'questions',
#u'faq': 'questions', #u'faq': 'questions',
...@@ -48,6 +49,7 @@ directives = { ...@@ -48,6 +49,7 @@ directives = {
u'nahradi\x9d': 'replace', u'nahradi\x9d': 'replace',
u'unicode': 'unicode', u'unicode': 'unicode',
u'class (translation required)': 'class', u'class (translation required)': 'class',
u'role (translation required)': 'role',
u'obsah': 'contents', u'obsah': 'contents',
u'\xe8as\x9d': 'sectnum', u'\xe8as\x9d': 'sectnum',
u'\xe8as\x9d-\xe8\xedslovanie': 'sectnum', u'\xe8as\x9d-\xe8\xedslovanie': 'sectnum',
......
# Author: Adam Chodorowski # Author: Adam Chodorowski
# Contact: chodorowski@users.sourceforge.net # Contact: chodorowski@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:07 $ # Date: $Date: 2004/05/12 19:57:51 $
# 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
...@@ -35,6 +35,7 @@ directives = { ...@@ -35,6 +35,7 @@ directives = {
u'epigraph (translation required)': 'epigraph', u'epigraph (translation required)': 'epigraph',
u'highlights (translation required)': 'highlights', u'highlights (translation required)': 'highlights',
u'pull-quote (translation required)': 'pull-quote', u'pull-quote (translation required)': 'pull-quote',
u'table (translation required)': 'table',
# u'fr\u00e5gor': 'questions', # u'fr\u00e5gor': 'questions',
# NOTE: A bit long, but recommended by http://www.nada.kth.se/dataterm/: # NOTE: A bit long, but recommended by http://www.nada.kth.se/dataterm/:
# u'fr\u00e5gor-och-svar': 'questions', # u'fr\u00e5gor-och-svar': 'questions',
...@@ -48,6 +49,7 @@ directives = { ...@@ -48,6 +49,7 @@ directives = {
u'ers\u00e4tt': 'replace', u'ers\u00e4tt': 'replace',
u'unicode': 'unicode', u'unicode': 'unicode',
u'class (translation required)': 'class', u'class (translation required)': 'class',
u'role (translation required)': 'role',
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',
......
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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:07:46 $ # Date: $Date: 2004/05/12 19:57:47 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:08 $ # Date: $Date: 2004/05/12 19:57:52 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:08 $ # Date: $Date: 2004/05/12 19:57:52 $
# 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.3 $ # Revision: $Revision: 1.3.2.1.8.1 $
# Date: $Date: 2003/11/30 15:06:08 $ # Date: $Date: 2004/05/12 19:57:53 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -13,9 +13,117 @@ __docformat__ = 'reStructuredText' ...@@ -13,9 +13,117 @@ __docformat__ = 'reStructuredText'
import sys import sys
import docutils.readers import docutils.readers
from docutils.readers.python import moduleparser
from docutils import parsers
from docutils import nodes
from docutils.readers.python import pynodes
from docutils import readers
class Reader(docutils.readers.Reader): class Reader(docutils.readers.Reader):
config_section = 'python reader' config_section = 'python reader'
config_section_dependencies = ('readers',) config_section_dependencies = ('readers',)
default_parser = 'restructuredtext'
def parse(self):
"""Parse `self.input` into a document tree."""
self.document = document = self.new_document()
module_section = moduleparser.parse_module(self.input,
self.source.source_path)
module_section.walk(DocformatVisitor(self.document))
visitor = DocstringFormattingVisitor(
document=document,
default_parser=self.default_parser)
module_section.walk(visitor)
self.document.append(module_section)
class DocformatVisitor(nodes.SparseNodeVisitor):
"""
This sets docformat attributes in a module. Wherever an assignment
to __docformat__ is found, we look for the enclosing scope -- a class,
a module, or a function -- and set the docformat attribute there.
We can't do this during the DocstringFormattingVisitor walking,
because __docformat__ may appear below a docstring in that format
(typically below the module docstring).
"""
def visit_attribute(self, node):
assert isinstance(node[0], pynodes.object_name)
name = node[0][0].data
if name != '__docformat__':
return
value = None
for child in children:
if isinstance(child, pynodes.expression_value):
value = child[0].data
break
assert value.startswith("'") or value.startswith('"'), "__docformat__ must be assigned a string literal (not %s); line: %s" % (value, node['lineno'])
name = name[1:-1]
looking_in = node.parent
while not isinstance(looking_in, (pynodes.module_section,
pynodes.function_section,
pynodes.class_section)):
looking_in = looking_in.parent
looking_in['docformat'] = name
class DocstringFormattingVisitor(nodes.SparseNodeVisitor):
def __init__(self, document, default_parser):
self.document = document
self.default_parser = default_parser
self.parsers = {}
def visit_docstring(self, node):
text = node[0].data
docformat = self.find_docformat(node)
del node[0]
node['docformat'] = docformat
parser = self.get_parser(docformat)
parser.parse(text, self.document)
for child in self.document.get_children():
node.append(child)
self.document.current_source = self.document.current_line = None
del self.document[:]
def get_parser(self, parser_name):
"""
Get a parser based on its name. We reuse parsers during this
visitation, so parser instances are cached.
"""
parser_name = parsers._parser_aliases.get(parser_name, parser_name)
if not self.parsers.has_key(parser_name):
cls = parsers.get_parser_class(parser_name)
self.parsers[parser_name] = cls()
return self.parsers[parser_name]
def find_docformat(self, node):
"""
Find the __docformat__ closest to this node (i.e., look in the
class or module)
"""
while node:
if node.get('docformat'):
return node['docformat']
node = node.parent
return self.default_parser
if __name__ == '__main__':
try:
import locale
locale.setlocale(locale.LC_ALL, '')
except:
pass
from docutils.core import publish_cmdline, default_description
description = ('Generates pseudo-XML from Python modules '
'(for testing purposes). ' + default_description)
publish_cmdline(description=description,
reader=Reader())
#! /usr/bin/env python
"""
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Revision: $Revision: 1.1.2.1 $
:Date: $Date: 2004/05/12 19:57:53 $
:Copyright: This module has been placed in the public domain.
"""
from docutils import nodes
from docutils.nodes import Element, TextElement, Structural, Inline, Part, \
Text
import types
# This is the parent class of all the other pynode classes:
class PythonStructural(Structural): pass
# =====================
# Structural Elements
# =====================
class module_section(PythonStructural, Element): pass
class class_section(PythonStructural, Element): pass
class class_base(PythonStructural, Element): pass
class method_section(PythonStructural, Element): pass
class attribute(PythonStructural, Element): pass
class function_section(PythonStructural, Element): pass
class class_attribute_section(PythonStructural, Element): pass
class class_attribute(PythonStructural, Element): pass
class expression_value(PythonStructural, Element): pass
class attribute(PythonStructural, Element): pass
# Structural Support Elements
# ---------------------------
class parameter_list(PythonStructural, Element): pass
class parameter_tuple(PythonStructural, Element): pass
class parameter_default(PythonStructural, TextElement): pass
class import_group(PythonStructural, TextElement): pass
class import_from(PythonStructural, TextElement): pass
class import_name(PythonStructural, TextElement): pass
class import_alias(PythonStructural, TextElement): pass
class docstring(PythonStructural, Element): pass
# =================
# Inline Elements
# =================
# These elements cannot become references until the second
# pass. Initially, we'll use "reference" or "name".
class object_name(PythonStructural, TextElement): pass
class parameter_list(PythonStructural, TextElement): pass
class parameter(PythonStructural, TextElement): pass
class parameter_default(PythonStructural, TextElement): pass
class class_attribute(PythonStructural, TextElement): pass
class attribute_tuple(PythonStructural, TextElement): pass
# =================
# Unused Elements
# =================
# These were part of the model, and maybe should be in the future, but
# aren't now.
#class package_section(PythonStructural, Element): pass
#class module_attribute_section(PythonStructural, Element): pass
#class instance_attribute_section(PythonStructural, Element): pass
#class module_attribute(PythonStructural, TextElement): pass
#class instance_attribute(PythonStructural, TextElement): pass
#class exception_class(PythonStructural, TextElement): pass
#class warning_class(PythonStructural, TextElement): pass
# Collect all the classes we've written above
def install_node_class_names():
node_class_names = []
for name, var in globals().items():
if (type(var) is types.ClassType
and issubclass(var, PythonStructural) \
and name.lower() == name):
node_class_names.append(var.tagname or name)
# Register the new node names with GenericNodeVisitor and
# SpecificNodeVisitor:
nodes._add_node_class_names(node_class_names)
install_node_class_names()
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:08 $ # Date: $Date: 2004/05/12 19:57:52 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -14,7 +14,6 @@ __docformat__ = 'reStructuredText' ...@@ -14,7 +14,6 @@ __docformat__ = 'reStructuredText'
import sys import sys
from docutils import frontend, readers from docutils import frontend, readers
from docutils.transforms import frontmatter, references from docutils.transforms import frontmatter, references
from docutils.parsers.rst import Parser
class Reader(readers.Reader): class Reader(readers.Reader):
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:39 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -59,6 +59,7 @@ class Transform: ...@@ -59,6 +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."""
...@@ -76,7 +77,8 @@ class Transformer(TransformSpec): ...@@ -76,7 +77,8 @@ class Transformer(TransformSpec):
default_transforms = (universal.Decorations, default_transforms = (universal.Decorations,
universal.FinalChecks, universal.FinalChecks,
universal.Messages) universal.Messages,
universal.FilterMessages)
"""These transforms are applied to all document trees.""" """These transforms are applied to all document trees."""
def __init__(self, document): def __init__(self, document):
...@@ -84,6 +86,9 @@ class Transformer(TransformSpec): ...@@ -84,6 +86,9 @@ class Transformer(TransformSpec):
"""List of transforms to apply. Each item is a 3-tuple: """List of transforms to apply. Each item is a 3-tuple:
``(priority string, transform class, pending node or None)``.""" ``(priority string, transform class, pending node or None)``."""
self.unknown_reference_resolvers = []
"""List of hook functions which assist in resolving references"""
self.document = document self.document = document
"""The `nodes.document` object this Transformer is attached to.""" """The `nodes.document` object this Transformer is attached to."""
...@@ -149,6 +154,16 @@ class Transformer(TransformSpec): ...@@ -149,6 +154,16 @@ class Transformer(TransformSpec):
self.add_transforms(component.default_transforms) self.add_transforms(component.default_transforms)
self.components[component.component_type] = component self.components[component.component_type] = component
self.sorted = 0 self.sorted = 0
# Setup all of the reference resolvers for this transformer. Each
# component of this transformer is able to register its own helper
# functions to help resolve references.
unknown_reference_resolvers = []
for i in components:
unknown_reference_resolvers.extend(i.unknown_reference_resolvers)
decorated_list = [(f.priority, f) for f in unknown_reference_resolvers]
decorated_list.sort()
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."""
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -334,10 +334,10 @@ class DocInfo(Transform): ...@@ -334,10 +334,10 @@ class DocInfo(Transform):
return 1 return 1
rcs_keyword_substitutions = [ rcs_keyword_substitutions = [
(re.compile(r'\$' r'Date: (\d\d\d\d)/(\d\d)/(\d\d) [\d:]+ \$$', (re.compile(r'\$' r'Date: (\d\d\d\d)/(\d\d)/(\d\d) [\d:]+ \$',
re.IGNORECASE), r'\1-\2-\3'), re.IGNORECASE), r'\1-\2-\3'),
(re.compile(r'\$' r'RCSfile: (.+),v \$$', re.IGNORECASE), r'\1'), (re.compile(r'\$' r'RCSfile: (.+),v \$', re.IGNORECASE), r'\1'),
(re.compile(r'\$[a-zA-Z]+: (.+) \$$'), r'\1'),] (re.compile(r'\$[a-zA-Z]+: (.+) \$'), r'\1'),]
def extract_authors(self, field, name, docinfo): def extract_authors(self, field, name, docinfo):
try: try:
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# 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, Dmitry Jemerov # Authors: David Goodger, Ueli Schlaepfer, Dmitry Jemerov
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -34,7 +34,8 @@ class SectNum(Transform): ...@@ -34,7 +34,8 @@ class SectNum(Transform):
def apply(self): def apply(self):
self.maxdepth = self.startnode.details.get('depth', sys.maxint) self.maxdepth = self.startnode.details.get('depth', sys.maxint)
self.startnode.parent.remove(self.startnode) self.startnode.parent.remove(self.startnode)
self.update_section_numbers(self.document) if self.document.settings.sectnum_xform:
self.update_section_numbers(self.document)
def update_section_numbers(self, node, prefix=(), depth=0): def update_section_numbers(self, node, prefix=(), depth=0):
depth += 1 depth += 1
...@@ -58,11 +59,11 @@ class Contents(Transform): ...@@ -58,11 +59,11 @@ class Contents(Transform):
""" """
This transform generates a table of contents from the entire document tree This transform generates a table of contents from the entire document tree
or from a single branch. It locates "section" elements and builds them or from a single branch. It locates "section" elements and builds them
into a nested bullet list, which is placed within a "topic". A title is into a nested bullet list, which is placed within a "topic" created by the
either explicitly specified, taken from the appropriate language module, contents directive. A title is either explicitly specified, taken from
or omitted (local table of contents). The depth may be specified. the appropriate language module, or omitted (local table of contents).
Two-way references between the table of contents and section titles are The depth may be specified. Two-way references between the table of
generated (requires Writer support). contents and section titles are generated (requires Writer support).
This transform requires a startnode, which which contains generation This transform requires a startnode, which which contains generation
options and provides the location for the generated table of contents (the options and provides the location for the generated table of contents (the
...@@ -72,41 +73,26 @@ class Contents(Transform): ...@@ -72,41 +73,26 @@ class Contents(Transform):
default_priority = 720 default_priority = 720
def apply(self): def apply(self):
topic = nodes.topic(CLASS='contents')
details = self.startnode.details details = self.startnode.details
if details.has_key('class'):
topic.set_class(details['class'])
title = details['title']
if details.has_key('local'): if details.has_key('local'):
startnode = self.startnode.parent startnode = self.startnode.parent.parent
# @@@ generate an error if the startnode (directive) not at # @@@ generate an error if the startnode (directive) not at
# section/document top-level? Drag it up until it is? # section/document top-level? Drag it up until it is?
while not isinstance(startnode, nodes.Structural): while not isinstance(startnode, nodes.Structural):
startnode = startnode.parent startnode = startnode.parent
else: else:
startnode = self.document startnode = self.document
if not title:
title = nodes.title('', self.language.labels['contents']) self.toc_id = self.startnode.parent['id']
if title:
name = title.astext()
topic += title
else:
name = self.language.labels['contents']
name = nodes.fully_normalize_name(name)
if not self.document.has_name(name):
topic['name'] = name
self.document.note_implicit_target(topic)
self.toc_id = topic['id']
if details.has_key('backlinks'): if details.has_key('backlinks'):
self.backlinks = details['backlinks'] self.backlinks = details['backlinks']
else: else:
self.backlinks = self.document.settings.toc_backlinks self.backlinks = self.document.settings.toc_backlinks
contents = self.build_contents(startnode) contents = self.build_contents(startnode)
if len(contents): if len(contents):
topic += contents self.startnode.parent.replace(self.startnode, contents)
self.startnode.parent.replace(self.startnode, topic)
else: else:
self.startnode.parent.remove(self.startnode) self.startnode.parent.parent.remove(self.startnode.parent)
def build_contents(self, node, level=0): def build_contents(self, node, level=0):
level += 1 level += 1
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -19,7 +19,7 @@ import sys ...@@ -19,7 +19,7 @@ import sys
import os import os
import re import re
import time import time
from docutils import nodes, utils from docutils import nodes, utils, languages
from docutils import ApplicationError, DataError from docutils import ApplicationError, DataError
from docutils.transforms import Transform, TransformError from docutils.transforms import Transform, TransformError
from docutils.transforms import parts, references, misc from docutils.transforms import parts, references, misc
...@@ -137,15 +137,24 @@ class Headers(Transform): ...@@ -137,15 +137,24 @@ class Headers(Transform):
class Contents(Transform): class Contents(Transform):
""" """
Insert a table of contents transform placeholder into the document after Insert an empty table of contents topic and a transform placeholder into
the RFC 2822 header. the document after the RFC 2822 header.
""" """
default_priority = 380 default_priority = 380
def apply(self): def apply(self):
pending = nodes.pending(parts.Contents, {'title': None}) language = languages.get_language(self.document.settings.language_code)
self.document.insert(1, pending) name = language.labels['contents']
title = nodes.title('', name)
topic = nodes.topic('', title, CLASS='contents')
name = nodes.fully_normalize_name(name)
if not self.document.has_name(name):
topic['name'] = name
self.document.note_implicit_target(topic)
pending = nodes.pending(parts.Contents)
topic += pending
self.document.insert(1, topic)
self.document.note_pending(pending) self.document.note_pending(pending)
......
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -216,7 +216,13 @@ class IndirectHyperlinks(Transform): ...@@ -216,7 +216,13 @@ class IndirectHyperlinks(Transform):
refname = target['refname'] refname = target['refname']
reftarget_id = self.document.nameids.get(refname) reftarget_id = self.document.nameids.get(refname)
if not reftarget_id: if not reftarget_id:
self.nonexistent_indirect_target(target) # Check the unknown_reference_resolvers
for resolver_function in (self.document.transformer
.unknown_reference_resolvers):
if resolver_function(target):
break
else:
self.nonexistent_indirect_target(target)
return return
reftarget = self.document.ids[reftarget_id] reftarget = self.document.ids[reftarget_id]
if isinstance(reftarget, nodes.target) \ if isinstance(reftarget, nodes.target) \
...@@ -248,7 +254,11 @@ class IndirectHyperlinks(Transform): ...@@ -248,7 +254,11 @@ class IndirectHyperlinks(Transform):
reftarget.referenced = 1 reftarget.referenced = 1
def nonexistent_indirect_target(self, target): def nonexistent_indirect_target(self, target):
self.indirect_target_error(target, 'which does not exist') if self.document.nameids.has_key(target['refname']):
self.indirect_target_error(target, 'which is a duplicate, and '
'cannot be used as a unique reference')
else:
self.indirect_target_error(target, 'which does not exist')
def circular_indirect_reference(self, target): def circular_indirect_reference(self, target):
self.indirect_target_error(target, 'forming a circular reference') self.indirect_target_error(target, 'forming a circular reference')
...@@ -353,7 +363,8 @@ class ExternalTargets(Transform): ...@@ -353,7 +363,8 @@ class ExternalTargets(Transform):
try: try:
reflist = self.document.refnames[name] reflist = self.document.refnames[name]
except KeyError, instance: except KeyError, instance:
if target.referenced: # @@@ First clause correct???
if not isinstance(target, nodes.target) or target.referenced:
continue continue
msg = self.document.reporter.info( msg = self.document.reporter.info(
'External hyperlink target "%s" is not referenced.' 'External hyperlink target "%s" is not referenced.'
......
# Authors: David Goodger, Ueli Schlaepfer # Authors: David Goodger, Ueli Schlaepfer
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:55 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -111,6 +111,29 @@ class Messages(Transform): ...@@ -111,6 +111,29 @@ class Messages(Transform):
self.document += section self.document += section
class FilterMessages(Transform):
"""
Remove system messages below verbosity threshold.
"""
default_priority = 870
def apply(self):
visitor = SystemMessageFilterVisitor(self.document)
self.document.walk(visitor)
class SystemMessageFilterVisitor(nodes.SparseNodeVisitor):
def unknown_visit(self, node):
pass
def visit_system_message(self, node):
if node['level'] < self.document.reporter['writer'].report_level:
node.parent.remove(node)
class TestMessages(Transform): class TestMessages(Transform):
""" """
...@@ -136,7 +159,9 @@ class FinalChecks(Transform): ...@@ -136,7 +159,9 @@ class FinalChecks(Transform):
default_priority = 840 default_priority = 840
def apply(self): def apply(self):
visitor = FinalCheckVisitor(self.document) visitor = FinalCheckVisitor(
self.document,
self.document.transformer.unknown_reference_resolvers)
self.document.walk(visitor) self.document.walk(visitor)
if self.document.settings.expose_internals: if self.document.settings.expose_internals:
visitor = InternalAttributeExposer(self.document) visitor = InternalAttributeExposer(self.document)
...@@ -144,6 +169,11 @@ class FinalChecks(Transform): ...@@ -144,6 +169,11 @@ class FinalChecks(Transform):
class FinalCheckVisitor(nodes.SparseNodeVisitor): class FinalCheckVisitor(nodes.SparseNodeVisitor):
def __init__(self, document, unknown_reference_resolvers):
nodes.SparseNodeVisitor.__init__(self, document)
self.document = document
self.unknown_reference_resolvers = unknown_reference_resolvers
def unknown_visit(self, node): def unknown_visit(self, node):
pass pass
...@@ -154,15 +184,24 @@ class FinalCheckVisitor(nodes.SparseNodeVisitor): ...@@ -154,15 +184,24 @@ class FinalCheckVisitor(nodes.SparseNodeVisitor):
refname = node['refname'] refname = node['refname']
id = self.document.nameids.get(refname) id = self.document.nameids.get(refname)
if id is None: if id is None:
msg = self.document.reporter.error( for resolver_function in self.unknown_reference_resolvers:
'Unknown target name: "%s".' % (node['refname']), if resolver_function(node):
base_node=node) break
msgid = self.document.set_id(msg) else:
prb = nodes.problematic( if self.document.nameids.has_key(refname):
node.rawsource, node.rawsource, refid=msgid) msg = self.document.reporter.error(
prbid = self.document.set_id(prb) 'Duplicate target name, cannot be used as a unique '
msg.add_backref(prbid) 'reference: "%s".' % (node['refname']), base_node=node)
node.parent.replace(node, prb) else:
msg = self.document.reporter.error(
'Unknown target name: "%s".' % (node['refname']),
base_node=node)
msgid = self.document.set_id(msg)
prb = nodes.problematic(
node.rawsource, node.rawsource, refid=msgid)
prbid = self.document.set_id(prb)
msg.add_backref(prbid)
node.parent.replace(node, prb)
else: else:
del node['refname'] del node['refname']
node['refid'] = id node['refid'] = id
......
""" """
`schemes` is a dictionary with lowercase URI addressing schemes as `schemes` is a dictionary with lowercase URI addressing schemes as
keys and descriptions as values. It was compiled from the index at keys and descriptions as values. It was compiled from the index at
http://www.w3.org/Addressing/schemes.html (revised 2001-08-20). http://www.iana.org/assignments/uri-schemes (revised 2003-11-26)
and an older list at http://www.w3.org/Addressing/schemes.html.
""" """
# Many values are blank and should be filled in with useful descriptions. # Many values are blank and should be filled in with useful descriptions.
...@@ -26,10 +27,12 @@ schemes = { ...@@ -26,10 +27,12 @@ schemes = {
'specialized to justify their own schemes'), 'specialized to justify their own schemes'),
'fax': ('a connection to a terminal that can handle telefaxes ' 'fax': ('a connection to a terminal that can handle telefaxes '
'(facsimiles); RFC 2806'), '(facsimiles); RFC 2806'),
'feed' : 'NetNewsWire feed',
'file': 'Host-specific file names', 'file': 'Host-specific file names',
'finger': '', 'finger': '',
'freenet': '', 'freenet': '',
'ftp': 'File Transfer Protocol', 'ftp': 'File Transfer Protocol',
'go': 'go; RFC3368',
'gopher': 'The Gopher Protocol', 'gopher': 'The Gopher Protocol',
'gsm-sms': ('Global System for Mobile Communications Short Message ' 'gsm-sms': ('Global System for Mobile Communications Short Message '
'Service'), 'Service'),
...@@ -40,16 +43,19 @@ schemes = { ...@@ -40,16 +43,19 @@ schemes = {
'hnews': 'an HTTP-tunneling variant of the NNTP news protocol', 'hnews': 'an HTTP-tunneling variant of the NNTP news protocol',
'http': 'Hypertext Transfer Protocol', 'http': 'Hypertext Transfer Protocol',
'https': 'HTTP over SSL', 'https': 'HTTP over SSL',
'hydra': 'SubEthaEdit URI. See http://www.codingmonkeys.de/subethaedit.',
'iioploc': 'Internet Inter-ORB Protocol Location?', 'iioploc': 'Internet Inter-ORB Protocol Location?',
'ilu': 'Inter-Language Unification', 'ilu': 'Inter-Language Unification',
'im': 'Instant Messaging',
'imap': 'Internet Message Access Protocol', 'imap': 'Internet Message Access Protocol',
'ior': 'CORBA interoperable object reference', 'ior': 'CORBA interoperable object reference',
'ipp': 'Internet Printing Protocol', 'ipp': 'Internet Printing Protocol',
'irc': 'Internet Relay Chat', 'irc': 'Internet Relay Chat',
'iseek' : 'See www.ambrosiasw.com; a little util for OS X.',
'jar': 'Java archive', 'jar': 'Java archive',
'javascript': ('JavaScript code; evaluates the expression after the ' 'javascript': ('JavaScript code; evaluates the expression after the '
'colon'), 'colon'),
'jdbc': '', 'jdbc': 'JDBC connection URI.',
'ldap': 'Lightweight Directory Access Protocol', 'ldap': 'Lightweight Directory Access Protocol',
'lifn': '', 'lifn': '',
'livescript': '', 'livescript': '',
...@@ -62,6 +68,7 @@ schemes = { ...@@ -62,6 +68,7 @@ schemes = {
'mocha': '', 'mocha': '',
'modem': ('a connection to a terminal that can handle incoming data ' 'modem': ('a connection to a terminal that can handle incoming data '
'calls; RFC 2806'), 'calls; RFC 2806'),
'mupdate': 'Mailbox Update (MUPDATE) Protocol',
'news': 'USENET news', 'news': 'USENET news',
'nfs': 'Network File System protocol', 'nfs': 'Network File System protocol',
'nntp': 'USENET news using NNTP access', 'nntp': 'USENET news using NNTP access',
...@@ -69,8 +76,10 @@ schemes = { ...@@ -69,8 +76,10 @@ schemes = {
'phone': '', 'phone': '',
'pop': 'Post Office Protocol', 'pop': 'Post Office Protocol',
'pop3': 'Post Office Protocol v3', 'pop3': 'Post Office Protocol v3',
'pres': 'Presence',
'printer': '', 'printer': '',
'prospero': 'Prospero Directory Service', 'prospero': 'Prospero Directory Service',
'rdar' : 'URLs found in Darwin source (http://www.opensource.apple.com/darwinsource/).',
'res': '', 'res': '',
'rtsp': 'real time streaming protocol', 'rtsp': 'real time streaming protocol',
'rvp': '', 'rvp': '',
...@@ -80,8 +89,12 @@ schemes = { ...@@ -80,8 +89,12 @@ schemes = {
'service': 'service location', 'service': 'service location',
'shttp': 'secure hypertext transfer protocol', 'shttp': 'secure hypertext transfer protocol',
'sip': 'Session Initiation Protocol', 'sip': 'Session Initiation Protocol',
'smb': '', 'sips': 'secure session intitiaion protocol',
'smb': 'SAMBA filesystems.',
'snews': 'For NNTP postings via SSL', 'snews': 'For NNTP postings via SSL',
'soap.beep': '',
'soap.beeps': '',
'ssh': 'Reference to interactive sessions via ssh.',
't120': 'real time data conferencing (audiographics)', 't120': 'real time data conferencing (audiographics)',
'tcp': '', 'tcp': '',
'tel': ('a connection to a terminal that handles normal voice ' 'tel': ('a connection to a terminal that handles normal voice '
...@@ -90,6 +103,7 @@ schemes = { ...@@ -90,6 +103,7 @@ schemes = {
'RFC 2806.'), 'RFC 2806.'),
'telephone': 'telephone', 'telephone': 'telephone',
'telnet': 'Reference to interactive sessions', 'telnet': 'Reference to interactive sessions',
'tftp': 'Trivial File Transfer Protocol',
'tip': 'Transaction Internet Protocol', 'tip': 'Transaction Internet Protocol',
'tn3270': 'Interactive 3270 emulation sessions', 'tn3270': 'Interactive 3270 emulation sessions',
'tv': '', 'tv': '',
...@@ -101,5 +115,8 @@ schemes = { ...@@ -101,5 +115,8 @@ schemes = {
'wais': 'Wide Area Information Servers', 'wais': 'Wide Area Information Servers',
'whodp': '', 'whodp': '',
'whois++': 'Distributed directory service.', 'whois++': 'Distributed directory service.',
'x-man-page': 'Opens man page in Terminal.app on OS X (see macosxhints.com)',
'xmlrpc.beep': '',
'xmlrpc.beeps': '',
'z39.50r': 'Z39.50 Retrieval', 'z39.50r': 'Z39.50 Retrieval',
'z39.50s': 'Z39.50 Session',} 'z39.50s': 'Z39.50 Session',}
# Author: David Goodger # Author: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:04 $ # Date: $Date: 2004/05/12 19:57:39 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -324,7 +324,9 @@ def assemble_option_dict(option_list, options_spec): ...@@ -324,7 +324,9 @@ def assemble_option_dict(option_list, options_spec):
""" """
options = {} options = {}
for name, value in option_list: for name, value in option_list:
convertor = options_spec[name] # raises KeyError if unknown convertor = options_spec[name] # raises KeyError if unknown
if convertor is None:
raise KeyError(name) # or if explicitly disabled
if options.has_key(name): if options.has_key(name):
raise DuplicateOptionError('duplicate option "%s"' % name) raise DuplicateOptionError('duplicate option "%s"' % name)
try: try:
...@@ -406,7 +408,7 @@ def clean_rcs_keywords(paragraph, keyword_substitutions): ...@@ -406,7 +408,7 @@ def clean_rcs_keywords(paragraph, keyword_substitutions):
if len(paragraph) == 1 and isinstance(paragraph[0], nodes.Text): if len(paragraph) == 1 and isinstance(paragraph[0], nodes.Text):
textnode = paragraph[0] textnode = paragraph[0]
for pattern, substitution in keyword_substitutions: for pattern, substitution in keyword_substitutions:
match = pattern.match(textnode.data) match = pattern.search(textnode.data)
if match: if match:
textnode.data = pattern.sub(substitution, textnode.data) textnode.data = pattern.sub(substitution, textnode.data)
return return
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:57 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -26,25 +26,43 @@ class Writer(Component): ...@@ -26,25 +26,43 @@ class Writer(Component):
Each writer must support all standard node types listed in Each writer must support all standard node types listed in
`docutils.nodes.node_class_names`. `docutils.nodes.node_class_names`.
Call `write()` to process a document. The `write()` method is the main entry point.
""" """
component_type = 'writer' component_type = 'writer'
config_section = 'writers' config_section = 'writers'
document = None document = None
"""The document to write.""" """The document to write (Docutils doctree); set by `write`."""
output = None
"""Final translated form of `document`; set by `translate`."""
language = None language = None
"""Language module for the document.""" """Language module for the document; set by `write`."""
destination = None destination = None
"""`docutils.io` IO object; where to write the document.""" """`docutils.io` IO object; where to write the document. Set by `write`."""
def __init__(self): def __init__(self):
"""Initialize the Writer instance."""
# Currently only used by HTML writer for output fragments:
self.parts = {}
"""Mapping of document part names to fragments of `self.output`.
Values are Unicode strings; encoding is up to the client. The 'whole'
key should contain the entire document output.
"""
def write(self, document, destination): def write(self, document, destination):
"""
Process a document into its final form.
Translate `document` (a Docutils document tree) into the Writer's
native format, and write it out to its `destination` (a
`docutils.io.Output` subclass object).
Normally not overridden or extended in subclasses.
"""
self.document = document self.document = document
self.language = languages.get_language( self.language = languages.get_language(
document.settings.language_code) document.settings.language_code)
...@@ -55,9 +73,10 @@ class Writer(Component): ...@@ -55,9 +73,10 @@ class Writer(Component):
def translate(self): def translate(self):
""" """
Override to do final document tree translation. Do final translation of `self.document` into `self.output`.
Called from `write`. Override in subclasses.
This is usually done with a `docutils.nodes.NodeVisitor` subclass, in Usually done with a `docutils.nodes.NodeVisitor` subclass, in
combination with a call to `docutils.nodes.Node.walk()` or combination with a call to `docutils.nodes.Node.walk()` or
`docutils.nodes.Node.walkabout()`. The ``NodeVisitor`` subclass must `docutils.nodes.Node.walkabout()`. The ``NodeVisitor`` subclass must
support all standard elements (listed in support all standard elements (listed in
...@@ -66,6 +85,10 @@ class Writer(Component): ...@@ -66,6 +85,10 @@ class Writer(Component):
""" """
raise NotImplementedError('subclass must override this method') raise NotImplementedError('subclass must override this method')
def assemble_parts(self):
"""Assemble the `self.parts` dictionary. Extend in subclasses."""
self.parts['whole'] = self.output
_writer_aliases = { _writer_aliases = {
'html': 'html4css1', 'html': 'html4css1',
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:57 $
# 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.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:57 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
...@@ -88,15 +88,6 @@ class Writer(html4css1.Writer): ...@@ -88,15 +88,6 @@ class Writer(html4css1.Writer):
class HTMLTranslator(html4css1.HTMLTranslator): class HTMLTranslator(html4css1.HTMLTranslator):
def get_stylesheet_reference(self, relative_to=None):
settings = self.settings
if relative_to == None:
relative_to = settings._destination
if settings.stylesheet_path:
return utils.relative_path(relative_to, settings.stylesheet_path)
else:
return settings.stylesheet
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 node.get('class') == 'rfc2822':
......
# Authors: David Goodger # Authors: David Goodger
# Contact: goodger@users.sourceforge.net # Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.5 $ # Revision: $Revision: 1.2.10.3.8.1 $
# Date: $Date: 2003/11/30 15:06:09 $ # Date: $Date: 2004/05/12 19:57:57 $
# Copyright: This module has been placed in the public domain. # Copyright: This module has been placed in the public domain.
""" """
......
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