[Python-checkins] r66915 - in doctools/trunk: CHANGES doc/ext/appapi.rst sphinx/application.py sphinx/environment.py
georg.brandl
python-checkins at python.org
Thu Oct 16 21:04:45 CEST 2008
Author: georg.brandl
Date: Thu Oct 16 21:04:45 2008
New Revision: 66915
Log:
Add "source-read" event.
Modified:
doctools/trunk/CHANGES
doctools/trunk/doc/ext/appapi.rst
doctools/trunk/sphinx/application.py
doctools/trunk/sphinx/environment.py
Modified: doctools/trunk/CHANGES
==============================================================================
--- doctools/trunk/CHANGES (original)
+++ doctools/trunk/CHANGES Thu Oct 16 21:04:45 2008
@@ -81,8 +81,8 @@
- Added ``Sphinx.add_javascript()`` that adds scripts to load in the
default HTML template.
- - Added new events: ``env-updated``, ``missing-reference``,
- ``build-finished``.
+ - Added new events: ``source-read``, ``env-updated``,
+ ``missing-reference``, ``build-finished``.
* Other changes:
Modified: doctools/trunk/doc/ext/appapi.rst
==============================================================================
--- doctools/trunk/doc/ext/appapi.rst (original)
+++ doctools/trunk/doc/ext/appapi.rst Thu Oct 16 21:04:45 2008
@@ -208,6 +208,14 @@
Emitted when the builder object has been created. It is available as
``app.builder``.
+.. event:: source-read (app, docname, source)
+
+ Emitted when a source file has been read. The *source* argument is a list
+ whose single element is the contents of the source file. You can process the
+ contents and replace this item to implement source-level transformations.
+
+ .. versionadded:: 0.5
+
.. event:: doctree-read (app, doctree)
Emitted when a doctree has been parsed and read by the environment, and is
Modified: doctools/trunk/sphinx/application.py
==============================================================================
--- doctools/trunk/sphinx/application.py (original)
+++ doctools/trunk/sphinx/application.py Thu Oct 16 21:04:45 2008
@@ -58,6 +58,7 @@
# List of all known core events. Maps name to arguments description.
events = {
'builder-inited': '',
+ 'source-read': 'docname, source text',
'doctree-read': 'the doctree before being pickled',
'missing-reference': 'env, node, contnode',
'doctree-resolved': 'doctree, docname',
Modified: doctools/trunk/sphinx/environment.py
==============================================================================
--- doctools/trunk/sphinx/environment.py (original)
+++ doctools/trunk/sphinx/environment.py Thu Oct 16 21:04:45 2008
@@ -485,8 +485,18 @@
else:
self.warn(docname, 'default role %s not found' %
self.config.default_role)
+
+ class SphinxSourceClass(FileInput):
+ def read(self):
+ data = FileInput.read(self)
+ if app:
+ arg = [data]
+ app.emit('source-read', docname, arg)
+ data = arg[0]
+ return data
+
self.docname = docname
- doctree = publish_doctree(None, src_path, FileInput,
+ doctree = publish_doctree(None, src_path, SphinxSourceClass,
settings_overrides=self.settings,
reader=SphinxStandaloneReader())
self.filter_messages(doctree)
More information about the Python-checkins
mailing list