doctree.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # $Id: doctree.py 4564 2006-05-21 20:44:42Z wiemann $
  2. # Author: Martin Blais <blais@furius.ca>
  3. # Copyright: This module has been placed in the public domain.
  4. """Reader for existing document trees."""
  5. from docutils import readers, utils, transforms
  6. class Reader(readers.ReReader):
  7. """
  8. Adapt the Reader API for an existing document tree.
  9. The existing document tree must be passed as the ``source`` parameter to
  10. the `docutils.core.Publisher` initializer, wrapped in a
  11. `docutils.io.DocTreeInput` object::
  12. pub = docutils.core.Publisher(
  13. ..., source=docutils.io.DocTreeInput(document), ...)
  14. The original document settings are overridden; if you want to use the
  15. settings of the original document, pass ``settings=document.settings`` to
  16. the Publisher call above.
  17. """
  18. supported = ('doctree',)
  19. config_section = 'doctree reader'
  20. config_section_dependencies = ('readers',)
  21. def parse(self):
  22. """
  23. No parsing to do; refurbish the document tree instead.
  24. Overrides the inherited method.
  25. """
  26. self.document = self.input
  27. # Create fresh Transformer object, to be populated from Writer
  28. # component.
  29. self.document.transformer = transforms.Transformer(self.document)
  30. # Replace existing settings object with new one.
  31. self.document.settings = self.settings
  32. # Create fresh Reporter object because it is dependent on
  33. # (new) settings.
  34. self.document.reporter = utils.new_reporter(
  35. self.document.get('source', ''), self.document.settings)