accessing Date from the docinfo metadata

dan90 avatardan90 created an issue

Currently sphinx.environment.BuildEnvironment.process_metadata deletes the docinfo node when it has finished stashing selected nodes' contents in its metadata attribute.

This means that docinfo node that is not an instance of the two currently accepted classes (, docutils.nodes.field) is discarded and not accessible to extensions. However, some other field types might be legitimately used by extensions. I'm thinking specifically of my own use case, which involves inspecting the date field to create a date-based index. More generally, I think there could be legitimate uses for many things that subclasses docutils.nodes.Bibliographic. (authors? copyright? status?)

Would it be possible to either

  1. emit an event before process_metadata is called in read_doc to enable extension to access the bibliographic fields (there is already 'source-read' of course, but that's before the doctree exists), or
  2. stash the metadata from other bibliographic fields in the environment's metadata attribute along with the author/generic field metadata?

If I were to write a patch for this functionality, would either of these options be more likely to be accepted into the mainline?

Comments (5)

  1. dan mackinlay
    • changed component to markup
    • changed version to tip

    Of course, the other option might be to use some kind of transform to extract the bibliographic metadata using some kind of transform before Sphinx gets to it, but this feels like an artificial solution to me.

  2. dan mackinlay

    changeset 756414bae132 in my fork of sphinx includes tests for the current docinfo metadata behaviour. From this point it would seem natural to proceed along the path of (2) above - stashing the other docinfo metadata in a natural way in the environment metadata. I'll do that next, but the new tests might be useful, if you consider them well-written enough, even if no new behavior is added.

  3. dan mackinlay

    What a rapid response. Quite a gift. Merry Christmas to you too, Georg, and thanks. (Thanks for the lesson in coding style too.)

    I believe this solves the issue entirely.

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.