Created
May 16, 2011 10:44
-
-
Save tkf/974223 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| """ | |
| A toy example for adding a transform in docutils reader | |
| """ | |
| from docutils.readers import standalone | |
| from docutils.transforms import Transform | |
| from docutils import nodes | |
| class AddSpecialLink(Transform): | |
| default_priority = 0 | |
| def apply(self): | |
| self.document += nodes.target( | |
| ids=['special-link'], | |
| names=['special_link'], | |
| refuri="http://google.com", | |
| ) | |
| pass | |
| class Reader(standalone.Reader): | |
| def get_transforms(self): | |
| return standalone.Reader.get_transforms(self) + [ | |
| # add transform here | |
| AddSpecialLink, | |
| ] | |
| def sample(writer_name="html"): | |
| """ | |
| Sample usage of the AddSpecialLink Transform class | |
| """ | |
| from docutils.core import publish_parts | |
| return publish_parts( | |
| "special_link_", | |
| writer_name=writer_name, | |
| reader=Reader()) | |
| if __name__ == '__main__': | |
| print sample()["whole"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment