[Zope-Checkins] CVS: Zope/lib/python/docutils/parsers/rst - __init__.py:1.1.2.2 states.py:1.1.2.2 tableparser.py:1.1.2.2

Andreas Jung andreas@andreas-jung.com
Sat, 25 Jan 2003 07:44:40 -0500


Update of /cvs-repository/Zope/lib/python/docutils/parsers/rst
In directory cvs.zope.org:/tmp/cvs-serv2352/parsers/rst

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	__init__.py states.py tableparser.py 
Log Message:
docutils updated


=== Zope/lib/python/docutils/parsers/rst/__init__.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/parsers/rst/__init__.py:1.1.2.1	Tue Nov  5 04:03:58 2002
+++ Zope/lib/python/docutils/parsers/rst/__init__.py	Sat Jan 25 07:44:06 2003
@@ -8,15 +8,16 @@
 This is ``docutils.parsers.rst`` package. It exports a single class, `Parser`,
 the reStructuredText parser.
 
+
 Usage
 =====
 
 1. Create a parser::
 
-       parser = docutils.parsers.restructuredtext.Parser()
+       parser = docutils.parsers.rst.Parser()
 
    Several optional arguments may be passed to modify the parser's behavior.
-   Please see `docutils.parsers.Parser` for details.
+   Please see `Customizing the Parser`_ below for details.
 
 2. Gather input (a multi-line string), by reading a file or the standard
    input::
@@ -25,7 +26,7 @@
 
 3. Create a new empty `docutils.nodes.document` tree::
 
-       document = docutils.utils.new_document(source)
+       document = docutils.utils.new_document(source, settings)
 
    See `docutils.utils.new_document()` for parameter details.
 
@@ -33,6 +34,7 @@
 
        parser.parse(input, document)
 
+
 Parser Overview
 ===============
 
@@ -40,6 +42,31 @@
 input one line at a time. To understand how the parser works, please first
 become familiar with the `docutils.statemachine` module, then see the
 `states` module.
+
+
+Customizing the Parser
+----------------------
+
+Anything that isn't already customizable is that way simply because that type
+of customizability hasn't been implemented yet.  Patches welcome!
+
+When instantiating an object of the `Parser` class, two parameters may be
+passed: ``rfc2822`` and ``inliner``.  Pass ``rfc2822=1`` to enable an initial
+RFC-2822 style header block, parsed as a "field_list" element (with "class"
+attribute set to "rfc2822").  Currently this is the only body-level element
+which is customizable without subclassing.  (Tip: subclass `Parser` and change
+its "state_classes" and "initial_state" attributes to refer to new classes.
+Contact the author if you need more details.)
+
+The ``inliner`` parameter takes an instance of `states.Inliner` or a subclass.
+It handles inline markup recognition.  A common extension is the addition of
+further implicit hyperlinks, like "RFC 2822".  This can be done by subclassing
+`states.Inliner`, adding a new method for the implicit markup, and adding a
+``(pattern, method)`` pair to the "implicit_dispatch" attribute of the
+subclass.  See `states.Inliner.implicit_inline()` for details.  Explicit
+inline markup can be customized in a `states.Inliner` subclass via the
+``patterns.initial`` and ``dispatch`` attributes (and new methods as
+appropriate).
 """
 
 __docformat__ = 'reStructuredText'


=== Zope/lib/python/docutils/parsers/rst/states.py 1.1.2.1 => 1.1.2.2 === (657/757 lines abridged)
--- Zope/lib/python/docutils/parsers/rst/states.py:1.1.2.1	Tue Nov  5 04:03:58 2002
+++ Zope/lib/python/docutils/parsers/rst/states.py	Sat Jan 25 07:44:06 2003
@@ -113,9 +113,12 @@
 from docutils.statemachine import StateMachineWS, StateWS
 from docutils.utils import normalize_name
 from docutils.parsers.rst import directives, languages, tableparser
+from docutils.parsers.rst.languages import en as _fallback_language_module
 
 
 class MarkupError(DataError): pass
+class UnknownInterpretedRoleError(DataError): pass
+class InterpretedRoleNotImplementedError(DataError): pass
 class ParserError(ApplicationError): pass
 class MarkupMismatch(Exception): pass
 
@@ -157,14 +160,23 @@
                            title_styles=[],
                            section_level=0,
                            inliner=inliner)
-        self.document = self.memo.document
-        self.attach_observer(self.document.note_state_machine_change)
+        self.document = document
+        self.attach_observer(document.note_source)
         self.reporter = self.memo.reporter
         self.node = document
-        results = StateMachineWS.run(self, input_lines, input_offset)
+        results = StateMachineWS.run(self, input_lines, input_offset,
+                                     input_source=document['source'])
         assert results == [], 'RSTStateMachine.run() results should be empty!'
+        self.check_document()
         self.node = self.memo = None    # remove unneeded references
 
+    def check_document(self):
+        """Check for illegal structure: empty document."""
+        if len(self.document) == 0:
+            error = self.reporter.error(
+                'Document empty; must have contents.', line=0)
+            self.document += error
+
 
 class NestedStateMachine(StateMachineWS):
 
@@ -182,7 +194,7 @@
         self.match_titles = match_titles
         self.memo = memo
         self.document = memo.document
-        self.attach_observer(self.document.note_state_machine_change)
+        self.attach_observer(self.document.note_source)
         self.reporter = memo.reporter
         self.node = node

[-=- -=- -=- 657 lines omitted -=- -=- -=-]

@@ -2354,8 +2589,8 @@
     def definition_list_item(self, termline):
         indented, indent, line_offset, blank_finish = \
               self.state_machine.get_indented()
-        definitionlistitem = nodes.definition_list_item('\n'.join(termline
-                                                                  + indented))
+        definitionlistitem = nodes.definition_list_item(
+            '\n'.join(termline + list(indented)))
         termlist, messages = self.term(
               termline, self.state_machine.abs_line_number() - 1)
         definitionlistitem += termlist
@@ -2446,31 +2681,35 @@
         if len(marker) < 4:
             self.state_correction(context)
         if self.eofcheck:               # ignore EOFError with sections
+            lineno = self.state_machine.abs_line_number() - 1
             transition = nodes.transition(context[0])
+            transition.line = lineno
             self.parent += transition
             msg = self.reporter.error(
                   'Document or section may not end with a transition.',
-                  line=self.state_machine.abs_line_number() - 1)
+                  line=lineno)
             self.parent += msg
         self.eofcheck = 1
         return []
 
     def blank(self, match, context, next_state):
         """Transition marker."""
+        lineno = self.state_machine.abs_line_number() - 1
         marker = context[0].strip()
         if len(marker) < 4:
             self.state_correction(context)
         transition = nodes.transition(marker)
+        transition.line = lineno
         if len(self.parent) == 0:
             msg = self.reporter.error(
                   'Document or section may not begin with a transition.',
-                  line=self.state_machine.abs_line_number() - 1)
+                  line=lineno)
             self.parent += msg
         elif isinstance(self.parent[-1], nodes.transition):
             msg = self.reporter.error(
                   'At least one body element must separate transitions; '
                   'adjacent transitions not allowed.',
-                  line=self.state_machine.abs_line_number() - 1)
+                  line=lineno)
             self.parent += msg
         self.parent += transition
         return [], 'Body', []


=== Zope/lib/python/docutils/parsers/rst/tableparser.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/parsers/rst/tableparser.py:1.1.2.1	Tue Nov  5 04:03:58 2002
+++ Zope/lib/python/docutils/parsers/rst/tableparser.py	Sat Jan 25 07:44:06 2003
@@ -131,7 +131,7 @@
     head_body_separator_pat = re.compile(r'\+=[=+]+=\+ *$')
 
     def setup(self, block):
-        self.block = block[:]           # make a copy; it may be modified
+        self.block = list(block)        # make a copy; it may be modified
         self.bottom = len(block) - 1
         self.right = len(block[0]) - 1
         self.head_body_sep = None
@@ -371,7 +371,7 @@
     span_pat = re.compile('-[ -]*$')
 
     def setup(self, block):
-        self.block = block[:]           # make a copy; it will be modified
+        self.block = list(block)        # make a copy; it will be modified
         # Convert top & bottom borders to column span underlines:
         self.block[0] = self.block[0].replace('=', '-')
         self.block[-1] = self.block[-1].replace('=', '-')