anonymous / gist:4404545
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:4404545
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
'''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
Something went wrong with that request. Please try again.