Skip to content

Instantly share code, notes, and snippets.

@mbukatov
Created April 3, 2017 11:59
Show Gist options
  • Save mbukatov/e813bc7b1e826aea584a26209bbc4591 to your computer and use it in GitHub Desktop.
Save mbukatov/e813bc7b1e826aea584a26209bbc4591 to your computer and use it in GitHub Desktop.
no-doc-info-example

Default behaviour with DocInfo transformation:

$ rst2pseudoxml nodocinfo_example.rst
<document ids="no-docinfo-example" names="no\ docinfo\ example" source="nodocinfo_example.rst" title="No DocInfo Example">
    <title>
        No DocInfo Example
    <docinfo>
        <author>
            mbukatov
        <date>
            2017-04-03
    <paragraph>
        This is just an example of document with doc info.

Custom rst tool with DocInfo transformation disabled:

$ ./nodocinfo_example.py nodocinfo_example.rst
<document ids="no-docinfo-example" names="no\ docinfo\ example" source="nodocinfo_example.rst" title="No DocInfo Example">
    <title>
        No DocInfo Example
    <field_list>
        <field>
            <field_name>
                author
            <field_body>
                <paragraph>
                    mbukatov
        <field>
            <field_name>
                date
            <field_body>
                <paragraph>
                    2017-04-03
    <paragraph>
        This is just an example of document with doc info.
#!/usr/bin/env python3
# -*- coding: utf8 -*-
from docutils.core import publish_cmdline
from docutils.readers import standalone
from docutils.transforms import frontmatter
class NoDocInfoReader(standalone.Reader):
"""
NoDocInfoReader extends docutils standalone ReStructuredText reader
to drop DocInfo transformation, everything else remains the same.
"""
def get_transforms(self):
transforms = standalone.Reader.get_transforms(self)
transforms.remove(frontmatter.DocInfo)
return transforms
if __name__ == '__main__':
publish_cmdline(writer_name='pseudoxml', reader=NoDocInfoReader())

No DocInfo Example

Author: mbukatov
Date: 2017-04-03

This is just an example of document with doc info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment