Skip to content

Instantly share code, notes, and snippets.

Created December 29, 2012 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4404545 to your computer and use it in GitHub Desktop.
Save anonymous/4404545 to your computer and use it in GitHub Desktop.
'''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`
'''
pass
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