Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:4404545
Created Dec 29, 2012

'''Example of a custom ReST directive in Python docutils'''
import docutils.core
from docutils.nodes import TextElement, Inline
from docutils.parsers.rst import Directive, directives
from docutils.writers.html4css1 import Writer, HTMLTranslator
class foo(Inline, TextElement):
'''This node class is a no-op -- just a fun way to define some parameters.
There are lots of base classes to choose from in `docutils.nodes`.
See examples in `docutils.nodes`
NODE = ''
class Foo(Directive):
'''This `Directive` class tells the ReST parser what to do with the text it
encounters -- parse the input, perhaps, and return a list of node objects.
Here, usage of a single required argument is shown.
See examples in docutils.parsers.rst.directives.*
required_arguments = 1
optional_arguments = 3
has_content = True
option_spec = {
'prompt': directives.unchanged,
'choices': directives.unchanged,
'default': directives.unchanged
def run(self):
thenode = foo(text=self.arguments[0])
return [thenode]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment