mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add "source-read" event.
This commit is contained in:
parent
39c3121344
commit
d7e2a48555
4
CHANGES
4
CHANGES
@ -81,8 +81,8 @@ New features added
|
||||
- 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:
|
||||
|
||||
|
@ -208,6 +208,14 @@ registered event handlers.
|
||||
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
|
||||
|
@ -58,6 +58,7 @@ class ExtensionError(SphinxError):
|
||||
# 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',
|
||||
|
@ -485,8 +485,18 @@ class BuildEnvironment:
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user