118
118
119
119
missing_imports = []
120
120
try :
121
- from docutils .parsers .rst import directives
121
+ from docutils .parsers .rst import directives , Directive
122
122
from docutils .parsers .rst .directives .images import Image
123
123
124
124
align = Image .align
@@ -146,26 +146,6 @@ def format_template(template, **kw):
146
146
missing_imports .append (str (e ))
147
147
148
148
149
- def wf_directive (
150
- name ,
151
- arguments ,
152
- options ,
153
- content ,
154
- lineno ,
155
- content_offset ,
156
- block_text ,
157
- state ,
158
- state_machine ,
159
- ):
160
- if len (missing_imports ) == 0 :
161
- return run (arguments , content , options , state_machine , state , lineno )
162
- else :
163
- raise ImportError ("\n " .join (missing_imports ))
164
-
165
-
166
- wf_directive .__doc__ = __doc__
167
-
168
-
169
149
def _option_boolean (arg ):
170
150
if not arg or not arg .strip ():
171
151
# no argument given, assume used as a flag
@@ -232,12 +212,12 @@ def mark_wf_labels(app, document):
232
212
break
233
213
234
214
235
- def setup ( app ):
236
- setup . app = app
237
- setup . config = app . config
238
- setup . confdir = app . confdir
239
-
240
- options = {
215
+ class WorkflowDirective ( Directive ):
216
+ has_content = True
217
+ required_arguments = 0
218
+ optional_arguments = 2
219
+ final_argument_whitespace = False
220
+ option_spec = {
241
221
"alt" : directives .unchanged ,
242
222
"height" : directives .length_or_unitless ,
243
223
"width" : directives .length_or_percentage_or_unitless ,
@@ -253,7 +233,16 @@ def setup(app):
253
233
"simple_form" : _option_boolean ,
254
234
}
255
235
256
- app .add_directive ("workflow" , wf_directive , True , (0 , 2 , False ), ** options )
236
+
237
+ WorkflowDirective .__doc__ = __doc__
238
+
239
+
240
+ def setup (app ):
241
+ setup .app = app
242
+ setup .config = app .config
243
+ setup .confdir = app .confdir
244
+
245
+ app .add_directive ("workflow" , WorkflowDirective )
257
246
app .add_config_value ("graph2use" , "hierarchical" , "html" )
258
247
app .add_config_value ("simple_form" , True , "html" )
259
248
app .add_config_value ("wf_pre_code" , None , True )
0 commit comments